Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from openai import OpenAI
|
| 2 |
from ddgs import DDGS
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
class BasicAgent:
|
| 6 |
def __init__(self):
|
|
@@ -23,12 +28,9 @@ class BasicAgent:
|
|
| 23 |
ans = str(ans).strip()
|
| 24 |
for x in ["FINAL ANSWER:", "Final Answer:", "Answer:"]:
|
| 25 |
ans = ans.replace(x, "")
|
| 26 |
-
ans = ans.strip()
|
| 27 |
return ans.split("\n")[0].strip()
|
| 28 |
|
| 29 |
def __call__(self, question: str) -> str:
|
| 30 |
-
print("Question:", question[:100])
|
| 31 |
-
|
| 32 |
context = self.web_search(question)
|
| 33 |
|
| 34 |
prompt = f"""
|
|
@@ -48,27 +50,15 @@ Search context:
|
|
| 48 |
response = self.client.chat.completions.create(
|
| 49 |
model="gpt-4o-mini",
|
| 50 |
messages=[
|
| 51 |
-
{
|
| 52 |
-
|
| 53 |
-
"content": "You solve exact-match benchmark questions. Return only the final answer."
|
| 54 |
-
},
|
| 55 |
-
{
|
| 56 |
-
"role": "user",
|
| 57 |
-
"content": prompt
|
| 58 |
-
}
|
| 59 |
],
|
| 60 |
temperature=0
|
| 61 |
)
|
| 62 |
-
|
| 63 |
-
answer = response.choices[0].message.content
|
| 64 |
-
final = self.clean(answer)
|
| 65 |
-
print("Submitted:", final)
|
| 66 |
-
return final
|
| 67 |
-
|
| 68 |
except Exception as e:
|
| 69 |
print("AGENT ERROR:", e)
|
| 70 |
return "unknown"
|
| 71 |
-
|
| 72 |
def run_and_submit_all(profile):
|
| 73 |
"""
|
| 74 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
import pandas as pd
|
| 5 |
from openai import OpenAI
|
| 6 |
from ddgs import DDGS
|
| 7 |
+
|
| 8 |
+
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 9 |
|
| 10 |
class BasicAgent:
|
| 11 |
def __init__(self):
|
|
|
|
| 28 |
ans = str(ans).strip()
|
| 29 |
for x in ["FINAL ANSWER:", "Final Answer:", "Answer:"]:
|
| 30 |
ans = ans.replace(x, "")
|
|
|
|
| 31 |
return ans.split("\n")[0].strip()
|
| 32 |
|
| 33 |
def __call__(self, question: str) -> str:
|
|
|
|
|
|
|
| 34 |
context = self.web_search(question)
|
| 35 |
|
| 36 |
prompt = f"""
|
|
|
|
| 50 |
response = self.client.chat.completions.create(
|
| 51 |
model="gpt-4o-mini",
|
| 52 |
messages=[
|
| 53 |
+
{"role": "system", "content": "Return exact final answers only."},
|
| 54 |
+
{"role": "user", "content": prompt}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
],
|
| 56 |
temperature=0
|
| 57 |
)
|
| 58 |
+
return self.clean(response.choices[0].message.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
print("AGENT ERROR:", e)
|
| 61 |
return "unknown"
|
|
|
|
| 62 |
def run_and_submit_all(profile):
|
| 63 |
"""
|
| 64 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|