Artin2009 commited on
Commit
2097c12
1 Parent(s): b550ebc

Update chain_app.py

Browse files
Files changed (1) hide show
  1. chain_app.py +10 -7
chain_app.py CHANGED
@@ -2060,19 +2060,22 @@ async def on_chat_start():
2060
  @cl.on_message
2061
  async def main(message: cl.Message):
2062
  chat_profile = cl.user_session.get("chat_profile")
2063
-
 
 
2064
  if chat_profile == 'neural-brain-AI':
2065
- completion = openai_client.chat.completions.create(
2066
  model="ft:gpt-3.5-turbo-1106:nb:aria1:9UWDrLJK",
2067
  messages=[
2068
  {"role": "system", "content": f"You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust and you are here to help people"},
2069
  {"role": "user", "content": message.content}
2070
- ]
 
2071
  )
2072
- model_response = completion.choices[0].message.content
2073
- await cl.Message(
2074
- content=model_response
2075
- ).send()
2076
 
2077
  elif chat_profile == "Dorna-AI":
2078
  result = hf_text_client.predict(
 
2060
  @cl.on_message
2061
  async def main(message: cl.Message):
2062
  chat_profile = cl.user_session.get("chat_profile")
2063
+
2064
+ msg = cl.Message(content="")
2065
+ await msg.send()
2066
  if chat_profile == 'neural-brain-AI':
2067
+ stream = completion = openai_client.chat.completions.create(
2068
  model="ft:gpt-3.5-turbo-1106:nb:aria1:9UWDrLJK",
2069
  messages=[
2070
  {"role": "system", "content": f"You are neural nexus official chatbot, you are made by Artin Daneshvar and Sadra Noadoust and you are here to help people"},
2071
  {"role": "user", "content": message.content}
2072
+ ],
2073
+ stream=True
2074
  )
2075
+
2076
+ async for part in stream:
2077
+ if token := part.choices[0].delta.content or "":
2078
+ await msg.stream_token(token)
2079
 
2080
  elif chat_profile == "Dorna-AI":
2081
  result = hf_text_client.predict(