Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Inform when api_key is missing #8

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,33 @@
chroma_client.heartbeat()


def api_message(api_key):
"""Inform if the api key is set."""
if api_key is None:
return st.warning("Add your OpenAI API key")

return st.success("Your API key is setup ")


def set_api_key():
"""Set the OpenAI API key."""
openai.api_key = st.session_state.api_key
st.write("Your API key is setup ")
st.session_state.api_message = api_message(openai.api_key)


openai.api_key = os.getenv("OPENAI_API_KEY")

if "api_message" not in st.session_state:
st.session_state.api_message = api_message(openai.api_key)

if os.getenv("OPENAI_API_KEY") is None:
st.warning("Add your OpenAI API key")
message = st.session_state.api_message
openai.api_key = st.text_input(
"Enter your OpenAI API key",
value="",
type="password",
key="api_key",
placeholder="Enter your OpenAI API key",
on_change=set_api_key,
label_visibility="collapsed",
)
Expand All @@ -54,7 +66,9 @@ def set_api_key():


# Query ChromaDb
query = st.text_input("Query ChromaDb", value="", placeholder="Enter query")
query = st.text_input(
"Query ChromaDb", value="", placeholder="Enter query", label_visibility="collapsed"
)
if st.button("Search"):
results = collection.query(
query_texts=[query],
Expand Down
Loading