Zevol commited on
Commit
df030af
1 Parent(s): 44b9816
Files changed (1) hide show
  1. main +22 -0
main ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ def predict(message, history):
3
+ history_openai_format = []
4
+ for human, assistant in history:
5
+ history_openai_format.append({"role": "user", "content": human })
6
+ history_openai_format.append({"role": "assistant", "content":assistant})
7
+ history_openai_format.append({"role": "user", "content": message})
8
+
9
+ response = openai.ChatCompletion.create(
10
+ model='gpt-3.5-turbo',
11
+ messages= history_openai_format,
12
+ temperature=1.0,
13
+ stream=True
14
+ )
15
+
16
+ partial_message = ""
17
+ for chunk in response:
18
+ if len(chunk['choices'][0]['delta']) != 0:
19
+ partial_message = partial_message + chunk['choices'][0]['delta']['content']
20
+ yield partial_message
21
+
22
+ gr.ChatInterface(predict).launch()