Update app.py
Browse files28 unmodified lines2930313233343536373839404142434445464728 unmodified linesreturn "No transactions found for today."return Noneexcept sqlite3.OperationalError as e:# Handle missing table or other DB errorsreturn f"Database error: {e}. Please initialize 'transactions' table in shop.db."def web_search_agent(query: str) -> str:# Example using SerpAPIresp = requests.get("https://serpapi.com/search",params={"q": query, "api_key": os.getenv("SERPAPI_KEY")})data = resp.json()snippet = data.get("organic_results", [{}])[0].get("snippet", "")return llm_agent(f"Summarize: {snippet}")def llm_agent(prompt: str) -> str:28 unmodified lines29303132333435363738394041424344454647484950515228 unmodified linesreturn "No transactions found for today."return Noneexcept sqlite3.OperationalError as e:return f"Database error: {e}. Please initialize 'transactions' table in shop.db."def web_search_agent(query: str) -> str:# Try fetching a snippet from SerpAPI, otherwise fallback to direct LLMtry:resp = requests.get("https://serpapi.com/search",params={"q": query, "api_key": os.getenv("SERPAPI_KEY")})data = resp.json()snippet = data.get("organic_results", [{}])[0].get("snippet", "").strip()if snippet:return llm_agent(f"Summarize: {snippet}")except Exception:pass# Fallback for no snippet or errorsreturn llm_agent(query)def llm_agent(prompt: str) -> str:
app.py+14-9