Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,11 +13,36 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
|
| 19 |
-
print(f"Agent
|
| 20 |
-
return
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
+
# Initialize model
|
| 17 |
+
model = OpenAIServerModel(model_id="gpt-4o")
|
| 18 |
+
# Add search tool
|
| 19 |
+
search_tool = DuckDuckGoSearchTool()
|
| 20 |
+
|
| 21 |
+
# Initialize CodeAgent with system prompt
|
| 22 |
+
self.agent = CodeAgent(model=model, tools=[search_tool])
|
| 23 |
+
|
| 24 |
+
SYSTEM_PROMPT = """
|
| 25 |
+
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 26 |
+
FINAL ANSWER: [YOUR FINAL ANSWER]
|
| 27 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 28 |
+
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.
|
| 29 |
+
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.
|
| 30 |
+
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.
|
| 31 |
+
|
| 32 |
+
Example:
|
| 33 |
+
QUESTION: The largest countries by land area are Russia, Canada, and China. I verified this through common knowledge and geographic data.
|
| 34 |
+
|
| 35 |
+
FINAL ANSWER: Russia, Canada, China
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
+
self.agent.prompt_templates["system_prompt"] += SYSTEM_PROMPT
|
| 39 |
+
|
| 40 |
+
|
| 41 |
def __call__(self, question: str) -> str:
|
| 42 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 43 |
+
answer = self.agent.run(question)
|
| 44 |
+
print(f"Agent returned answer: {answer}")
|
| 45 |
+
return answer
|
| 46 |
|
| 47 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 48 |
"""
|