Spaces:
Paused
Paused
Update controllers/chat_controller.py
Browse files- controllers/chat_controller.py +33 -23
controllers/chat_controller.py
CHANGED
@@ -1,23 +1,33 @@
|
|
1 |
-
from fastapi import APIRouter, Request
|
2 |
-
from llm_model import Message
|
3 |
-
from chat_handler import handle_chat
|
4 |
-
from core import service_config, session_store, llm_models
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, Request
|
2 |
+
from llm_model import Message
|
3 |
+
from chat_handler import handle_chat
|
4 |
+
from core import service_config, session_store, llm_models
|
5 |
+
import uuid
|
6 |
+
|
7 |
+
router = APIRouter()
|
8 |
+
|
9 |
+
@router.post("/start_chat")
|
10 |
+
def start_chat(request: Request):
|
11 |
+
project_name = request.query_params.get("project_name")
|
12 |
+
if not project_name:
|
13 |
+
return {"error": "project_name parametresi gereklidir."}
|
14 |
+
|
15 |
+
session = session_store.create_session(project_name)
|
16 |
+
return {"session_id": session.session_id}
|
17 |
+
|
18 |
+
@router.post("/chat")
|
19 |
+
async def chat_endpoint(msg: Message, request: Request):
|
20 |
+
session_id = request.headers.get("X-Session-ID")
|
21 |
+
if not session_id:
|
22 |
+
return {"error": "Session ID eksik."}
|
23 |
+
|
24 |
+
session = session_store.get_session(session_id)
|
25 |
+
if not session:
|
26 |
+
return {"error": "Geçersiz veya süresi dolmuş session."}
|
27 |
+
|
28 |
+
project_name = session.project_name
|
29 |
+
llm_model = llm_models.get(project_name)
|
30 |
+
if llm_model is None:
|
31 |
+
return {"error": f"{project_name} için model yüklenmemiş."}
|
32 |
+
|
33 |
+
return await handle_chat(msg, request, None, service_config, session, llm_model)
|