Longy King commited on
Commit
0207cdc
·
unverified ·
2 Parent(s): 8db9d93 05b7f8b

Merge pull request #14 from chatxbt/feature/swap-tokens

Browse files
Files changed (1) hide show
  1. chatxbt-assistant.py +10 -5
chatxbt-assistant.py CHANGED
@@ -130,16 +130,21 @@ async def start():
130
  @cl.on_message
131
  async def main(message: cl.Message):
132
 
 
 
 
133
  # Retrieve the assistant from the user session
134
  agent = cl.user_session.get("agent")
135
 
136
  # Process the user message using the assistant
137
- response = ""
138
  for delta in agent.run(message.content, stream=True):
139
- response += delta
140
-
141
- # Send the response back to the user
142
- await cl.Message(content=response).send()
 
 
 
143
 
144
  # Run the Chainlit application
145
  if __name__ == "__main__":
 
130
  @cl.on_message
131
  async def main(message: cl.Message):
132
 
133
+ msg = cl.Message(content="")
134
+ await msg.send()
135
+
136
  # Retrieve the assistant from the user session
137
  agent = cl.user_session.get("agent")
138
 
139
  # Process the user message using the assistant
 
140
  for delta in agent.run(message.content, stream=True):
141
+ for part in delta:
142
+ if token := part or "":
143
+ # Send the response back to the user
144
+ print(token)
145
+ await msg.stream_token(token)
146
+
147
+ await msg.update()
148
 
149
  # Run the Chainlit application
150
  if __name__ == "__main__":