Skip to content

Commit

Permalink
test connection with openai on settings page (#76)
Browse files Browse the repository at this point in the history
* add option to test openai connection in settings page

* add spinner when testing openai connection
  • Loading branch information
dayesouza authored Nov 4, 2024
1 parent 7ca086e commit 7601dc1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.yml text eol=lf
*.html text eol=lf
*.py text eol=lf
*.ipynb linguist-language=Python
*.toml text eol=lf
.gitattributes text eol=lf
.gitignore text eol=lf
Expand Down
33 changes: 27 additions & 6 deletions app/pages/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
)
from util.secrets_handler import SecretsHandler

from app.util import ui_components
from intelligence_toolkit.AI.defaults import DEFAULT_LOCAL_EMBEDDING_MODEL
from intelligence_toolkit.AI.utils import prepare_messages
from intelligence_toolkit.AI.vector_store import VectorStore
from intelligence_toolkit.helpers.constants import CACHE_PATH

Expand Down Expand Up @@ -139,12 +141,6 @@ def main():

if secret and len(secret) > 0:
st.info("Your key is saved securely.")
clear_btn = st.button("Clear local key")

if clear_btn:
secrets_handler.delete_secret(key)
time.sleep(0.3)
st.rerun()

if secret_input and secret_input != secret:
secrets_handler.write_secret(key, secret_input)
Expand All @@ -166,6 +162,31 @@ def main():
if deployment_name != openai_config.model:
on_change(secrets_handler, openai_model_key, deployment_name)()
st.rerun()
with col2:
if secret and len(secret) > 0:
if type_input != "OpenAI":
# streamlit alignment
for _ in range(6):
st.write("")
clear_btn = st.button("Clear local key")

if clear_btn:
secrets_handler.delete_secret(key)
time.sleep(0.3)
st.rerun()

test_btn = st.button(
"Test connection",
)
if test_btn:
message = prepare_messages("Answer with OK only", {})
try:
with st.spinner("Sending ping..."):
ui_components.generate_text(message)
st.success(f"Connection with {type_input} successful.")
except Exception as e:
st.error(f"Error: {e}")
return
st.divider()

st.subheader("Embeddings")
Expand Down

0 comments on commit 7601dc1

Please sign in to comment.