MCPcopy Create free account
hub / github.com/TAMustafa/Local_Chat_RAG / chat

Function chat

backend/app/main.py:190–214  ·  view source on GitHub ↗

Chat endpoint: supports hybrid retrieval (keywords, metadata, MMR, k). Accepts ChatRequest body or legacy query params.

(
    chat_req: ChatRequest = None,
    question: str = Query(None, min_length=3, max_length=500),
    file_id: int = Query(None),
    db: Session = Depends(get_db)
)

Source from the content-addressed store, hash-verified

188
189@app.post("/api/chat", response_model=ChatResponse)
190def chat(
191 chat_req: ChatRequest = None,
192 question: str = Query(None, min_length=3, max_length=500),
193 file_id: int = Query(None),
194 db: Session = Depends(get_db)
195) -> ChatResponse:
196 """
197 Chat endpoint: supports hybrid retrieval (keywords, metadata, MMR, k). Accepts ChatRequest body or legacy query params.
198 """
199 # Prefer body if provided, else fallback to query params for legacy clients
200 if chat_req is not None:
201 req = chat_req
202 else:
203 req = ChatRequest(question=question, file_id=file_id)
204 return ChatResponse(**chat_service(
205 question=req.question,
206 file_id=req.file_id,
207 db=db,
208 rag_pipeline=rag_pipeline,
209 ollama_llm=ollama_llm,
210 keywords=req.keywords,
211 metadata_filter=req.metadata_filter,
212
213 k=req.k
214 ))

Callers

nothing calls this directly

Calls 3

ChatRequestClass · 0.90
ChatResponseClass · 0.90
chat_serviceFunction · 0.90

Tested by

no test coverage detected