Spaces:
Sleeping
Sleeping
Made the agent conversational without memory
Browse files
agent.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
from dotenv import load_dotenv
|
3 |
from huggingface_hub import InferenceClient
|
4 |
-
from smolagents import CodeAgent, Model, ChatMessage
|
5 |
import tools.tools as tls # Your tool definitions
|
6 |
|
7 |
load_dotenv()
|
@@ -61,18 +61,23 @@ class BasicAgent:
|
|
61 |
def __init__(self):
|
62 |
print("β
BasicAgent initialized with Hugging Face chat model.")
|
63 |
self.model = HuggingFaceChatModel()
|
64 |
-
|
65 |
-
|
66 |
self.agent = CodeAgent(
|
67 |
tools=[tls.search_tool, tls.calculate_cargo_travel_time],
|
68 |
model=self.model,
|
69 |
-
memory=self.memory,
|
70 |
additional_authorized_imports=["pandas"],
|
71 |
max_steps=20,
|
72 |
)
|
73 |
|
74 |
-
def __call__(self,
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
print(f"π₯ Received question: {question[:60]}...")
|
76 |
response = self.agent.run(question)
|
77 |
print(f"π€ Response generated: {response[:60]}...")
|
78 |
return response
|
|
|
|
1 |
import os
|
2 |
from dotenv import load_dotenv
|
3 |
from huggingface_hub import InferenceClient
|
4 |
+
from smolagents import CodeAgent, Model, ChatMessage
|
5 |
import tools.tools as tls # Your tool definitions
|
6 |
|
7 |
load_dotenv()
|
|
|
61 |
def __init__(self):
|
62 |
print("β
BasicAgent initialized with Hugging Face chat model.")
|
63 |
self.model = HuggingFaceChatModel()
|
64 |
+
|
|
|
65 |
self.agent = CodeAgent(
|
66 |
tools=[tls.search_tool, tls.calculate_cargo_travel_time],
|
67 |
model=self.model,
|
|
|
68 |
additional_authorized_imports=["pandas"],
|
69 |
max_steps=20,
|
70 |
)
|
71 |
|
72 |
+
def __call__(self, messages) -> str:
|
73 |
+
# Extract last user message from the chat history
|
74 |
+
if isinstance(messages, list):
|
75 |
+
question = messages[-1]["content"] # Gradio gives list of dicts
|
76 |
+
else:
|
77 |
+
question = messages # Fallback if it's just a string
|
78 |
+
|
79 |
print(f"π₯ Received question: {question[:60]}...")
|
80 |
response = self.agent.run(question)
|
81 |
print(f"π€ Response generated: {response[:60]}...")
|
82 |
return response
|
83 |
+
|