Spaces:
Sleeping
Sleeping
shan gao
commited on
Commit
·
b9de22e
1
Parent(s):
6ee21c1
change
Browse files
agent.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
# agent_v6.py
|
|
|
|
|
|
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
import os, re, base64, mimetypes, tempfile, uuid, subprocess, json
|
| 4 |
from urllib.parse import urlparse, unquote
|
|
@@ -350,7 +353,7 @@ def solve_multimodal_node(state: AgentState) -> AgentState:
|
|
| 350 |
sys = SystemMessage(content=(
|
| 351 |
"You solve GAIA tasks using the provided evidence and attached images.\n"
|
| 352 |
"Be precise, quote numbers/strings exactly. If uncertain, say so.\n"
|
| 353 |
-
"Your answer to the GAIA tasks should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\n" + end_instr
|
| 354 |
))
|
| 355 |
|
| 356 |
# Summarized text evidence (ASR/OCR/PDF text)
|
|
@@ -399,7 +402,7 @@ def solve_text_only_node(state: "AgentState") -> "AgentState":
|
|
| 399 |
sys = SystemMessage(content=(
|
| 400 |
"You solve GAIA tasks. Use careful step-by-step reasoning but keep it concise.\n"
|
| 401 |
"You can use the provided textual evidence if there is any. \n"
|
| 402 |
-
"Your answer to the GAIA tasks should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.\n" + end_instr
|
| 403 |
))
|
| 404 |
|
| 405 |
user = HumanMessage(content=(
|
|
@@ -465,7 +468,7 @@ def has_images(state: AgentState) -> bool:
|
|
| 465 |
return True
|
| 466 |
return False
|
| 467 |
|
| 468 |
-
def route_after_preprocess(state: AgentState) -> Literal["
|
| 469 |
return "vision" if has_images(state) else "text"
|
| 470 |
|
| 471 |
# ---------- Graph ----------
|
|
|
|
| 1 |
# agent_v6.py
|
| 2 |
+
# Develop an AI agent with LangGraph and LangChain
|
| 3 |
+
# to answer the questions in the "gaia-benchmark/GAIA" dataset.
|
| 4 |
+
|
| 5 |
from pathlib import Path
|
| 6 |
import os, re, base64, mimetypes, tempfile, uuid, subprocess, json
|
| 7 |
from urllib.parse import urlparse, unquote
|
|
|
|
| 353 |
sys = SystemMessage(content=(
|
| 354 |
"You solve GAIA tasks using the provided evidence and attached images.\n"
|
| 355 |
"Be precise, quote numbers/strings exactly. If uncertain, say so.\n"
|
| 356 |
+
"Your answer to the GAIA tasks should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. If your answer only include a single word, make the first letter capital.\n" + end_instr
|
| 357 |
))
|
| 358 |
|
| 359 |
# Summarized text evidence (ASR/OCR/PDF text)
|
|
|
|
| 402 |
sys = SystemMessage(content=(
|
| 403 |
"You solve GAIA tasks. Use careful step-by-step reasoning but keep it concise.\n"
|
| 404 |
"You can use the provided textual evidence if there is any. \n"
|
| 405 |
+
"Your answer to the GAIA tasks should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. If your answer only include a single word, make the first letter capital.\n" + end_instr
|
| 406 |
))
|
| 407 |
|
| 408 |
user = HumanMessage(content=(
|
|
|
|
| 468 |
return True
|
| 469 |
return False
|
| 470 |
|
| 471 |
+
def route_after_preprocess(state: AgentState) -> Literal["vision","text"]:
|
| 472 |
return "vision" if has_images(state) else "text"
|
| 473 |
|
| 474 |
# ---------- Graph ----------
|