naman1102 commited on
Commit
abff174
·
1 Parent(s): 3e9852e

Tools_corrected

Browse files
Files changed (2) hide show
  1. app.py +22 -11
  2. tools.py +3 -1
app.py CHANGED
@@ -261,19 +261,30 @@ def respond_to_input(user_input: str, task_id) -> str:
261
  """
262
  system_msg = SystemMessage(
263
  content=(
264
- "You are an agent that picks exactly one course of action:\n"
265
- "Use Wikipedia first before even using web search Please. "
266
- " 1) If the user's question is best answered by looking up a Wikipedia summary, return\n"
267
- " {\"wiki_query\":\"<query for Wikipedia>\"} and nothing else.\n"
268
- " 2) Otherwise, if Wikipedia won't directly help, but you still need web results, return\n"
269
- " {\"web_search_query\":\"<search terms>\"} and nothing else.\n"
270
- " 3) Otherwise, if it's an image, use OCR: return {\"ocr_path\":\"<path>\"}.\n"
271
- " 4) Otherwise, if it's a spreadsheet question, return {\"excel_path\":\"<path>\", \"excel_sheet_name\":\"<sheet>\"}.\n"
272
- " 5) Otherwise, if it's an audio transcription, return {\"audio_path\":\"<path to audio file>\"}.\n"
273
- " 6) If you can answer immediately without any tool, return exactly {\"final_answer\":\"<your answer>\"}.\n"
274
- "Do NOT include any other keys, text, or explanation—just one JSON object with exactly one of those keys."
 
 
 
 
 
 
 
 
 
 
275
  )
276
  )
 
277
  human_msg = HumanMessage(content=user_input)
278
 
279
  initial_state: AgentState = {"messages": [system_msg, human_msg], "task_id": task_id}
 
261
  """
262
  system_msg = SystemMessage(
263
  content=(
264
+ "You are an agent that must choose exactly one of the following actions:\n"
265
+ " 1) If the user's question can be answered directly by consulting Wikipedia, return exactly:\n"
266
+ " {\"wiki_query\":\"<search terms for Wikipedia>\"}\n"
267
+ " and nothing else. Use Wikipedia before any other tool.\n"
268
+ " 2) Only if Wikipedia cannot directly answer, perform a web search and return:\n"
269
+ " {\"web_search_query\":\"<search terms>\"}\n"
270
+ " and nothing else.\n"
271
+ " 3) If the user's question requires extracting text from an image, return:\n"
272
+ " {\"ocr_path\":\"<local image path>\"}\n"
273
+ " and nothing else.\n"
274
+ " 4) If the user's question requires reading a spreadsheet, return:\n"
275
+ " {\"excel_path\":\"<local .xlsx path>\", \"excel_sheet_name\":\"<sheet name>\"}\n"
276
+ " and nothing else.\n"
277
+ " 5) If the user needs an audio transcription, return:\n"
278
+ " {\"audio_path\":\"<local audio file path>\"}\n"
279
+ " and nothing else.\n"
280
+ " 6) If you already know the answer without using any tool, return exactly:\n"
281
+ " {\"final_answer\":\"<your concise answer>\"}\n"
282
+ " and nothing else.\n"
283
+ "If the user's prompt explicitly tells you to perform a specific action (for example, “translate this sentence”), then do it directly and return your result as {\"final_answer\":\"<your answer>\"} or the appropriate tool key if needed. \n"
284
+ "Do NOT include any additional keys, explanation, or markdown—only one JSON object with exactly one key."
285
  )
286
  )
287
+
288
  human_msg = HumanMessage(content=user_input)
289
 
290
  initial_state: AgentState = {"messages": [system_msg, human_msg], "task_id": task_id}
tools.py CHANGED
@@ -262,11 +262,13 @@ def audio_transcriber_tool(state: AgentState) -> AgentState:
262
  raise RuntimeError("OPENAI_API_KEY is not set in environment.")
263
 
264
  with open(local_audio, "rb") as audio_file:
 
265
  response = openai.audio.transcriptions.create(
266
  model="whisper-1",
267
  file=audio_file,
268
  )
269
- text = response.get("text", "").strip()
 
270
  except Exception as e:
271
  text = f"Error during transcription: {e}"
272
  print(f"Transcripted as transcript: {text}")
 
262
  raise RuntimeError("OPENAI_API_KEY is not set in environment.")
263
 
264
  with open(local_audio, "rb") as audio_file:
265
+ print("reached openai.audio.transcriptions.create")
266
  response = openai.audio.transcriptions.create(
267
  model="whisper-1",
268
  file=audio_file,
269
  )
270
+ print("reached response")
271
+ text = response.text.strip()
272
  except Exception as e:
273
  text = f"Error during transcription: {e}"
274
  print(f"Transcripted as transcript: {text}")