Hi all,
My streamlit app works fine when locally hosted.
But as soon as I deployed it to streamlit. I can’t seem to get the API key working. I have checked more times then I can count that I have inputted the correct OpenAI API key.
here’s the repo: GitHub - ginozambe/AIToolHub
Any help would be greatly appreciated.
Hi @Gino_Zambe
How are you storing your OpenAI credentials? Is it stored in the secrets from within the secrets management in Community Cloud platform (Secrets management - Streamlit Docs ), then calling it in the app via st.secrets
Please see a step-by-step tutorial showing how in this video: https://www.youtube.com/watch?v=Z41pEtTAgfs
Hope this helps!
Goyo
February 8, 2024, 4:53pm
3
What makes you think there is a problem with your API key? The error message, albeit incomplete, seems unrelated to it.
opened 06:11PM - 18 Dec 23 UTC
closed 03:12AM - 19 Dec 23 UTC
bug
### Confirm this is an issue with the Python library and not an underlying OpenA… I API
- [X] This is an issue with the Python library
### Describe the bug
I'm trying to create a simple BOT however getting the below error.
APIRemovedInV1: You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API. You can run `openai migrate` to automatically upgrade your codebase to use the 1.0.0 interface. Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28` A detailed migration guide is available here: https://github.com/openai/openai-python/discussions/742
Validations:
Environment Check done
Upgraded OpenAI Python Library
Restarted Kernel
Validated API key
### To Reproduce
Code attached
### Code snippets
```Python
# Streamlit UI
st.title("Vitamin Quiz Bot")
# Initialize session state
if 'iteration' not in st.session_state:
st.session_state.iteration = 0
st.session_state.quiz_active = False
# Main loop for the quiz
user_input = st.text_input("You (Iteration {}):".format(st.session_state.iteration))
if user_input.lower() == "lets begin the quiz":
st.session_state.quiz_active = True
if st.session_state.quiz_active:
# Generate a question
chat_history = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Generate a question about vitamins and minerals for a 3rd-grade quiz."},
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=chat_history,
max_tokens=50,
temperature=0.7,
)
question = response['choices'][0]['message']['content'].strip()
# Display the question
st.text("Bot: {}".format(question))
# Get user's response
user_response = st.text_input("You:")
# Evaluate the response
if st.button("Submit"):
st.text("You said: {}".format(user_response))
```
### OS
windows
### Python version
Python 3.12.1
### Library version
openai 1.5.0
not sure, to be honest, still new to it all… but thank you for the link!
system
Closed
August 6, 2024, 5:42pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.