-
Notifications
You must be signed in to change notification settings - Fork 0
/
KeysValidation.py
25 lines (18 loc) · 976 Bytes
/
KeysValidation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import streamlit as st
from ValidateOpenAIKey import ValidateOpenAIKEY
from ValidateHuggingFaceKey import ValidateHuggingFaceKEY
def ValidateKeyBasedOnSelection(validate_api_button,api_key_selection,api_key):
if validate_api_button:
if api_key_selection == "OPENAI":
# validate OpenAI key
st.session_state.is_validate_key = ValidateOpenAIKEY(api_key)
st.session_state.embedding_function = "OpenAI"
else:
# Validate HuggingFace Key
if ValidateHuggingFaceKEY(api_key) != 200:
st.session_state.is_validate_key = False
else:
st.session_state.is_validate_key = True
st.session_state.embedding_function = "HuggingFace"
if not st.session_state.is_validate_key:
st.sidebar.error(f'Entered {api_key_selection} key is wrong', icon="🚨")