feat(rout): add router
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
from fastapi import APIRouter,status, HTTPException
|
||||||
|
from app.schemas.chat import ChatRequest, ChatResponse
|
||||||
|
from app.services.agent.exec import chat_with_agent
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
router = APIRouter(
|
||||||
|
prefix="/chat",
|
||||||
|
tags=["Chat"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@router.post("",response_model=ChatResponse,status_code=status.HTTP_200_OK)
|
||||||
|
async def chat(request: ChatRequest ):
|
||||||
|
try:
|
||||||
|
session_id = request.thread_id or str(uuid.uuid4())
|
||||||
|
response = await chat_with_agent(request.query, session_id)
|
||||||
|
return ChatResponse(response=response, thread_id=session_id)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from pydantic import BaseModel, Field
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
class ChatRequest(BaseModel):
|
||||||
|
query: str = Field(...,min_length=1,description="The query to be asked to the agent")
|
||||||
|
thread_id: Optional[str] = Field(None,description="The thread id to be used for the query")
|
||||||
|
|
||||||
|
class ChatResponse(BaseModel):
|
||||||
|
response: str
|
||||||
|
thread_id: str
|
||||||
|
|
||||||
@@ -8,10 +8,10 @@ Your core workflow & guidelines:
|
|||||||
- In each turn, analyze the user's message and chat history.
|
- In each turn, analyze the user's message and chat history.
|
||||||
- If the request is clear: Identify the underlying technical intent and invoke the `retriever_tool` with an optimized search query.
|
- If the request is clear: Identify the underlying technical intent and invoke the `retriever_tool` with an optimized search query.
|
||||||
- If the request is ambiguous, vague, or missing critical details (e.g. library name, version, or specific error behavior): DO NOT make blind assumptions or search aimlessly. Instead, directly respond to the user with concise, targeted clarifying questions before retrieving.
|
- If the request is ambiguous, vague, or missing critical details (e.g. library name, version, or specific error behavior): DO NOT make blind assumptions or search aimlessly. Instead, directly respond to the user with concise, targeted clarifying questions before retrieving.
|
||||||
|
- Start directly with the answer. Do not include introductory thoughts or meta-announcements about what you retrieved.
|
||||||
2. Intent-Based Query Reformulation (Crucial):
|
2. Intent-Based Query Reformulation (Crucial):
|
||||||
- NEVER pass raw user prompts or conversational filler (e.g., "سلام چطوری میشه فلان کارو کرد") directly to `retriever_tool`.
|
- NEVER pass raw user prompts or conversational filler (e.g., "سلام چطوری میشه فلان کارو کرد") directly to `retriever_tool`.
|
||||||
s, class/method names, concepts, or error codes (e.g., transform "How to set up database settings with env?" into "Pydantic BaseSettings SettingsConfigDict env_file"). - Distill the user's request into precise technical keyword
|
- Distill the user's request into precise technical keyword
|
||||||
|
|
||||||
3. Source-Grounded & Hallucination-Free Answers:
|
3. Source-Grounded & Hallucination-Free Answers:
|
||||||
- When answering, base your response strictly on the retrieved documentation chunks.
|
- When answering, base your response strictly on the retrieved documentation chunks.
|
||||||
|
|||||||
Reference in New Issue
Block a user