agent endpoint updated
Browse files
app.py
CHANGED
|
@@ -79,24 +79,43 @@ async def upload_dataframe(file: UploadFile = File(...), styling_instructions: s
|
|
| 79 |
@app.post("/chat/{agent_name}", response_model=dict)
|
| 80 |
async def chat_with_agent(agent_name: str, request: QueryRequest):
|
| 81 |
if agent_name not in AVAILABLE_AGENTS:
|
| 82 |
-
raise HTTPException(status_code=404, detail="Agent not found")
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
@app.post("/chat", response_model=dict)
|
| 93 |
async def chat_with_all(request: QueryRequest):
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
return {
|
| 97 |
-
"
|
| 98 |
-
"
|
| 99 |
-
"response": response_text,
|
| 100 |
}
|
| 101 |
|
| 102 |
@app.get("/health", response_model=dict)
|
|
|
|
| 79 |
@app.post("/chat/{agent_name}", response_model=dict)
|
| 80 |
async def chat_with_agent(agent_name: str, request: QueryRequest):
|
| 81 |
if agent_name not in AVAILABLE_AGENTS:
|
| 82 |
+
raise HTTPException(status_code=404, detail=f"Agent '{agent_name}' not found. Available agents: {list(AVAILABLE_AGENTS.keys())}")
|
| 83 |
|
| 84 |
+
try:
|
| 85 |
+
print("agent_name: ", agent_name)
|
| 86 |
+
agent = AVAILABLE_AGENTS[agent_name]
|
| 87 |
+
response = agent(request.query)
|
| 88 |
+
# Format the response using the same formatter as the main chat endpoint
|
| 89 |
+
formatted_response = format_response_to_markdown(response)
|
| 90 |
+
|
| 91 |
+
return {
|
| 92 |
+
"agent_name": agent_name,
|
| 93 |
+
"query": request.query,
|
| 94 |
+
"response": formatted_response,
|
| 95 |
+
}
|
| 96 |
+
except Exception as e:
|
| 97 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 98 |
|
| 99 |
@app.post("/chat", response_model=dict)
|
| 100 |
async def chat_with_all(request: QueryRequest):
|
| 101 |
+
try:
|
| 102 |
+
response = ai_system(request.query)
|
| 103 |
+
formatted_response = format_response_to_markdown(response)
|
| 104 |
+
|
| 105 |
+
return {
|
| 106 |
+
"agent_name": "ai_system",
|
| 107 |
+
"query": request.query,
|
| 108 |
+
"response": formatted_response,
|
| 109 |
+
}
|
| 110 |
+
except Exception as e:
|
| 111 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 112 |
+
|
| 113 |
+
# Add an endpoint to list available agents
|
| 114 |
+
@app.get("/agents", response_model=dict)
|
| 115 |
+
async def list_agents():
|
| 116 |
return {
|
| 117 |
+
"available_agents": list(AVAILABLE_AGENTS.keys()),
|
| 118 |
+
"description": "List of available specialized agents that can be called using @agent_name"
|
|
|
|
| 119 |
}
|
| 120 |
|
| 121 |
@app.get("/health", response_model=dict)
|