Henry Hommel commited on
Commit
c818a43
·
1 Parent(s): e4cf850

Update clbaseimplementation.py

Browse files
Files changed (1) hide show
  1. 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": "system", "content":message})
50
- cl.user_session.set("history",h)
51
  resp = ""
52
- async for stream_resp in await openai.ChatCompletion.create(
53
- model="gpt-3.5-turbo",
54
- messages=cl.user_session.get("history"),
55
- stream = True
56
- )
57
- resp += stream_resp.get("choices")[0].get("text")
58
- token = stream_resp.get("choices")[0].get("text")
59
- await msg.stream_token(token)
60
- cl.user_session.set("history",cl.user_session.get("history").append({"role": "assistant", "content":resp})
 
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()