My issue is that I saved my api key for openai in the secrets section when you deploy steamlit apps.
Also, I saved it in a config.toml and secrests.toml in the .streamlit folder on my private GitHub. Neither is being recognized by my app. I am not sure what to try next to get it to recognize my api key.
Are you running your app locally or is it deployed?
This is deployed.
If your app is deployed:
This is my app. https://maternalhealthlegislationapp.streamlit.app/
Here is a link to the source code. https://github.com/AndreaHobby/MaternalHealthLegislationApp/blob/main/App.py
Share the link to your app’s public GitHub repository (including a [requirements file]
I have my GitHub on Private. Here is the contents of the requirements file.
Share the full text of the error message (not a screenshot).
2023-11-05 13:55:23.305 Uncaught app exception
Traceback (most recent call last):
File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
File "/mount/src/maternalhealthapp/MomAppUpload.py", line 81, in <module>
File "/mount/src/maternalhealthapp/MomAppUpload.py", line 74, in main
answer = ask_openai_question(extracted_text, question, openai_api_key)
File "/mount/src/maternalhealthapp/MomAppUpload.py", line 44, in ask_openai_question
response = openai.Completion.create(
File "/home/adminuser/venv/lib/python3.9/site-packages/openai/api_resources/completion.py", line 25, in create
return super().create(*args, **kwargs)
File "/home/adminuser/venv/lib/python3.9/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 151, in create
) = cls.__prepare_create_request(
File "/home/adminuser/venv/lib/python3.9/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 108, in __prepare_create_request
requestor = api_requestor.APIRequestor(
File "/home/adminuser/venv/lib/python3.9/site-packages/openai/api_requestor.py", line 139, in __init__
self.api_key = key or util.default_api_key()
File "/home/adminuser/venv/lib/python3.9/site-packages/openai/util.py", line 186, in default_api_key
openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details.
- Share the Streamlit and Python versions.