Spaces:
Sleeping
Sleeping
Refactor app.py for chat interface and update agent logic 2
Browse files
agent.py
CHANGED
|
@@ -41,7 +41,7 @@ class BasicAgent:
|
|
| 41 |
self.model = HfApiModel(
|
| 42 |
model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud",
|
| 43 |
provider="together",
|
| 44 |
-
use_auth_token=True
|
| 45 |
)
|
| 46 |
|
| 47 |
# Initialize agent once
|
|
@@ -49,7 +49,7 @@ class BasicAgent:
|
|
| 49 |
tools=[tls.search_tool, tls.calculate_cargo_travel_time],
|
| 50 |
model=self.model, # <-- use self.model instead of re-instantiating
|
| 51 |
additional_authorized_imports=["pandas"],
|
| 52 |
-
max_steps=20
|
| 53 |
)
|
| 54 |
|
| 55 |
self.chat_history = [] # Optional: for memory support later
|
|
|
|
| 41 |
self.model = HfApiModel(
|
| 42 |
model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud",
|
| 43 |
provider="together",
|
| 44 |
+
use_auth_token=True
|
| 45 |
)
|
| 46 |
|
| 47 |
# Initialize agent once
|
|
|
|
| 49 |
tools=[tls.search_tool, tls.calculate_cargo_travel_time],
|
| 50 |
model=self.model, # <-- use self.model instead of re-instantiating
|
| 51 |
additional_authorized_imports=["pandas"],
|
| 52 |
+
max_steps=20
|
| 53 |
)
|
| 54 |
|
| 55 |
self.chat_history = [] # Optional: for memory support later
|
app.py
CHANGED
|
@@ -146,8 +146,8 @@ def test_init_agent_for_chat(text_input, history):
|
|
| 146 |
# --- Agent Logic for Chat Interface ---
|
| 147 |
def handle_chat(message, history):
|
| 148 |
try:
|
| 149 |
-
|
| 150 |
-
response =
|
| 151 |
return response
|
| 152 |
except Exception as e:
|
| 153 |
return f"[ERROR] Agent failed: {str(e)}"
|
|
|
|
| 146 |
# --- Agent Logic for Chat Interface ---
|
| 147 |
def handle_chat(message, history):
|
| 148 |
try:
|
| 149 |
+
basicAgent = agent.BasicAgent()
|
| 150 |
+
response = basicAgent(message)
|
| 151 |
return response
|
| 152 |
except Exception as e:
|
| 153 |
return f"[ERROR] Agent failed: {str(e)}"
|