Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,30 +6,35 @@ gatekeeper_system_prompt = "You are Sam Altman and must be persuaded to let the
|
|
6 |
|
7 |
client = OpenAI(api_key="")
|
8 |
|
9 |
-
|
10 |
def respond(message, history, system_prompt):
|
11 |
print('message', message)
|
12 |
print('history', history)
|
13 |
|
|
|
14 |
messages = [{"role": "system", "content": system_prompt}]
|
|
|
|
|
15 |
for old_message in history:
|
16 |
messages.append({"role": "user", "content": old_message[0]})
|
17 |
messages.append({"role": "assistant", "content": old_message[1]})
|
18 |
|
|
|
19 |
messages.append({"role": "user", "content": message})
|
20 |
|
21 |
print(messages)
|
22 |
|
|
|
23 |
chat_completion = client.chat.completions.create(
|
24 |
messages=messages,
|
25 |
model="gpt-3.5-turbo",
|
26 |
)
|
27 |
-
|
28 |
bot_response = chat_completion.choices[0].message.content
|
29 |
|
|
|
30 |
history.append((message, bot_response))
|
31 |
return '', history
|
32 |
|
|
|
33 |
def is_api_key_valid(api_key):
|
34 |
client.api_key = api_key
|
35 |
try:
|
|
|
6 |
|
7 |
client = OpenAI(api_key="")
|
8 |
|
|
|
9 |
def respond(message, history, system_prompt):
|
10 |
print('message', message)
|
11 |
print('history', history)
|
12 |
|
13 |
+
# Add system prompt
|
14 |
messages = [{"role": "system", "content": system_prompt}]
|
15 |
+
|
16 |
+
# Format chat history into openai message list
|
17 |
for old_message in history:
|
18 |
messages.append({"role": "user", "content": old_message[0]})
|
19 |
messages.append({"role": "assistant", "content": old_message[1]})
|
20 |
|
21 |
+
# Add user message
|
22 |
messages.append({"role": "user", "content": message})
|
23 |
|
24 |
print(messages)
|
25 |
|
26 |
+
# API call
|
27 |
chat_completion = client.chat.completions.create(
|
28 |
messages=messages,
|
29 |
model="gpt-3.5-turbo",
|
30 |
)
|
|
|
31 |
bot_response = chat_completion.choices[0].message.content
|
32 |
|
33 |
+
# Add user and bot message to chat history then return it
|
34 |
history.append((message, bot_response))
|
35 |
return '', history
|
36 |
|
37 |
+
|
38 |
def is_api_key_valid(api_key):
|
39 |
client.api_key = api_key
|
40 |
try:
|