Sk4467 commited on
Commit
0844366
1 Parent(s): a0b17c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
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
- 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:
 
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: