Ghisalbertifederico commited on
Commit
2ea61e0
·
verified ·
1 Parent(s): a1b1643

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -219,8 +219,12 @@ def call_tools(state: AgentState) -> AgentState:
219
  elif label == "youtube":
220
  print("[TOOL] youtube_transcript")
221
  if matched_obj:
222
- url = matched_obj[0]
223
- state["context"] = get_youtube_transcript.invoke({"url": url})
 
 
 
 
224
  elif label == "research":
225
  print("[TOOL] web search")
226
  search_json = web_search.invoke({"query": question})
@@ -232,6 +236,10 @@ def call_tools(state: AgentState) -> AgentState:
232
  return state
233
 
234
  def synthesize_response(state: AgentState) -> AgentState:
 
 
 
 
235
  prompt = [
236
  SystemMessage(content=get_prompt("final_llm_system")),
237
  HumanMessage(
@@ -369,7 +377,7 @@ def _answer_question(item: dict) -> str:
369
  continue
370
  for attempt in range(2):
371
  try:
372
- result = LGAgent(model_id=model_id)(augmented_question)
373
  # Pause between questions to respect Groq's tokens/min limit
374
  time.sleep(5)
375
  return result
 
219
  elif label == "youtube":
220
  print("[TOOL] youtube_transcript")
221
  if matched_obj:
222
+ url = re.sub(r'[.,;:!?")]+$', '', matched_obj.group(0))
223
+ print(f"[TOOL] fetching transcript for: {url}")
224
+ state["context"] = get_youtube_transcript.invoke({"video_url": url})
225
+ else:
226
+ print("[TOOL] youtube label but no URL found — falling back to web search")
227
+ state["context"] = web_search.invoke({"query": question})
228
  elif label == "research":
229
  print("[TOOL] web search")
230
  search_json = web_search.invoke({"query": question})
 
236
  return state
237
 
238
  def synthesize_response(state: AgentState) -> AgentState:
239
+ # Skip if a tool already produced a direct answer (image / python / excel paths)
240
+ if state.get("answer"):
241
+ print(f"[SYNTHESIZE] skipped — answer already set by tool")
242
+ return state
243
  prompt = [
244
  SystemMessage(content=get_prompt("final_llm_system")),
245
  HumanMessage(
 
377
  continue
378
  for attempt in range(2):
379
  try:
380
+ result = LGAgent(model_id=model_id)(augmented_question, task_id=task_id)
381
  # Pause between questions to respect Groq's tokens/min limit
382
  time.sleep(5)
383
  return result