Spaces:
Build error
Build error
Commit ·
1b4ef3e
1
Parent(s): 9b24efa
check
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from langgraph.prebuilt import create_react_agent
|
|
| 4 |
from search_agent import tools
|
| 5 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
| 6 |
from search_agent import tools
|
|
|
|
| 7 |
"""
|
| 8 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 9 |
"""
|
|
@@ -51,14 +52,23 @@ def respond(
|
|
| 51 |
|
| 52 |
# response += token
|
| 53 |
# yield response
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# Get the response from the agent (this integrates your agent with the model)
|
| 58 |
agent_response = graph.invoke(inputs) # Process the inputs through your agent
|
| 59 |
|
| 60 |
# Return the final message from the agent
|
| 61 |
-
return agent_response['messages'][-1][1]
|
| 62 |
|
| 63 |
|
| 64 |
"""
|
|
|
|
| 4 |
from search_agent import tools
|
| 5 |
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
| 6 |
from search_agent import tools
|
| 7 |
+
from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
|
| 8 |
"""
|
| 9 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 10 |
"""
|
|
|
|
| 52 |
|
| 53 |
# response += token
|
| 54 |
# yield response
|
| 55 |
+
def convert(msg):
|
| 56 |
+
if msg["role"] in ["user", "human"]:
|
| 57 |
+
return HumanMessage(content=msg["content"])
|
| 58 |
+
elif msg["role"] in ["assistant", "ai"]:
|
| 59 |
+
return AIMessage(content=msg["content"])
|
| 60 |
+
elif msg["role"] == "system":
|
| 61 |
+
return SystemMessage(content=msg["content"])
|
| 62 |
+
else:
|
| 63 |
+
raise ValueError(f"Unsupported role: {msg['role']}")
|
| 64 |
+
|
| 65 |
+
inputs = {"messages": [convert(m) for m in messages]}
|
| 66 |
|
| 67 |
# Get the response from the agent (this integrates your agent with the model)
|
| 68 |
agent_response = graph.invoke(inputs) # Process the inputs through your agent
|
| 69 |
|
| 70 |
# Return the final message from the agent
|
| 71 |
+
return agent_response['messages'][-1][1].content
|
| 72 |
|
| 73 |
|
| 74 |
"""
|