Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,17 @@ 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 |
|
|
@@ -46,9 +57,49 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
|
|
| 46 |
custom_role_conversions=None,
|
| 47 |
)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Import tool from Hub
|
| 51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
|
| 52 |
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def calculator_tool(a: int, b: int) -> int:
|
| 38 |
+
"""
|
| 39 |
+
Multiply two integers.
|
| 40 |
+
Args:
|
| 41 |
+
a: An integer
|
| 42 |
+
b: An integer
|
| 43 |
+
Output: An integer
|
| 44 |
+
"""
|
| 45 |
+
return a * b
|
| 46 |
+
|
| 47 |
|
| 48 |
final_answer = FinalAnswerTool()
|
| 49 |
|
|
|
|
| 57 |
custom_role_conversions=None,
|
| 58 |
)
|
| 59 |
|
| 60 |
+
system_message="""Answer the following questions as best you can. You have access to the following tools:
|
| 61 |
+
{tools_description}
|
| 62 |
+
|
| 63 |
+
The way you use the tools is by specifying a json blob.
|
| 64 |
+
Specifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).
|
| 65 |
+
|
| 66 |
+
The only values that should be in the "action" field are:
|
| 67 |
+
get_current_time_in_timezone: A tool that fetches the current local time in a specified timezone., args: {"timezone": {"type": "string"}}
|
| 68 |
+
calculator_tool: A tool that multiply 2 integers., args: {"a": {"type": "int"}, "b": {"type": "int"}}
|
| 69 |
+
web_search_tool: Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results., args: {"max_results": {type": "int"}, "query": {type": "str"}}, output: {}
|
| 70 |
+
image_generation_tool: This tool creates an image according to a prompt, which is a text description. args: {}
|
| 71 |
+
|
| 72 |
+
example use :
|
| 73 |
+
```
|
| 74 |
+
{{
|
| 75 |
+
"action": "get_current_time_in_timezone",
|
| 76 |
+
"action_input": {"timezone": "America/New_York"}
|
| 77 |
+
}}
|
| 78 |
+
|
| 79 |
+
ALWAYS use the following format:
|
| 80 |
+
|
| 81 |
+
Question: the input question you must answer
|
| 82 |
+
Thought: you should always think about one action to take. Only one action at a time in this format:
|
| 83 |
+
Action:
|
| 84 |
+
```
|
| 85 |
+
$JSON_BLOB
|
| 86 |
+
```
|
| 87 |
+
Observation: the result of the action. This Observation is unique, complete, and the source of truth.
|
| 88 |
+
... (this Thought/Action/Observation can repeat N times, you should take several steps when needed. The $JSON_BLOB must be formatted as markdown and only use a SINGLE action at a time.)
|
| 89 |
+
|
| 90 |
+
You must always end your output with the following format:
|
| 91 |
+
|
| 92 |
+
Thought: I now know the final answer
|
| 93 |
+
Final Answer: the final answer to the original input question
|
| 94 |
+
|
| 95 |
+
Now begin! Reminder to ALWAYS use the exact characters `Final Answer:` when you provide a definitive answer.
|
| 96 |
+
"""
|
| 97 |
+
|
| 98 |
+
|
| 99 |
|
| 100 |
# Import tool from Hub
|
| 101 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 102 |
+
web_search_tool = DuckDuckGoSearchTool()
|
| 103 |
|
| 104 |
with open("prompts.yaml", 'r') as stream:
|
| 105 |
prompt_templates = yaml.safe_load(stream)
|