Mel Seto commited on
Commit
6a5b9c2
·
2 Parent(s): 77a7202 b99f5be

Merge pull request #2 from mel-seto/handle-429-error

Browse files
src/verification/wiktionary_client.py CHANGED
@@ -5,7 +5,7 @@ _WIKTIONARY_CACHE = {}
5
 
6
  class WiktionaryClient:
7
  """Simple wrapper for Wiktionary API queries."""
8
- BASE_URL = "https://zh.wiktionary.org/w/api.php"
9
  HEADERS = {"User-Agent": "MyChineseIdiomApp/1.0 (email@example.com)"}
10
 
11
  def exists(self, term: str) -> bool:
@@ -19,6 +19,7 @@ class WiktionaryClient:
19
  response = requests.get(self.BASE_URL, params=params, headers=self.HEADERS, timeout=5)
20
  response.raise_for_status()
21
  data = response.json()
 
22
  pages = data.get("query", {}).get("pages", {})
23
  exists = "-1" not in pages
24
  except Exception:
 
5
 
6
  class WiktionaryClient:
7
  """Simple wrapper for Wiktionary API queries."""
8
+ BASE_URL = "https://en.wiktionary.org/w/api.php"
9
  HEADERS = {"User-Agent": "MyChineseIdiomApp/1.0 (email@example.com)"}
10
 
11
  def exists(self, term: str) -> bool:
 
19
  response = requests.get(self.BASE_URL, params=params, headers=self.HEADERS, timeout=5)
20
  response.raise_for_status()
21
  data = response.json()
22
+ print(f'data: {data}')
23
  pages = data.get("query", {}).get("pages", {})
24
  exists = "-1" not in pages
25
  except Exception:
tests/test_retriever.py CHANGED
@@ -23,6 +23,7 @@ def test_empty_query():
23
  assert isinstance(item, str)
24
  assert len(item) > 0
25
 
 
26
  @pytest.mark.parametrize(
27
  "situation, idiom",
28
  [
@@ -34,4 +35,5 @@ def test_definition_returns_correct_idiom(situation, idiom):
34
  """if input situation is the same as the embedded English definition,
35
  RAG implementation should return the correct Chinese idiom"""
36
  top_k_idioms = retrieve_idiom(situation, top_k=3)
 
37
  assert any(idiom in s for s in top_k_idioms)
 
23
  assert isinstance(item, str)
24
  assert len(item) > 0
25
 
26
+ ## TODO: fix embedding logic so that this test passes
27
  @pytest.mark.parametrize(
28
  "situation, idiom",
29
  [
 
35
  """if input situation is the same as the embedded English definition,
36
  RAG implementation should return the correct Chinese idiom"""
37
  top_k_idioms = retrieve_idiom(situation, top_k=3)
38
+ print(top_k_idioms)
39
  assert any(idiom in s for s in top_k_idioms)