Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,15 @@ def echo(message, chat_history):
|
|
6 |
chat_history.append((message, bot_message))
|
7 |
return '', chat_history
|
8 |
|
9 |
-
def
|
10 |
openai.api_key = api_key
|
11 |
try:
|
12 |
-
openai.
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
return False
|
15 |
else:
|
16 |
return True
|
@@ -31,7 +35,7 @@ with gr.Blocks() as demo:
|
|
31 |
openai_key_textbox = gr.Textbox(label='OpenAI Key')
|
32 |
openai_key_button = gr.Button(value='Test OpenAI Key')
|
33 |
|
34 |
-
openai_key_button.click(
|
35 |
|
36 |
# Titles
|
37 |
with gr.Row():
|
|
|
6 |
chat_history.append((message, bot_message))
|
7 |
return '', chat_history
|
8 |
|
9 |
+
def is_api_key_valid(api_key):
|
10 |
openai.api_key = api_key
|
11 |
try:
|
12 |
+
response = openai.Completion.create(
|
13 |
+
engine="davinci",
|
14 |
+
prompt="This is a test.",
|
15 |
+
max_tokens=5
|
16 |
+
)
|
17 |
+
except:
|
18 |
return False
|
19 |
else:
|
20 |
return True
|
|
|
35 |
openai_key_textbox = gr.Textbox(label='OpenAI Key')
|
36 |
openai_key_button = gr.Button(value='Test OpenAI Key')
|
37 |
|
38 |
+
openai_key_button.click(is_api_key_valid, inputs=[openai_key_textbox], outputs=[openai_key_textbox])
|
39 |
|
40 |
# Titles
|
41 |
with gr.Row():
|