ahnhs2k commited on
Commit
bdd4e88
ยท
1 Parent(s): 7677e2e
Files changed (1) hide show
  1. app.py +28 -11
app.py CHANGED
@@ -9,6 +9,7 @@ from typing import TypedDict
9
 
10
  from langchain_openai import ChatOpenAI
11
  from langchain_core.messages import HumanMessage
 
12
 
13
  # (Keep Constants as is)
14
  # --- Constants ---
@@ -46,6 +47,8 @@ class AgentState(TypedDict):
46
  # -------------------------------
47
  # Tools & LLM
48
  # -------------------------------
 
 
49
 
50
  # LLM (OpenAI โ€“ ์ด๋ฏธ ๋„ค ํ™˜๊ฒฝ์—์„œ ๋™์ž‘ ํ™•์ธ๋จ)
51
  llm = ChatOpenAI(
@@ -59,24 +62,38 @@ llm = ChatOpenAI(
59
  # -------------------------------
60
  class BasicAgent:
61
  def __init__(self):
62
- print("GAIA LLM-only Agent initialized.")
63
 
64
  def __call__(self, question: str) -> str:
65
  print(f"Question: {question[:80]}...")
66
 
67
- prompt = f"""
68
- You are solving a GAIA benchmark question.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
- Rules:
71
- - Answer with ONLY the final answer.
72
- - No explanation.
73
- - No formatting.
74
- - No extra text.
75
- - If the answer is a number, output ONLY the number.
76
- - If the answer is Yes/No, output ONLY Yes or No.
77
 
78
  Question:
79
  {question}
 
 
 
80
  """.strip()
81
 
82
  response = llm.invoke([HumanMessage(content=prompt)])
@@ -84,7 +101,7 @@ Question:
84
 
85
  print(f"Answer: {answer}")
86
  return answer
87
-
88
  def run_and_submit_all( profile: gr.OAuthProfile | None):
89
  """
90
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
9
 
10
  from langchain_openai import ChatOpenAI
11
  from langchain_core.messages import HumanMessage
12
+ from langchain_community.tools import DuckDuckGoSearchRun
13
 
14
  # (Keep Constants as is)
15
  # --- Constants ---
 
47
  # -------------------------------
48
  # Tools & LLM
49
  # -------------------------------
50
+ # Search tool (๋ฌด๋ฃŒ)
51
+ search_tool = DuckDuckGoSearchRun()
52
 
53
  # LLM (OpenAI โ€“ ์ด๋ฏธ ๋„ค ํ™˜๊ฒฝ์—์„œ ๋™์ž‘ ํ™•์ธ๋จ)
54
  llm = ChatOpenAI(
 
62
  # -------------------------------
63
  class BasicAgent:
64
  def __init__(self):
65
+ print("Search-based GAIA Agent initialized.")
66
 
67
  def __call__(self, question: str) -> str:
68
  print(f"Question: {question[:80]}...")
69
 
70
+ queries = [
71
+ question,
72
+ f"{question} wikipedia",
73
+ f"{question} site:wikipedia.org",
74
+ f"{question} fact",
75
+ ]
76
+
77
+ snippets = []
78
+ for q in queries:
79
+ try:
80
+ r = search_tool.run(q)
81
+ if r:
82
+ snippets.append(r)
83
+ time.sleep(0.5) # rate-limit ํšŒํ”ผ
84
+ except Exception as e:
85
+ print("Search error:", e)
86
+
87
+ search_result = "\n\n".join(snippets)
88
 
89
+ prompt = f"""
90
+ {SYSTEM_PROMPT}
 
 
 
 
 
91
 
92
  Question:
93
  {question}
94
+
95
+ Search Results:
96
+ {search_result}
97
  """.strip()
98
 
99
  response = llm.invoke([HumanMessage(content=prompt)])
 
101
 
102
  print(f"Answer: {answer}")
103
  return answer
104
+
105
  def run_and_submit_all( profile: gr.OAuthProfile | None):
106
  """
107
  Fetches all questions, runs the BasicAgent on them, submits all answers,