Ashad001 commited on
Commit
0fc0644
·
1 Parent(s): 0f5347f

agent endpoint updated

Browse files
Files changed (1) hide show
  1. app.py +32 -13
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
- agent = AVAILABLE_AGENTS[agent_name]
85
- response_text = agent(request.query)
86
- return {
87
- "agent_name": agent_name,
88
- "query": request.query,
89
- "response": response_text,
90
- }
 
 
 
 
 
 
 
91
 
92
  @app.post("/chat", response_model=dict)
93
  async def chat_with_all(request: QueryRequest):
94
- response_text = ai_system(request.query)
95
- response_text = format_response_to_markdown(response_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  return {
97
- "agent_name": "ai_system",
98
- "query": request.query,
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)