forked from stackitcloud/rag-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_endpoint.py
More file actions
49 lines (38 loc) · 1.33 KB
/
chat_endpoint.py
File metadata and controls
49 lines (38 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Module for the use case chat endpoint."""
import logging
from langchain_core.runnables import RunnableConfig
from rag_core_api.api_endpoints.chat import Chat
from rag_core_api.models.chat_request import ChatRequest
from rag_core_api.models.chat_response import ChatResponse
from rag_core_lib.tracers.traced_runnable import TracedRunnable
logger = logging.getLogger(__name__)
class UseCaseChat(Chat):
"""Use case chat endpoint implementation."""
def __init__(self, chat_graph: TracedRunnable):
self._chat_graph = chat_graph
async def achat(
self,
session_id: str,
chat_request: ChatRequest,
) -> ChatResponse:
"""
Handle a chat request and return a chat response.
Parameters
----------
session_id : str
The session identifier for the chat.
chat_request : ChatRequest
The chat request data.
Returns
-------
ChatResponse
The chat response.
"""
config = RunnableConfig(
tags=[],
callbacks=None,
recursion_limit=25,
metadata={"session_id": session_id},
)
logger.info("Hold onto your hats, folks! The chat endpoint is now powered by UseCaseChat!")
return await self._chat_graph.ainvoke(chat_request, config)