Upload app.py
Browse files
app.py
CHANGED
@@ -33,24 +33,36 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
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 |
-
MAX_ALLOWED_TOKENS = 16000 # Model limit
|
42 |
-
|
43 |
-
def get_safe_max_tokens(input_tokens, default_max_tokens=1200):
|
44 |
-
remaining = MAX_ALLOWED_TOKENS - input_tokens
|
45 |
-
return min(remaining, default_max_tokens) if remaining > 0 else 100 # Set minimum fallback
|
46 |
|
47 |
model = HfApiModel(
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
)
|
53 |
|
|
|
54 |
# Import tool from Hub
|
55 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
56 |
|
@@ -59,7 +71,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
59 |
|
60 |
agent = CodeAgent(
|
61 |
model=model,
|
62 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
63 |
max_steps=6,
|
64 |
verbosity_level=1,
|
65 |
grammar=None,
|
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
+
@tool
|
37 |
+
def get_current_weather_condition_in_location(location: str) -> str:
|
38 |
+
"""A tool that fetches the current weather condition in a specified location.
|
39 |
+
Args:
|
40 |
+
location: A string representing a valid location (e.g., 'New York', 'Chennai', 'Paris').
|
41 |
+
"""
|
42 |
+
try:
|
43 |
+
# Create Weather API URL
|
44 |
+
api_url = f"https://api.weatherapi.com/v1/current.json?key=80b3c1b0b84648de88b204919251802&q='{location}'"
|
45 |
+
# Get current weather condition in a location
|
46 |
+
response = requests.get(api_url)
|
47 |
+
weather_condition = response.json()["current"]["condition"]["text"]
|
48 |
+
return f"The current weather condition in {location} is: {weather_condition}"
|
49 |
+
except Exception as e:
|
50 |
+
return f"Error fetching weather condition for location '{location}': {str(e)}"
|
51 |
+
|
52 |
|
53 |
final_answer = FinalAnswerTool()
|
54 |
|
55 |
# 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:
|
56 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
model = HfApiModel(
|
59 |
+
max_tokens=2096,
|
60 |
+
temperature=0.5,
|
61 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
62 |
+
custom_role_conversions=None,
|
63 |
)
|
64 |
|
65 |
+
|
66 |
# Import tool from Hub
|
67 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
68 |
|
|
|
71 |
|
72 |
agent = CodeAgent(
|
73 |
model=model,
|
74 |
+
tools=[final_answer,get_current_time_in_timezone,image_generation_tool,get_current_weather_condition_in_location], ## add your tools here (don't remove final answer)
|
75 |
max_steps=6,
|
76 |
verbosity_level=1,
|
77 |
grammar=None,
|