Spaces:
Sleeping
Sleeping
Update 250309:1927
Browse filesSigue la limpieza...
app.py
CHANGED
|
@@ -7,53 +7,7 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
# Here we suppose that the textual description of the tools has already been appended
|
| 12 |
-
SYSTEM_PROMPT = """Answer the following questions as best you can. You have access to the following tools:
|
| 13 |
-
|
| 14 |
-
get_current_time_in_timezone: Fetches the current local time in a specified timezone
|
| 15 |
-
|
| 16 |
-
The way you use the tools is by specifying a json blob.
|
| 17 |
-
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).
|
| 18 |
-
|
| 19 |
-
The only values that should be in the "action" field are:
|
| 20 |
-
get_current_time_in_timezone: Get the current current local time in a specified timezone, args: {"timezone": {"type": "string"}}
|
| 21 |
-
example use :
|
| 22 |
-
```
|
| 23 |
-
{{
|
| 24 |
-
"action": "get_current_time_in_timezone",
|
| 25 |
-
"action_input": {"timezone": 'America/New_York'}
|
| 26 |
-
}}
|
| 27 |
-
|
| 28 |
-
ALWAYS use the following format:
|
| 29 |
-
|
| 30 |
-
Question: the input question you must answer
|
| 31 |
-
Thought: you should always think about one action to take. Only one action at a time in this format:
|
| 32 |
-
Action:
|
| 33 |
-
```
|
| 34 |
-
$JSON_BLOB
|
| 35 |
-
```
|
| 36 |
-
Observation: the result of the action. This Observation is unique, complete, and the source of truth.
|
| 37 |
-
... (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.)
|
| 38 |
-
|
| 39 |
-
You must always end your output with the following format:
|
| 40 |
-
|
| 41 |
-
Thought: I now know the final answer
|
| 42 |
-
Final Answer: the final answer to the original input question
|
| 43 |
-
|
| 44 |
-
Now begin! Reminder to ALWAYS use the exact characters `Final Answer:` when you provide a definitive answer. """
|
| 45 |
-
|
| 46 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 47 |
-
@tool
|
| 48 |
-
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 49 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 50 |
-
"""A tool that does nothing yet
|
| 51 |
-
Args:
|
| 52 |
-
arg1: the first argument
|
| 53 |
-
arg2: the second argument
|
| 54 |
-
"""
|
| 55 |
-
return "What magic will you build ?"
|
| 56 |
-
|
| 57 |
@tool
|
| 58 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 59 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -69,12 +23,11 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 69 |
except Exception as e:
|
| 70 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 71 |
|
| 72 |
-
|
| 73 |
final_answer = FinalAnswerTool()
|
| 74 |
|
|
|
|
| 75 |
# 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:
|
| 76 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 77 |
-
|
| 78 |
model = HfApiModel(
|
| 79 |
max_tokens=2096,
|
| 80 |
temperature=0.5,
|
|
@@ -82,16 +35,10 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
|
|
| 82 |
custom_role_conversions=None,
|
| 83 |
)
|
| 84 |
|
| 85 |
-
# new_prompt=prompt+output+get_current_time_in_timezone('{input}')
|
| 86 |
-
|
| 87 |
-
# Import tool from Hub
|
| 88 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 89 |
|
| 90 |
with open("prompts.yaml", 'r') as stream:
|
| 91 |
prompt_templates = yaml.safe_load(stream)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
agent = CodeAgent(
|
| 96 |
model=model,
|
| 97 |
tools=[get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
#Available tools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@tool
|
| 12 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 13 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 23 |
except Exception as e:
|
| 24 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 25 |
|
|
|
|
| 26 |
final_answer = FinalAnswerTool()
|
| 27 |
|
| 28 |
+
|
| 29 |
# 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:
|
| 30 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 31 |
model = HfApiModel(
|
| 32 |
max_tokens=2096,
|
| 33 |
temperature=0.5,
|
|
|
|
| 35 |
custom_role_conversions=None,
|
| 36 |
)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
with open("prompts.yaml", 'r') as stream:
|
| 40 |
prompt_templates = yaml.safe_load(stream)
|
| 41 |
|
|
|
|
|
|
|
| 42 |
agent = CodeAgent(
|
| 43 |
model=model,
|
| 44 |
tools=[get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
|