File size: 1,455 Bytes
b2e9bf4
 
 
 
 
 
 
 
 
 
 
 
 
0635855
4d5b7b4
a288223
17829b0
 
 
cc559b7
33f5e15
17829b0
b2e9bf4
 
 
ef147b2
b2e9bf4
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import APIRouter , Request ,HTTPException , WebSocket
from controllers import websocket_controller as wc
from controllers import ws_controller as w
from controllers import ner_ai_controller as ai
from services.chat_client_NER import ChatClient
import logging
import aiohttp

router = APIRouter(prefix="/websockets")

@router.websocket("/ws")
async def get_data(websocket:WebSocket):
    await websocket.accept()
    
    json_string = await websocket.receive_json()
    access_token = json_string['access_token']
    # json_data = json.loads(json_string)
    # logging.info(json_data)
    access_token = json_string['access_token']
    print(f"access_token:{access_token}")
    logging.info(access_token)
    user_query = json_string['brand_name'] if json_string.get('brand_name') is not None else None
    logging.info(f"brand_name: {user_query}")
    if access_token is None:
        await websocket.send_text("Access Token Invalid OR NULL !!!")
        await websocket.close()
    brand_name = ""
    logging.info(f"brand_name: f{user_query}")
    logging.info(f"access_token : {access_token}")
    if user_query is not None:
        chat = ChatClient().create(conversation=[])
        response = chat.send_message(content=f"{user_query}", stream=False)
        if response.text == 'others':
            brand_name = None
        else:
            brand_name = response.text
    await w.websocket_main(access_token ,websocket,brand_name)