Spaces:
Sleeping
Sleeping
Initial commit with full functionality extend app req tools
Browse files- app.py +25 -21
- tools/final_answer.py +10 -16
app.py
CHANGED
@@ -4,29 +4,33 @@ from tools.final_answer import FinalAnswerTool
|
|
4 |
import yaml
|
5 |
from Gradio_UI import GradioUI
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
# Load prompt templates
|
16 |
-
with open("prompts.yaml", 'r') as stream:
|
17 |
-
prompt_templates = yaml.safe_load(stream)
|
18 |
-
|
19 |
-
# Create agent
|
20 |
-
agent = CodeAgent(
|
21 |
-
model=model,
|
22 |
-
tools=[final_answer],
|
23 |
-
max_steps=6,
|
24 |
-
verbosity_level=1,
|
25 |
-
prompt_templates=prompt_templates
|
26 |
-
)
|
27 |
-
|
28 |
-
# Launch interface
|
29 |
if __name__ == "__main__":
|
|
|
|
|
30 |
GradioUI(agent).launch(
|
31 |
server_name="0.0.0.0",
|
32 |
server_port=7860
|
|
|
4 |
import yaml
|
5 |
from Gradio_UI import GradioUI
|
6 |
|
7 |
+
def create_agent():
|
8 |
+
# Initialize the final answer tool
|
9 |
+
final_answer = FinalAnswerTool()
|
10 |
+
|
11 |
+
# Load prompt templates
|
12 |
+
with open("prompts.yaml", 'r') as stream:
|
13 |
+
prompt_templates = yaml.safe_load(stream)
|
14 |
+
|
15 |
+
# Create the model
|
16 |
+
model = HfApiModel(
|
17 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
18 |
+
max_tokens=2096,
|
19 |
+
temperature=0.5
|
20 |
+
)
|
21 |
+
|
22 |
+
# Create and return the agent
|
23 |
+
return CodeAgent(
|
24 |
+
model=model,
|
25 |
+
tools=[final_answer],
|
26 |
+
max_steps=6,
|
27 |
+
verbosity_level=1,
|
28 |
+
prompt_templates=prompt_templates
|
29 |
+
)
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
if __name__ == "__main__":
|
32 |
+
# Create and launch the agent
|
33 |
+
agent = create_agent()
|
34 |
GradioUI(agent).launch(
|
35 |
server_name="0.0.0.0",
|
36 |
server_port=7860
|
tools/final_answer.py
CHANGED
@@ -1,23 +1,17 @@
|
|
1 |
# tools/final_answer.py
|
2 |
-
from
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
|
|
7 |
|
8 |
-
name: str = field(default="final_answer", init=False)
|
9 |
-
description: str = field(default="Tool to provide the final answer", init=False)
|
10 |
-
|
11 |
def __call__(self, answer: str) -> str:
|
12 |
-
"""Process and return the final
|
13 |
-
|
14 |
Args:
|
15 |
-
answer: The
|
16 |
-
|
17 |
Returns:
|
18 |
-
The processed answer
|
19 |
"""
|
20 |
-
return answer
|
21 |
-
|
22 |
-
def __str__(self) -> str:
|
23 |
-
return self.name
|
|
|
1 |
# tools/final_answer.py
|
2 |
+
from smolagents import Tool
|
3 |
+
from typing import Optional
|
4 |
|
5 |
+
class FinalAnswerTool(Tool):
|
6 |
+
"""Tool for providing final answers to user queries."""
|
7 |
+
|
8 |
+
name = "final_answer"
|
9 |
|
|
|
|
|
|
|
10 |
def __call__(self, answer: str) -> str:
|
11 |
+
"""Process and return the final answer.
|
|
|
12 |
Args:
|
13 |
+
answer: The answer text to be returned
|
|
|
14 |
Returns:
|
15 |
+
str: The processed answer
|
16 |
"""
|
17 |
+
return answer
|
|
|
|
|
|