Spaces:
Sleeping
Sleeping
add prompts and first agent draft
Browse files- app.py +19 -2
- prompts.yaml +17 -0
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -40,13 +42,28 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 40 |
|
| 41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 42 |
try:
|
| 43 |
-
agent = BasicAgent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
print(f"Error instantiating agent: {e}")
|
| 46 |
return f"Error initializing agent: {e}", None
|
| 47 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 48 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 49 |
-
print(agent_code)
|
| 50 |
|
| 51 |
# 2. Fetch Questions
|
| 52 |
print(f"Fetching questions from: {questions_url}")
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from smolagents import CodeAgent, ToolCallingAgent, InferenceClientModel, WebSearchTool, LiteLLMModel, HfApiModel
|
| 7 |
+
import yaml
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 42 |
|
| 43 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 44 |
try:
|
| 45 |
+
#agent = BasicAgent()
|
| 46 |
+
model = HfApiModel(
|
| 47 |
+
max_tokens=2096,
|
| 48 |
+
temperature=0.5,
|
| 49 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 50 |
+
custom_role_conversions=None,
|
| 51 |
+
)
|
| 52 |
+
with open("prompts.yaml", 'r') as stream:
|
| 53 |
+
prompt_templates = yaml.safe_load(stream)
|
| 54 |
+
agent = CodeAgent(
|
| 55 |
+
model=model,
|
| 56 |
+
tools=[WebSearchTool()],
|
| 57 |
+
max_steps=10,
|
| 58 |
+
verbosity_level=1,
|
| 59 |
+
prompt_templates=prompt_templates
|
| 60 |
+
)
|
| 61 |
except Exception as e:
|
| 62 |
print(f"Error instantiating agent: {e}")
|
| 63 |
return f"Error initializing agent: {e}", None
|
| 64 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 65 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
| 66 |
+
#print(agent_code)
|
| 67 |
|
| 68 |
# 2. Fetch Questions
|
| 69 |
print(f"Fetching questions from: {questions_url}")
|
prompts.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"system_prompt": |-
|
| 2 |
+
You are a general AI assistant. You will be asked a question.
|
| 3 |
+
Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 4 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
| 5 |
+
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.
|
| 6 |
+
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.
|
| 7 |
+
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.
|
| 8 |
+
|
| 9 |
+
Other rules you should always follow to solve your task:
|
| 10 |
+
- Use only variables that you have defined!
|
| 11 |
+
- Always use the right arguments for the tools.
|
| 12 |
+
- Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.
|
| 13 |
+
- Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
|
| 14 |
+
- Never create any notional variables in our code, as having these in your logs will derail you from the true variables.
|
| 15 |
+
- You can use imports in your code, but only from the following list of modules: {{authorized_imports}}
|
| 16 |
+
- The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.
|
| 17 |
+
- Don't give up! You're in charge of solving the task, not providing directions to solve it.
|