25 lines
991 B
Python
25 lines
991 B
Python
from apps.onboarding.consumers.base import BaseOnboardingConsumer, LogType
|
|
|
|
__all__ = ["OnboardingChatConsumer"]
|
|
|
|
class OnboardingChatConsumer(BaseOnboardingConsumer):
|
|
"""
|
|
Route: /ws/onboarding/chat/<config_uuid>/
|
|
"""
|
|
|
|
config_uuid: str
|
|
|
|
def parse_extra(self):
|
|
self.config_uuid = self.scope["url_route"]["kwargs"].get("config_uuid")
|
|
|
|
async def action_message(self, data: dict):
|
|
user_query = data.get("query")
|
|
if not user_query:
|
|
return await self.send_error("Missing 'query' field in payload.")
|
|
max_tokens = self.parse_max_tokens(data.get("max_tokens"))
|
|
config = await self.get_config_for_user(self.config_uuid)
|
|
if config is None:
|
|
await self.send_error("Forbidden or Invalid Config UUID")
|
|
return
|
|
response = await self.orchestrate(user_query, config, max_tokens=max_tokens)
|
|
await self.send_log(LogType.COMPLETED, "Inferenced complete.", {"response": response})
|