ahnhs2k commited on
Commit
660ba3e
ยท
1 Parent(s): 8e7ca4b
Files changed (1) hide show
  1. app.py +25 -18
app.py CHANGED
@@ -45,7 +45,7 @@ def clean_answer(text: str) -> str:
45
 
46
  if s.lower() in ["yes", "no"]:
47
  s = s.capitalize()
48
-
49
  return s
50
 
51
  def classify_question(q: str) -> str:
@@ -89,30 +89,37 @@ class BasicAgent:
89
  print(f"Question: {question[:80]}...")
90
 
91
  qtype = classify_question(question)
92
- rule = RULES[qtype]
93
 
94
- # ๊ฒ€์ƒ‰ ์ฟผ๋ฆฌ ๋ณด์ • (์ˆซ์ž/๋‚ ์งœ๋Š” Wikipedia ์šฐ์„ )
95
- search_query = question
96
- if qtype in ["number", "date"]:
97
- search_query = question + " site:wikipedia.org"
 
 
 
 
98
 
99
- # ๊ฒ€์ƒ‰ (์‹คํŒจ ์‹œ 1ํšŒ ์žฌ์‹œ๋„)
 
 
 
 
 
 
 
 
 
 
 
 
100
  try:
101
- search_result = search_tool.run(search_query)
102
- if not search_result:
103
- raise RuntimeError("empty search")
104
  except Exception:
105
- try:
106
- search_result = search_tool.run(question)
107
- except Exception:
108
- search_result = ""
109
 
110
  prompt = f"""
111
  {SYSTEM_PROMPT}
112
 
113
- Additional Rules:
114
- - {rule}
115
-
116
  Question:
117
  {question}
118
 
@@ -123,7 +130,7 @@ class BasicAgent:
123
  response = llm.invoke([HumanMessage(content=prompt)])
124
  answer = clean_answer(response.content)
125
 
126
- print(f"Answer: {answer}")
127
  return answer
128
 
129
  def run_and_submit_all( profile: gr.OAuthProfile | None):
 
45
 
46
  if s.lower() in ["yes", "no"]:
47
  s = s.capitalize()
48
+
49
  return s
50
 
51
  def classify_question(q: str) -> str:
 
89
  print(f"Question: {question[:80]}...")
90
 
91
  qtype = classify_question(question)
 
92
 
93
+ # ๐Ÿ”น 1๋‹จ๊ณ„: ๊ฒ€์ƒ‰ ์—†์ด ๋จผ์ € ๋‹ต ์‹œ๋„
94
+ base_prompt = f"""
95
+ You are solving a GAIA benchmark question.
96
+
97
+ Rules:
98
+ - Answer with ONLY the final answer
99
+ - No explanation
100
+ - No extra text
101
 
102
+ Question:
103
+ {question}
104
+ """.strip()
105
+
106
+ base_response = llm.invoke([HumanMessage(content=base_prompt)])
107
+ base_answer = clean_answer(base_response.content)
108
+
109
+ # ๐Ÿ”น ์ˆซ์ž/์—ฐ๋„/YesNo๊ฐ€ ๋ช…ํ™•ํ•˜๋ฉด ๋ฐ”๋กœ ๋ฐ˜ํ™˜
110
+ if qtype in ["number", "date", "yesno"] and base_answer:
111
+ print(f"Answer (no search): {base_answer}")
112
+ return base_answer
113
+
114
+ # ๐Ÿ”น 2๋‹จ๊ณ„: ๊ทธ๋ž˜๋„ ์• ๋งคํ•˜๋ฉด ๊ฒ€์ƒ‰ ์‚ฌ์šฉ
115
  try:
116
+ search_result = search_tool.run(question)
 
 
117
  except Exception:
118
+ search_result = ""
 
 
 
119
 
120
  prompt = f"""
121
  {SYSTEM_PROMPT}
122
 
 
 
 
123
  Question:
124
  {question}
125
 
 
130
  response = llm.invoke([HumanMessage(content=prompt)])
131
  answer = clean_answer(response.content)
132
 
133
+ print(f"Answer (with search): {answer}")
134
  return answer
135
 
136
  def run_and_submit_all( profile: gr.OAuthProfile | None):