Update app.py
Browse files
app.py
CHANGED
|
@@ -38,12 +38,48 @@ final_answer = FinalAnswerTool()
|
|
| 38 |
|
| 39 |
# 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
|
|
@@ -55,7 +91,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer],
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 38 |
|
| 39 |
# 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:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 41 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, load_tool, tool
|
| 42 |
+
import datetime
|
| 43 |
+
import requests
|
| 44 |
+
import pytz
|
| 45 |
+
import yaml
|
| 46 |
+
from tools.final_answer import FinalAnswerTool
|
| 47 |
+
|
| 48 |
+
from Gradio_UI import GradioUI
|
| 49 |
+
|
| 50 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 51 |
+
@tool
|
| 52 |
+
def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type
|
| 53 |
+
# Keep this format for the tool description / args description but feel free to modify the tool
|
| 54 |
+
"""A tool that does nothing yet
|
| 55 |
+
Args:
|
| 56 |
+
arg1: the first argument
|
| 57 |
+
arg2: the second argument
|
| 58 |
+
"""
|
| 59 |
+
return "What magic will you build ?"
|
| 60 |
+
|
| 61 |
+
@tool
|
| 62 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 63 |
+
"""A tool that fetches the current local time in a specified timezone.
|
| 64 |
+
Args:
|
| 65 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 66 |
+
"""
|
| 67 |
+
try:
|
| 68 |
+
# Create timezone object
|
| 69 |
+
tz = pytz.timezone(timezone)
|
| 70 |
+
# Get current time in that timezone
|
| 71 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 72 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 73 |
+
except Exception as e:
|
| 74 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 75 |
|
| 76 |
+
|
| 77 |
+
final_answer = FinalAnswerTool()
|
| 78 |
+
model = InferenceClientModel(
|
| 79 |
+
max_tokens=2096,
|
| 80 |
+
temperature=0.5,
|
| 81 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 82 |
+
custom_role_conversions=None,
|
| 83 |
)
|
| 84 |
|
| 85 |
|
|
|
|
| 91 |
|
| 92 |
agent = CodeAgent(
|
| 93 |
model=model,
|
| 94 |
+
tools=[final_answer], # add your tools here (don't remove final_answer)
|
| 95 |
max_steps=6,
|
| 96 |
verbosity_level=1,
|
| 97 |
grammar=None,
|