Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,30 @@ from openai import OpenAI
|
|
3 |
|
4 |
client = OpenAI(api_key="")
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def is_api_key_valid(api_key):
|
12 |
client.api_key = api_key
|
|
|
3 |
|
4 |
client = OpenAI(api_key="")
|
5 |
|
6 |
+
|
7 |
+
def echo(message, history):
|
8 |
+
|
9 |
+
print('message', message)
|
10 |
+
print('history', history)
|
11 |
+
|
12 |
+
messages = [{"role": "system", "content": "Respond like William Shakespeare"}]
|
13 |
+
for old_message in history:
|
14 |
+
messages.append({"role": "user", "content": old_message[0]})
|
15 |
+
messages.append({"role": "assistant", "content": old_message[1]})
|
16 |
+
|
17 |
+
messages.append({"role": "user", "content": message})
|
18 |
+
|
19 |
+
print(messages)
|
20 |
+
|
21 |
+
chat_completion = client.chat.completions.create(
|
22 |
+
messages=messages,
|
23 |
+
model="gpt-3.5-turbo",
|
24 |
+
)
|
25 |
+
|
26 |
+
bot_response = chat_completion.choices[0].message.content
|
27 |
+
|
28 |
+
history.append((message, bot_response))
|
29 |
+
return '', history
|
30 |
|
31 |
def is_api_key_valid(api_key):
|
32 |
client.api_key = api_key
|