Files
Ai/rag/views.py
T
sajad-dev 94355af62b Add LLM configuration and update URL routing
- Introduced LLM configuration in rag_config.yaml and corresponding LLMConfig class in config.py.
- Updated load_rag_config function to parse LLM settings from the configuration file.
- Added new API route for RAG in urls.py to facilitate access to the chat model.
- Modified QdrantVectorStore to use query_points method for improved functionality.
2026-02-27 19:44:49 +03:30

44 lines
1.3 KiB
Python

"""
ویوهای RAG — چت با استریم
"""
from django.http import StreamingHttpResponse
from rest_framework import status
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView
from .chat import chat_rag_stream
class ChatView(APIView):
"""
چت RAG با استریم.
POST با {"message": "متن سوال"} یا query param message
"""
def post(self, request: Request):
message = request.data.get("message") or request.query_params.get("message")
if not message or not isinstance(message, str):
return Response(
{"code": 400, "msg": "پارامتر message الزامی است."},
status=status.HTTP_400_BAD_REQUEST,
)
message = str(message).strip()
if not message:
return Response(
{"code": 400, "msg": "پیام نباید خالی باشد."},
status=status.HTTP_400_BAD_REQUEST,
)
def generate():
try:
for chunk in chat_rag_stream(message):
yield chunk
except Exception as e:
yield f"\n[خطا: {e}]"
return StreamingHttpResponse(
generate(),
content_type="text/plain; charset=utf-8",
)