feat: complete production hardening implementation, specialty canonicalization, google-genai migration, voice reliability, sqlite concurrency, and test suite consolidation
This commit is contained in:
@@ -8,7 +8,7 @@ class GeminiClient:
|
||||
|
||||
def __init__(self):
|
||||
self.api_key = GEMINI_API_KEY
|
||||
self.model = GEMINI_MODEL
|
||||
self.model = GEMINI_MODEL or "gemini-1.5-flash"
|
||||
|
||||
async def extract_from_document(
|
||||
self,
|
||||
@@ -30,9 +30,10 @@ class GeminiClient:
|
||||
}
|
||||
|
||||
try:
|
||||
import google.generativeai as genai
|
||||
genai.configure(api_key=self.api_key)
|
||||
model = genai.GenerativeModel(self.model or "gemini-1.5-flash")
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
|
||||
client = genai.Client(api_key=self.api_key)
|
||||
|
||||
prompt = f"""
|
||||
You are a medical document extraction AI.
|
||||
@@ -56,12 +57,12 @@ Return ONLY JSON:
|
||||
"summary": "short clinical summary of the document"
|
||||
}}
|
||||
"""
|
||||
part = {
|
||||
"mime_type": mime_type,
|
||||
"data": file_bytes,
|
||||
}
|
||||
part = types.Part.from_bytes(data=file_bytes, mime_type=mime_type)
|
||||
response = await asyncio.wait_for(
|
||||
model.generate_content_async([part, prompt]),
|
||||
client.aio.models.generate_content(
|
||||
model=self.model,
|
||||
contents=[part, prompt]
|
||||
),
|
||||
timeout=4.0
|
||||
)
|
||||
cleaned_text = response.text.replace("```json", "").replace("```", "").strip()
|
||||
@@ -84,15 +85,18 @@ Return ONLY JSON:
|
||||
if not self.api_key or self.api_key in ["your_gemini_key", "your_gemini_api_key", ""]:
|
||||
raise ValueError("Gemini API key not configured")
|
||||
|
||||
import google.generativeai as genai
|
||||
genai.configure(api_key=self.api_key)
|
||||
model = genai.GenerativeModel(
|
||||
model_name=self.model or "gemini-1.5-flash",
|
||||
generation_config={"response_mime_type": "application/json"},
|
||||
)
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
|
||||
client = genai.Client(api_key=self.api_key)
|
||||
full_prompt = f"{system_prompt}\n\nPATIENT SAID: {user_message}"
|
||||
config = types.GenerateContentConfig(response_mime_type="application/json")
|
||||
response = await asyncio.wait_for(
|
||||
model.generate_content_async(full_prompt),
|
||||
client.aio.models.generate_content(
|
||||
model=self.model,
|
||||
contents=full_prompt,
|
||||
config=config,
|
||||
),
|
||||
timeout=3.5
|
||||
)
|
||||
return response.text
|
||||
|
||||
Reference in New Issue
Block a user