VietCat commited on
Commit
3c1e19a
·
1 Parent(s): 22ad536

init project

Browse files
Files changed (1) hide show
  1. rag_core/embedder.py +5 -4
rag_core/embedder.py CHANGED
@@ -4,20 +4,21 @@ import logging
4
  from rag_core.utils import log_timed
5
 
6
  @log_timed("gửi API tạo embedding")
7
- def get_embedding(text: str, retries: int = 3):
8
- baseTimeout=30
9
  for i in range(retries):
10
  try:
 
11
  response = requests.post(
12
  "https://vietcat-phobertnode.hf.space/embed",
13
  json={"text": text},
14
- timeout=baseTimeout*(i+1)
15
  )
16
  response.raise_for_status()
17
  return response.json()["embedding"]
18
  except requests.exceptions.RequestException as e:
19
- logging.warning(f"Lỗi embedding (lần {i+1}/{retries}): {e}")
20
  if i < retries - 1:
21
  time.sleep(2)
22
  else:
23
  raise
 
 
4
  from rag_core.utils import log_timed
5
 
6
  @log_timed("gửi API tạo embedding")
7
+ def get_embedding(text: str, retries: int = 3, base_timeout: int = 30):
 
8
  for i in range(retries):
9
  try:
10
+ current_timeout = base_timeout * (i + 1)
11
  response = requests.post(
12
  "https://vietcat-phobertnode.hf.space/embed",
13
  json={"text": text},
14
+ timeout=current_timeout
15
  )
16
  response.raise_for_status()
17
  return response.json()["embedding"]
18
  except requests.exceptions.RequestException as e:
19
+ logging.warning(f"Lỗi embedding (lần {i+1}/{retries}, timeout={current_timeout}s): {e}")
20
  if i < retries - 1:
21
  time.sleep(2)
22
  else:
23
  raise
24
+