Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -583,6 +583,49 @@ async def followup_agent(query: FollowupQueryModel, background_tasks: Background
|
|
583 |
|
584 |
return StreamingResponse(process_response(), media_type="text/event-stream")
|
585 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
586 |
@app.post("/v3/followup-agent")
|
587 |
async def followup_agent(query: FollowupQueryModel, background_tasks: BackgroundTasks, api_key: str = Depends(verify_api_key)):
|
588 |
"""
|
|
|
583 |
|
584 |
return StreamingResponse(process_response(), media_type="text/event-stream")
|
585 |
|
586 |
+
@app.post("/v2/followup-tools-agent")
|
587 |
+
async def followup_agent(query: FollowupQueryModel, background_tasks: BackgroundTasks, api_key: str = Depends(verify_api_key)):
|
588 |
+
"""
|
589 |
+
Followup agent endpoint that provides helpful responses or generates clarifying questions based on user queries.
|
590 |
+
Requires API Key authentication via X-API-Key header.
|
591 |
+
"""
|
592 |
+
logger.info(f"Received followup agent query: {query.query}")
|
593 |
+
|
594 |
+
if query.conversation_id not in conversations:
|
595 |
+
conversations[query.conversation_id] = [
|
596 |
+
{"role": "system", "content": MULTI_AGENT_PROMPT}
|
597 |
+
]
|
598 |
+
|
599 |
+
conversations[query.conversation_id].append({"role": "user", "content": query.query})
|
600 |
+
last_activity[query.conversation_id] = time.time()
|
601 |
+
|
602 |
+
# Limit tokens in the conversation history
|
603 |
+
limited_conversation = conversations[query.conversation_id]
|
604 |
+
|
605 |
+
def process_response():
|
606 |
+
full_response = ""
|
607 |
+
for content in chat_with_llama_stream(limited_conversation, model=query.model_id):
|
608 |
+
full_response += content
|
609 |
+
yield content
|
610 |
+
|
611 |
+
logger.info(f"LLM RAW response for query: {query.query}: {full_response}")
|
612 |
+
response_content, interact, tools = parse_followup_and_tools(full_response)
|
613 |
+
|
614 |
+
result = {
|
615 |
+
"clarification": interact,
|
616 |
+
"tools":tools
|
617 |
+
}
|
618 |
+
|
619 |
+
yield "<json>" + json.dumps(result)
|
620 |
+
|
621 |
+
# Add the assistant's response to the conversation history
|
622 |
+
conversations[query.conversation_id].append({"role": "assistant", "content": full_response})
|
623 |
+
|
624 |
+
background_tasks.add_task(update_db, query.user_id, query.conversation_id, query.query, full_response)
|
625 |
+
logger.info(f"Completed followup agent response for query: {query.query}, send result: {result}")
|
626 |
+
|
627 |
+
return StreamingResponse(process_response(), media_type="text/event-stream")
|
628 |
+
|
629 |
@app.post("/v3/followup-agent")
|
630 |
async def followup_agent(query: FollowupQueryModel, background_tasks: BackgroundTasks, api_key: str = Depends(verify_api_key)):
|
631 |
"""
|