Update app.py
Browse files
app.py
CHANGED
@@ -37,24 +37,23 @@ class NewAgent:
|
|
37 |
description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
|
38 |
)
|
39 |
# Generate the chat interface, including the tools
|
40 |
-
llm = HuggingFaceEndpoint(
|
41 |
-
repo_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
42 |
-
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
43 |
-
)
|
44 |
-
chat = ChatHuggingFace(llm=llm, verbose=True)
|
45 |
tools = [
|
46 |
search_tool,
|
47 |
# weather_info_tool,
|
48 |
hub_stats_tool,
|
49 |
]
|
50 |
-
|
|
|
|
|
51 |
# Generate the AgentState and Agent graph
|
52 |
class AgentState(TypedDict):
|
53 |
messages: Annotated[list[AnyMessage], add_messages]
|
54 |
def assistant(state: AgentState):
|
|
|
55 |
return {
|
56 |
-
"messages": [
|
57 |
}
|
|
|
58 |
## The graph
|
59 |
builder = StateGraph(AgentState)
|
60 |
# Define nodes: these do the work
|
|
|
37 |
description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
|
38 |
)
|
39 |
# Generate the chat interface, including the tools
|
|
|
|
|
|
|
|
|
|
|
40 |
tools = [
|
41 |
search_tool,
|
42 |
# weather_info_tool,
|
43 |
hub_stats_tool,
|
44 |
]
|
45 |
+
llm = ChatOpenAI(model="gpt-4o")
|
46 |
+
llm_with_tools = llm.bind_tools(tools, parallel_tool_calls=False)
|
47 |
+
|
48 |
# Generate the AgentState and Agent graph
|
49 |
class AgentState(TypedDict):
|
50 |
messages: Annotated[list[AnyMessage], add_messages]
|
51 |
def assistant(state: AgentState):
|
52 |
+
sys_msg = SystemMessage(content=f"You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.")
|
53 |
return {
|
54 |
+
"messages": [llm_with_tools.invoke([sys_msg] + state["messages"])],
|
55 |
}
|
56 |
+
|
57 |
## The graph
|
58 |
builder = StateGraph(AgentState)
|
59 |
# Define nodes: these do the work
|