arxiv_chatbot / chat /consumers.py
Artteiv's picture
Refactoring gemini functions (#9)
3826b3b verified
raw
history blame
853 Bytes
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}))