Spaces:
Runtime error
Runtime error
clementrof
commited on
Commit
•
2e04ca7
1
Parent(s):
6d8c23b
Delete app2.py
Browse files
app2.py
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
import openai
|
2 |
-
import gradio as gr
|
3 |
-
|
4 |
-
openai.api_key = "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" # Replace with your key
|
5 |
-
|
6 |
-
def predict(message, history):
|
7 |
-
history_openai_format = []
|
8 |
-
for human, assistant in history:
|
9 |
-
history_openai_format.append({"role": "user", "content": human })
|
10 |
-
history_openai_format.append({"role": "assistant", "content":assistant})
|
11 |
-
history_openai_format.append({"role": "user", "content": message})
|
12 |
-
|
13 |
-
response = openai.ChatCompletion.create(
|
14 |
-
model='gpt-3.5-turbo',
|
15 |
-
messages= history_openai_format,
|
16 |
-
temperature=1.0,
|
17 |
-
stream=True
|
18 |
-
)
|
19 |
-
|
20 |
-
partial_message = ""
|
21 |
-
for chunk in response:
|
22 |
-
if len(chunk['choices'][0]['delta']) != 0:
|
23 |
-
partial_message = partial_message + chunk['choices'][0]['delta']['content']
|
24 |
-
yield partial_message
|
25 |
-
|
26 |
-
gr.ChatInterface(predict).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|