Add files via upload

This commit is contained in:
FatihMakes authored and GitHub committed 2026-06-06 17:41:38 +03:00
1 parent d3e8504706
commit 502309ad24
25 files changed
+4097 -3006

No files matched your search

+14 -27
View File
@@ -18,10 +18,6 @@ BASE_DIR = _get_base_dir()
API_CONFIG_PATH = BASE_DIR / "config" / "api_keys.json"
def _get_api_key() -> str:
with open(API_CONFIG_PATH, "r", encoding="utf-8") as f:
return json.load(f)["gemini_api_key"]
_MONTH_MAP: dict[str, int] = {
"january": 1, "february": 2, "march": 3, "april": 4,
@@ -62,19 +58,16 @@ def _parse_date(raw: str) -> str:
return val.strftime("%Y-%m-%d")
try:
import google.generativeai as genai
genai.configure(api_key=_get_api_key())
model = genai.GenerativeModel("gemini-2.5-flash-lite")
response = model.generate_content(
from core.llm_client import call_llm_text
result = call_llm_text(
f"Today is {today.strftime('%Y-%m-%d')}. "
f"Convert this date expression to YYYY-MM-DD: '{raw}'. "
f"Return ONLY the date string, nothing else."
)
result = response.text.strip()
).strip()
if re.match(r"\d{4}-\d{2}-\d{2}", result):
return result
except Exception as e:
print(f"[FlightFinder] ⚠️ Gemini date parse failed: {e}")
print(f"[FlightFinder] ⚠️ LLM date parse failed: {e}")
for month_name, month_num in _MONTH_MAP.items():
if month_name in lower:
@@ -152,34 +145,28 @@ def _parse_flights_with_gemini(
destination: str,
date: str,
) -> list[dict]:
import google.generativeai as genai
from core.llm_client import call_llm_text
genai.configure(api_key=_get_api_key())
model = genai.GenerativeModel(
model_name="gemini-2.5-flash",
system_instruction=(
"You are a flight data extraction expert. "
"Extract flight information from raw webpage text. "
"Return ONLY valid JSON — no markdown, no explanation."
),
system = (
"You are a flight data extraction expert. "
"Extract flight information from raw webpage text. "
"Return ONLY valid JSON — no markdown, no explanation."
)
prompt = (
f"Extract flight options from {origin} to {destination} on {date} "
f"from this Google Flights page text:\n\n{raw_text[:12000]}\n\n"
f"from this Google Flights page text:\n\n{raw_text[:8000]}\n\n"
f"Return a JSON array of up to 5 flights:\n"
f'[{{"airline":"...","departure":"HH:MM","arrival":"HH:MM",'
f'"duration":"Xh Ym","stops":0,"price":"...","currency":"USD"}}]\n'
f"If no flights found, return: []"
)
try:
response = model.generate_content(prompt)
text = re.sub(r"```(?:json)?", "", response.text).strip().rstrip("`").strip()
flights = json.loads(text)
text = call_llm_text(prompt, system=system)
text = re.sub(r"```(?:json)?", "", text).strip().rstrip("`").strip()
flights = json.loads(text)
return flights if isinstance(flights, list) else []
except Exception as e:
print(f"[FlightFinder] ⚠️ Gemini parse failed: {e}")
print(f"[FlightFinder] ⚠️ LLM parse failed: {e}")
return []
def _format_spoken(