-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathchat_endpoint.py
More file actions
30 lines (23 loc) · 914 Bytes
/
chat_endpoint.py
File metadata and controls
30 lines (23 loc) · 914 Bytes
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
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):
def __init__(self, chat_graph: TracedRunnable):
self._chat_graph = chat_graph
async def achat(
self,
session_id: str,
chat_request: ChatRequest,
) -> ChatResponse:
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)