Daniel Marques commited on
Commit
3c4d8f2
1 Parent(s): 42d6b9c

fix: add tokenWs

Browse files
Files changed (1) hide show
  1. main.py +17 -10
main.py CHANGED
@@ -14,7 +14,7 @@ from langchain.chains import RetrievalQA
14
  from langchain.embeddings import HuggingFaceInstructEmbeddings
15
  from langchain.prompts import PromptTemplate
16
  from langchain.memory import ConversationBufferMemory
17
- from langchain.callbacks.base import BaseCallbackHandler
18
  from langchain.schema import LLMResult
19
 
20
  # from langchain.embeddings import HuggingFaceEmbeddings
@@ -35,9 +35,9 @@ tokenWS = ''
35
 
36
  class MyCustomHandler(BaseCallbackHandler):
37
  def on_llm_new_token(self, token: str, **kwargs) -> None:
38
- global tokenWS
39
 
40
- tokenWS = token
41
 
42
  print(f" token: {tokenWS}")
43
 
@@ -73,11 +73,14 @@ RETRIEVER = DB.as_retriever()
73
 
74
  LLM = load_model(device_type=DEVICE_TYPE, model_id=MODEL_ID, model_basename=MODEL_BASENAME, stream=True, callbacks=[MyCustomHandler()])
75
 
76
- template = """you are a helpful, respectful and honest assistant. When answering questions, you should only use the documents provided.
77
- You should only answer the topics that appear in these documents.
78
- Always answer in the most helpful and reliable way possible, if you don't know the answer to a question, just say you don't know, don't try to make up an answer,
79
- don't share false information. you should use no more than 15 sentences and all your answers should be as concise as possible.
80
- Always say "Thank you for asking!" at the end of your answer.
 
 
 
81
  Context: {history} \n {context}
82
  Question: {question}
83
  """
@@ -245,11 +248,15 @@ async def create_upload_file(file: UploadFile):
245
  @api_app.websocket("/ws")
246
  async def websocket_endpoint(websocket: WebSocket):
247
  global QA
 
248
 
249
  await websocket.accept()
250
  while True:
 
 
 
251
  data = await websocket.receive_text()
252
 
253
- res = QA(data)
254
 
255
- await websocket.send_text(f"Message text was: {tokenWS}")
 
14
  from langchain.embeddings import HuggingFaceInstructEmbeddings
15
  from langchain.prompts import PromptTemplate
16
  from langchain.memory import ConversationBufferMemory
17
+ from langchain.callbacks.base import BaseCallbackHandler, AsyncCallbackHandler
18
  from langchain.schema import LLMResult
19
 
20
  # from langchain.embeddings import HuggingFaceEmbeddings
 
35
 
36
  class MyCustomHandler(BaseCallbackHandler):
37
  def on_llm_new_token(self, token: str, **kwargs) -> None:
38
+ global websocketClient
39
 
40
+ websocketClient.send_text(f"Message text was: {tokenWS}")
41
 
42
  print(f" token: {tokenWS}")
43
 
 
73
 
74
  LLM = load_model(device_type=DEVICE_TYPE, model_id=MODEL_ID, model_basename=MODEL_BASENAME, stream=True, callbacks=[MyCustomHandler()])
75
 
76
+ template = """you are a helpful, respectful and honest assistant.
77
+ Your name is Katara llma. You should only use the source documents provided to answer the questions.
78
+ You should only respond only topics that contains in documents use to training.
79
+ Use the following pieces of context to answer the question at the end.
80
+ Always answer in the most helpful and safe way possible.
81
+ If you don't know the answer to a question, just say that you don't know, don't try to make up an answer, don't share false information.
82
+ Use 15 sentences maximum. Keep the answer as concise as possible.
83
+ Always say "thanks for asking!" at the end of the answer.
84
  Context: {history} \n {context}
85
  Question: {question}
86
  """
 
248
  @api_app.websocket("/ws")
249
  async def websocket_endpoint(websocket: WebSocket):
250
  global QA
251
+ global websocketClient
252
 
253
  await websocket.accept()
254
  while True:
255
+ global websocketClient
256
+ websocketClient = websocket;
257
+
258
  data = await websocket.receive_text()
259
 
260
+ QA(data)
261
 
262
+ await websocket.send_text(f"Message text was:")