Spaces:
Sleeping
Sleeping
Henry Hommel
commited on
Commit
·
c818a43
1
Parent(s):
e4cf850
Update clbaseimplementation.py
Browse files- clbaseimplementation.py +13 -14
clbaseimplementation.py
CHANGED
|
@@ -21,6 +21,7 @@ from threading import Thread
|
|
| 21 |
import chainlit as cl
|
| 22 |
import torch
|
| 23 |
import time
|
|
|
|
| 24 |
#load model
|
| 25 |
openai.api_key = "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"
|
| 26 |
@cl.on_chat_start
|
|
@@ -34,9 +35,6 @@ async def main():
|
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
-
cl.user_session.set("llm", model)
|
| 38 |
-
cl.user_session.set("tokenizer", tokenizer)
|
| 39 |
-
|
| 40 |
# Let the user know that the system is ready
|
| 41 |
await msg.update(content=f"Chat has been loaded. You can now ask questions!")
|
| 42 |
|
|
@@ -46,16 +44,17 @@ async def main():
|
|
| 46 |
@cl.on_message
|
| 47 |
async def main(message: str):
|
| 48 |
h = cl.user_session.get("history")
|
| 49 |
-
h.append({"role": "
|
| 50 |
-
|
| 51 |
resp = ""
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
cl.user_session.set("history",
|
|
|
|
| 61 |
await msg.send()
|
|
|
|
| 21 |
import chainlit as cl
|
| 22 |
import torch
|
| 23 |
import time
|
| 24 |
+
import openai
|
| 25 |
#load model
|
| 26 |
openai.api_key = "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"
|
| 27 |
@cl.on_chat_start
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
# Let the user know that the system is ready
|
| 39 |
await msg.update(content=f"Chat has been loaded. You can now ask questions!")
|
| 40 |
|
|
|
|
| 44 |
@cl.on_message
|
| 45 |
async def main(message: str):
|
| 46 |
h = cl.user_session.get("history")
|
| 47 |
+
h.append({"role": "user", "content":message})
|
| 48 |
+
|
| 49 |
resp = ""
|
| 50 |
+
msg = cl.Message(content="")
|
| 51 |
+
async for stream_resp in await openai.ChatCompletion.acreate(model="gpt-3.5-turbo",messages=h,stream = True):
|
| 52 |
+
print(stream_resp)
|
| 53 |
+
token = stream_resp.get("choices")[0].get("delta").get("content")
|
| 54 |
+
if token:
|
| 55 |
+
resp += token
|
| 56 |
+
await msg.stream_token(token)
|
| 57 |
+
h.append({"role": "assistant", "content":resp})
|
| 58 |
+
cl.user_session.set("history",h)
|
| 59 |
+
print(h)
|
| 60 |
await msg.send()
|