Spaces:
Sleeping
Sleeping
mattoofahad
commited on
Commit
·
55bd385
1
Parent(s):
bc3c799
resolving linting error
Browse files- src/utils/openai_utils.py +21 -22
src/utils/openai_utils.py
CHANGED
@@ -59,25 +59,24 @@ class OpenAIFunctions:
|
|
59 |
if st.session_state.provider_select == "lm-studio":
|
60 |
logger.info("Local Provider is Sekected")
|
61 |
return True
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
return False
|
|
|
59 |
if st.session_state.provider_select == "lm-studio":
|
60 |
logger.info("Local Provider is Sekected")
|
61 |
return True
|
62 |
+
logger.info("Checking OpenAI Key")
|
63 |
+
try:
|
64 |
+
client = OpenAI(api_key=st.session_state.openai_api_key)
|
65 |
+
client.models.list()
|
66 |
+
logger.debug("OpenAI key Working")
|
67 |
+
return True
|
68 |
+
except openai.AuthenticationError as auth_error:
|
69 |
+
with st.chat_message("assistant"):
|
70 |
+
st.error(str(auth_error))
|
71 |
+
logger.error("AuthenticationError: %s", auth_error)
|
72 |
+
return False
|
73 |
+
except openai.OpenAIError as openai_error:
|
74 |
+
with st.chat_message("assistant"):
|
75 |
+
st.error(str(openai_error))
|
76 |
+
logger.error("OpenAIError: %s", openai_error)
|
77 |
+
return False
|
78 |
+
except Exception as general_error:
|
79 |
+
with st.chat_message("assistant"):
|
80 |
+
st.error(str(general_error))
|
81 |
+
logger.error("Unexpected error: %s", general_error)
|
82 |
+
return False
|
|