Move to GPT for API consistency
This commit is contained in:
@@ -113,20 +113,14 @@ def _sync_extract(
|
||||
system_id: Optional[str],
|
||||
segments: Optional[list[dict]],
|
||||
) -> dict:
|
||||
"""Call Gemini Flash and parse the JSON response."""
|
||||
"""Call GPT-4o mini and parse the JSON response."""
|
||||
from app.config import settings
|
||||
import google.generativeai as genai
|
||||
from openai import OpenAI
|
||||
|
||||
if not settings.gemini_api_key:
|
||||
logger.warning("GEMINI_API_KEY not set — intelligence extraction disabled.")
|
||||
if not settings.openai_api_key:
|
||||
logger.warning("OPENAI_API_KEY not set — intelligence extraction disabled.")
|
||||
return {}
|
||||
|
||||
genai.configure(api_key=settings.gemini_api_key)
|
||||
model = genai.GenerativeModel(
|
||||
"gemini-2.5-flash-lite",
|
||||
generation_config={"response_mime_type": "application/json"},
|
||||
)
|
||||
|
||||
tg = f"{talkgroup_name} (TGID {talkgroup_id})" if talkgroup_id else (talkgroup_name or "unknown")
|
||||
prompt = _PROMPT_TEMPLATE.format(
|
||||
transcript_block=_build_transcript_block(transcript, segments),
|
||||
@@ -135,13 +129,18 @@ def _sync_extract(
|
||||
)
|
||||
|
||||
try:
|
||||
response = model.generate_content(prompt)
|
||||
return json.loads(response.text)
|
||||
client = OpenAI(api_key=settings.openai_api_key)
|
||||
response = client.chat.completions.create(
|
||||
model="gpt-4o-mini",
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
response_format={"type": "json_object"},
|
||||
)
|
||||
return json.loads(response.choices[0].message.content)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.warning(f"Gemini returned non-JSON: {e}")
|
||||
logger.warning(f"GPT-4o mini returned non-JSON: {e}")
|
||||
return {}
|
||||
except Exception as e:
|
||||
logger.warning(f"Gemini extraction failed: {e}")
|
||||
logger.warning(f"GPT-4o mini extraction failed: {e}")
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user