Spaces:
Sleeping
Sleeping
Tools_corrected
Browse files
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
|
| 265 |
-
"
|
| 266 |
-
"
|
| 267 |
-
"
|
| 268 |
-
" 2)
|
| 269 |
-
"
|
| 270 |
-
"
|
| 271 |
-
"
|
| 272 |
-
"
|
| 273 |
-
"
|
| 274 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
| 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}")
|