bichnhan2701 commited on
Commit
29e7f58
·
1 Parent(s): 65f24bc

Update requirement

Browse files
app/services/nlp_postprocess.py CHANGED
@@ -7,8 +7,14 @@ from app.utils.hashing import sha256
7
  from app.config.settings import GEMINI_API_KEY
8
 
9
  # New official client
10
- import google.genai as genai
11
- from google.api_core.exceptions import GoogleAPIError # optional but useful
 
 
 
 
 
 
12
 
13
  CACHE_TTL = 60 * 60 * 24 * 3 # 3 days
14
 
@@ -16,13 +22,15 @@ CACHE_TTL = 60 * 60 * 24 * 3 # 3 days
16
  _gemini_client = None
17
  _GEMINI_MODEL = "gemini-1.5-flash" # hoặc "gemini-1.5-flash-latest"
18
 
19
- if GEMINI_API_KEY:
20
  try:
21
  _gemini_client = genai.Client(api_key=GEMINI_API_KEY)
22
  logging.info(f"[nlp_postprocess] Initialized google.genai client with model={_GEMINI_MODEL}")
23
  except Exception as e:
24
  logging.exception(f"[nlp_postprocess] Failed to init google.genai client: {e}")
25
  _gemini_client = None
 
 
26
  else:
27
  logging.warning("[nlp_postprocess] GEMINI_API_KEY is not set, using raw_text as normalization fallback")
28
 
 
7
  from app.config.settings import GEMINI_API_KEY
8
 
9
  # New official client
10
+ try:
11
+ import google.genai as genai
12
+ from google.api_core.exceptions import GoogleAPIError # optional but useful
13
+ except Exception:
14
+ genai = None
15
+ # fallback exception type so except GoogleAPIError still works
16
+ class GoogleAPIError(Exception):
17
+ pass
18
 
19
  CACHE_TTL = 60 * 60 * 24 * 3 # 3 days
20
 
 
22
  _gemini_client = None
23
  _GEMINI_MODEL = "gemini-1.5-flash" # hoặc "gemini-1.5-flash-latest"
24
 
25
+ if GEMINI_API_KEY and genai is not None:
26
  try:
27
  _gemini_client = genai.Client(api_key=GEMINI_API_KEY)
28
  logging.info(f"[nlp_postprocess] Initialized google.genai client with model={_GEMINI_MODEL}")
29
  except Exception as e:
30
  logging.exception(f"[nlp_postprocess] Failed to init google.genai client: {e}")
31
  _gemini_client = None
32
+ elif GEMINI_API_KEY and genai is None:
33
+ logging.warning("[nlp_postprocess] google.genai package not installed; GEMINI API disabled")
34
  else:
35
  logging.warning("[nlp_postprocess] GEMINI_API_KEY is not set, using raw_text as normalization fallback")
36
 
requirements.txt CHANGED
@@ -11,5 +11,6 @@ rq
11
  tenacity
12
  prometheus-client
13
  google-generativeai
 
14
  numpy
15
  pytest
 
11
  tenacity
12
  prometheus-client
13
  google-generativeai
14
+ google-genai
15
  numpy
16
  pytest