File size: 853 Bytes
75df934
3826b3b
75df934
 
 
 
 
 
3826b3b
9235b6d
75df934
3826b3b
75df934
3826b3b
75df934
 
f7e0e10
75df934
3826b3b
 
 
 
 
 
75df934
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
import json
from . import model_manage2 as md
from channels.generic.websocket import WebsocketConsumer


class ChatConsumer(WebsocketConsumer):
    def connect(self):
        self.accept()
        self.model, self.session = md.init_model("auto")
        
    def disconnect(self, close_code):
        del self.model, self.session
        pass
    
    def receive(self, text_data):
        text_data_json = json.loads(text_data)
        message = text_data_json["messages"]
        print(message)
        question = message[-1]['content']
        response, history_state = md.full_chain_history_question(question, self.session, mode="auto")
        # print("First answer: ",response)
        print("Session history:")
        md.print_history(history_state)
        self.send(text_data=json.dumps({"message": response}))