TheBlueberry-AI commited on
Commit
4d41c1d
1 Parent(s): 207dcbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -11,30 +11,28 @@ messages = [{"role": "system",
11
  "content": "You are a friendly AI assistant and an expert in health ."}]
12
 
13
 
14
- def CustomOpenChat(user_input):
15
  messages.append({"role": "user", "content": user_input})
16
  response = openai.ChatCompletion.create(
17
  model="gpt-3.5-turbo",
 
18
  messages=messages,
19
- max_tokens=256,
20
- temperature=0.3,
21
  top_p=0.95
22
  )
23
- OpenChat_reply = response["choices"][0]["message"]["content"]
24
- messages.append({"role": "assistant", "content": OpenChat_reply})
25
- return OpenChat_reply
26
-
27
-
28
- def chat_response(message, history):
29
- result = CustomOpenChat(message)
30
- return result
31
 
32
 
33
  mychatbot = gr.Chatbot(
34
  avatar_images=["./user.png", "./aibot.png"], bubble_full_width=False, show_label=False, show_copy_button=True,)
35
 
36
 
37
- demo = gr.ChatInterface(fn=chat_response,
38
  chatbot=mychatbot,
39
  title="🫐BuruBuru Chat🫐",
40
  retry_btn=None,
 
11
  "content": "You are a friendly AI assistant and an expert in health ."}]
12
 
13
 
14
+ def ChatResponse(user_input, history):
15
  messages.append({"role": "user", "content": user_input})
16
  response = openai.ChatCompletion.create(
17
  model="gpt-3.5-turbo",
18
+ stream=True,
19
  messages=messages,
20
+ max_tokens=512,
21
+ temperature=0.5,
22
  top_p=0.95
23
  )
24
+ partial_response = ""
25
+ for stream_response in response:
26
+ token = stream_response["choices"][0]["delta"].get("content", "")
27
+ partial_response += token
28
+ yield partial_response
 
 
 
29
 
30
 
31
  mychatbot = gr.Chatbot(
32
  avatar_images=["./user.png", "./aibot.png"], bubble_full_width=False, show_label=False, show_copy_button=True,)
33
 
34
 
35
+ demo = gr.ChatInterface(fn=ChatResponse,
36
  chatbot=mychatbot,
37
  title="🫐BuruBuru Chat🫐",
38
  retry_btn=None,