HowardZhangdqs commited on
Commit
f432512
·
1 Parent(s): df5beb9

fix: label cache id error

Browse files
Files changed (2) hide show
  1. ai/classify_paper.py +5 -2
  2. fetch_paper.py +1 -0
ai/classify_paper.py CHANGED
@@ -158,12 +158,12 @@ class PaperCache:
158
  self.lock = Lock()
159
 
160
  def get(self, paper):
161
- key = (paper['title'], paper.get('abstract'))
162
  with self.lock:
163
  return self.cache.get(key)
164
 
165
  def set(self, paper, result):
166
- key = (paper['title'], paper.get('abstract'))
167
  with self.lock:
168
  self.cache[key] = result
169
 
@@ -188,6 +188,9 @@ def classify_papers(papers: List[Dict[str, str]]) -> Optional[List[Dict[str, Lis
188
  else:
189
  uncached_papers.append(paper)
190
 
 
 
 
191
  if not uncached_papers:
192
  return cached_results
193
 
 
158
  self.lock = Lock()
159
 
160
  def get(self, paper):
161
+ key = paper["id"]
162
  with self.lock:
163
  return self.cache.get(key)
164
 
165
  def set(self, paper, result):
166
+ key = paper["id"]
167
  with self.lock:
168
  self.cache[key] = result
169
 
 
188
  else:
189
  uncached_papers.append(paper)
190
 
191
+ # 输出 cache 的数量
192
+ print(f"Cache hit: {len(cached_results)}, Cache miss: {len(uncached_papers)}")
193
+
194
  if not uncached_papers:
195
  return cached_results
196
 
fetch_paper.py CHANGED
@@ -106,6 +106,7 @@ def fetch_papers_with_daterange(start_date: Date, end_date: Date):
106
  preprocessed_articles = list(map(lambda article: {
107
  "title": article.title,
108
  "abstract": article.paper.summary,
 
109
  }, unique_articles))
110
 
111
  classified_articles = classify_papers(preprocessed_articles)
 
106
  preprocessed_articles = list(map(lambda article: {
107
  "title": article.title,
108
  "abstract": article.paper.summary,
109
+ "id": article.paper.id
110
  }, unique_articles))
111
 
112
  classified_articles = classify_papers(preprocessed_articles)