Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,21 +6,21 @@ import ast
|
|
6 |
import openai
|
7 |
openAiKey = st.text_input(label="Input the openai key", type="password")
|
8 |
# openai.api_key = openAiKey
|
9 |
-
|
10 |
-
try:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
except Exception as e:
|
22 |
-
|
23 |
-
|
24 |
|
25 |
def get_chat_completion(prompt, model="gpt-3.5-turbo"):
|
26 |
try:
|
|
|
6 |
import openai
|
7 |
openAiKey = st.text_input(label="Input the openai key", type="password")
|
8 |
# openai.api_key = openAiKey
|
9 |
+
if openAiKey:
|
10 |
+
try:
|
11 |
+
openai.api_key = openAiKey
|
12 |
+
# Test request to check if the key is valid
|
13 |
+
openai.ChatCompletion.create(
|
14 |
+
model="gpt-3.5-turbo",
|
15 |
+
messages=[
|
16 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
17 |
+
{"role": "user", "content": "Test prompt to check OpenAI key validity."}
|
18 |
+
]
|
19 |
+
)
|
20 |
+
st.success("OpenAI key is valid!")
|
21 |
+
except Exception as e:
|
22 |
+
st.error(f"Invalid OpenAI key: {e}")
|
23 |
+
st.stop()
|
24 |
|
25 |
def get_chat_completion(prompt, model="gpt-3.5-turbo"):
|
26 |
try:
|