LONGYKING
commited on
Commit
·
cd787aa
1
Parent(s):
efcb7ec
fixed token streaming
Browse files- chatxbt-assistant.py +11 -13
chatxbt-assistant.py
CHANGED
|
@@ -94,14 +94,7 @@ async def start():
|
|
| 94 |
|
| 95 |
# Initialize the assistant
|
| 96 |
cxbt_assistant = Assistant(
|
| 97 |
-
llm=OpenAIChat(
|
| 98 |
-
api_key=os.getenv("PORTKEY_API_KEY"),
|
| 99 |
-
base_url=os.getenv("PORTKEY_LOCAL_GATEWAY_URL") or PORTKEY_GATEWAY_URL,
|
| 100 |
-
default_headers=createHeaders(
|
| 101 |
-
api_key=os.getenv("PORTKEY_API_KEY") or None,
|
| 102 |
-
config=portkey_config
|
| 103 |
-
),
|
| 104 |
-
),
|
| 105 |
tools=[
|
| 106 |
DuckDuckGo(),
|
| 107 |
CryptoDataTools(),
|
|
@@ -130,16 +123,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 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
# Run the Chainlit application
|
| 145 |
if __name__ == "__main__":
|
|
|
|
| 94 |
|
| 95 |
# Initialize the assistant
|
| 96 |
cxbt_assistant = Assistant(
|
| 97 |
+
llm=OpenAIChat(),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
tools=[
|
| 99 |
DuckDuckGo(),
|
| 100 |
CryptoDataTools(),
|
|
|
|
| 123 |
@cl.on_message
|
| 124 |
async def main(message: cl.Message):
|
| 125 |
|
| 126 |
+
msg = cl.Message(content="")
|
| 127 |
+
await msg.send()
|
| 128 |
+
|
| 129 |
# Retrieve the assistant from the user session
|
| 130 |
agent = cl.user_session.get("agent")
|
| 131 |
|
| 132 |
# Process the user message using the assistant
|
|
|
|
| 133 |
for delta in agent.run(message.content, stream=True):
|
| 134 |
+
for part in delta:
|
| 135 |
+
if token := part or "":
|
| 136 |
+
# Send the response back to the user
|
| 137 |
+
print(token)
|
| 138 |
+
await msg.stream_token(token)
|
| 139 |
+
|
| 140 |
+
await msg.update()
|
| 141 |
|
| 142 |
# Run the Chainlit application
|
| 143 |
if __name__ == "__main__":
|