Matthew Franglen
commited on
Commit
·
bdb1978
1
Parent(s):
145c2b2
Create the agent in a function
Browse files- src/agent.py +41 -0
- src/paths.py +5 -0
src/agent.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import yaml
|
| 2 |
+
from smolagents import CodeAgent, HfApiModel
|
| 3 |
+
|
| 4 |
+
from src.paths import PROMPT_FILE
|
| 5 |
+
from src.tools.final_answer import FinalAnswerTool
|
| 6 |
+
from src.tools.image_generation import image_generation_tool
|
| 7 |
+
from src.tools.weather import get_current_weather_in_location
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def get_agent() -> CodeAgent:
|
| 11 |
+
final_answer = FinalAnswerTool()
|
| 12 |
+
|
| 13 |
+
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 14 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 15 |
+
|
| 16 |
+
model = HfApiModel(
|
| 17 |
+
max_tokens=2096,
|
| 18 |
+
temperature=0.5,
|
| 19 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 20 |
+
custom_role_conversions=None,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
with open(PROMPT_FILE, "r") as stream:
|
| 24 |
+
prompt_templates = yaml.safe_load(stream)
|
| 25 |
+
|
| 26 |
+
agent = CodeAgent(
|
| 27 |
+
model=model,
|
| 28 |
+
tools=[
|
| 29 |
+
image_generation_tool,
|
| 30 |
+
get_current_weather_in_location,
|
| 31 |
+
final_answer,
|
| 32 |
+
],
|
| 33 |
+
max_steps=6,
|
| 34 |
+
verbosity_level=1,
|
| 35 |
+
grammar=None,
|
| 36 |
+
planning_interval=None,
|
| 37 |
+
name=None,
|
| 38 |
+
description=None,
|
| 39 |
+
prompt_templates=prompt_templates,
|
| 40 |
+
)
|
| 41 |
+
return agent
|
src/paths.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
| 4 |
+
PROMPTS_FOLDER = PROJECT_ROOT / "src" / "prompts"
|
| 5 |
+
PROMPT_FILE = PROMPTS_FOLDER / "agent.yaml"
|