Problem with my API KEY chatgpt (using st.secrets)

Hello @Goyo

Yes, it’s.

You can it in my picture.

Amr

1 Like

You got the email from OpenAI because you have the API key committed directly to GitHub which is not advisable as others might steal it and use it.

I think the issue is that you need to follow this guide which has a step by step process of adding your API key to your app when deploying to Streamlit Community Cloud, that way when you use the code I provided earlier you can then retrieve the API key from your secrets file. Try it and let me know.

3 Likes

That is why OpenAI is disabling it, as stated in their e-mail.

2 Likes

hey @Goyo

thank you very much ive understood

1 Like

hey @tonykip

thank you for your reply i will try and let you know the result,

Amr

Hey @tonykip @REPNOT @Goyo ,

I’ve just tried your solution but know I don’t have same result I mean my API KEY is still available but I have an other kind of error:

When I press analyse I have immediately this error. I followed your tutorial step by step I added my key in the settings of the app:


I hide last part of my key but it’s ended by β€œβ€ no worry.

I wrote the same name in my settings avec here :

I still have the file secrets.toml but as i can read in the tutorial i can remove it in my
case ?

I cannot understand what it’s wrong i mean i set up everything… :frowning:

I need help please :slight_smile:

Thank you very much again for your help and time I really appreciate it.

Amr

Your current error handling isn’t giving you much information about what’s going wrong. Modify your except block to print the exception like so:

except Exception as e:
    print(f"Error: {e}")
    message = "Sorry, I was not able to process your request at this time. Please try again later."

Once you run it, copy what is printed in the logs (bottom right corner of the app) and paste it here in your response.

1 Like

Hey @tonykip ,

Thank you for your answer :slight_smile:

I did what you said and this is the log:
(no error found…)


[     UTC     ] Logs for chatgpt-btc.streamlit.app/
────────────────────────────────────────────────────────────────────────────────────────
[08:52:57] πŸ–₯ Provisioning machine...
[08:52:57] πŸŽ› Preparing system...
[08:52:57] β›“ Spinning up manager process...
[09:31:55] πŸš€ Starting up repository: 'chatgptetbtc', branch: 'main', main module: 'app.py'
[09:31:55] πŸ™ Cloning repository...
[09:31:57] πŸ™ Cloning into '/mount/src/chatgptetbtc'...
Warning: Permanently added the ED25519 host key for IP address '20.29.134.23' to the list of known hosts.

[09:31:57] πŸ™ Cloned repository!
[09:31:57] πŸ™ Pulling code changes from Github...
[09:31:58] πŸ“¦ Processing dependencies...

──────────────────────────────────────── pip ───────────────────────────────────────────

Collecting openai
  Downloading openai-1.3.5-py3-none-any.whl (220 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 220.8/220.8 KB 11.6 MB/s eta 0:00:00[2023-11-28 09:31:59.049853] 
Collecting requests
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 KB 136.2 MB/s eta 0:00:00[2023-11-28 09:31:59.169200] 
Collecting streamlit
  Downloading streamlit-1.28.2-py2.py3-none-any.whl (8.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.4/8.4 MB 121.6 MB/s eta 0:00:00[2023-11-28 09:31:59.429210] 
Collecting pydantic<3,>=1.9.0
  Downloading pydantic-2.5.2-py3-none-any.whl (381 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 381.9/381.9 KB 138.9 MB/s eta 0:00:00[2023-11-28 09:31:59.931189] 
Collecting typing-extensions<5,>=4.5
  Downloading typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Collecting tqdm>4
  Downloading tqdm-4.66.1-py3-none-any.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.3/78.3 KB 103.0 MB/s eta 0:00:00[2023-11-28 09:32:00.186351] 
Collecting distro<2,>=1.7.0
  Downloading distro-1.8.0-py3-none-any.whl (20 kB)
Collecting httpx<1,>=0.23.0
  Downloading httpx-0.25.2-py3-none-any.whl (74 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.0/75.0 KB 133.2 MB/s eta 0:00:00[2023-11-28 09:32:00.333036] 
Collecting anyio<4,>=3.5.0
  Downloading anyio-3.7.1-py3-none-any.whl (80 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 80.9/80.9 KB 122.7 MB/s eta 0:00:00
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.1.0-py3-none-any.whl (104 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 104.6/104.6 KB 144.9 MB/s eta 0:00:00[2023-11-28 09:32:00.565607] 
Collecting idna<4,>=2.5
  Downloading idna-3.6-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.6/61.6 KB 113.3 MB/s eta 0:00:00[2023-11-28 09:32:00.617666] 
Collecting certifi>=2017.4.17
  Downloading certifi-2023.11.17-py3-none-any.whl (162 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 162.5/162.5 KB 147.0 MB/s eta 0:00:00[2023-11-28 09:32:00.691714] 
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.3/142.3 KB 245.4 MB/s eta 0:00:00[2023-11-28 09:32:00.909008] 
Collecting click<9,>=7.0
  Downloading click-8.1.7-py3-none-any.whl (97 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 KB 127.7 MB/s eta 0:00:00[2023-11-28 09:32:01.014205] 
Collecting pyarrow>=6.0
  Downloading pyarrow-14.0.1-cp39-cp39-manylinux_2_28_x86_64.whl (38.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.0/38.0 MB 137.3 MB/s eta 0:00:00[2023-11-28 09:32:01.486829] 
Collecting gitpython!=3.1.19,<4,>=3.0.7
  Downloading GitPython-3.1.40-py3-none-any.whl (190 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 190.6/190.6 KB 132.0 MB/s eta 0:00:00[2023-11-28 09:32:01.671730] 
Collecting altair<6,>=4.0
  Downloading altair-5.2.0-py3-none-any.whl (996 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 996.9/996.9 KB 149.3 MB/s eta 0:00:00[2023-11-28 09:32:01.742598] 
Collecting blinker<2,>=1.0.0
  Downloading blinker-1.7.0-py3-none-any.whl (13 kB)
Collecting pydeck<1,>=0.8.0b4
  Downloading pydeck-0.8.1b0-py2.py3-none-any.whl (4.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.8/4.8 MB 131.1 MB/s eta 0:00:00[2023-11-28 09:32:01.941066] 
Collecting validators<1,>=0.2
  Downloading validators-0.22.0-py3-none-any.whl (26 kB)
Collecting rich<14,>=10.14.0
  Downloading rich-13.7.0-py3-none-any.whl (240 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 240.6/240.6 KB 19.8 MB/s eta 0:00:00
Collecting tzlocal<6,>=1.1
  Downloading tzlocal-5.2-py3-none-any.whl (17 kB)
Collecting packaging<24,>=16.8
  Downloading packaging-23.2-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.0/53.0 KB 116.0 MB/s eta 0:00:00[2023-11-28 09:32:02.513466] 
Collecting python-dateutil<3,>=2.7.3
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 KB 124.9 MB/s eta 0:00:00[2023-11-28 09:32:02.612459] 
Collecting pandas<3,>=1.3.0
  Downloading pandas-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.3/12.3 MB 166.0 MB/s eta 0:00:00[2023-11-28 09:32:03.182203] 
Collecting pillow<11,>=7.1.0
  Downloading Pillow-10.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (3.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.6/3.6 MB 76.1 MB/s eta 0:00:00[2023-11-28 09:32:03.914025] 
Collecting cachetools<6,>=4.0
  Downloading cachetools-5.3.2-py3-none-any.whl (9.3 kB)
Collecting numpy<2,>=1.19.3
  Downloading numpy-1.26.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 189.7 MB/s eta 0:00:00[2023-11-28 09:32:04.743787] 
Collecting watchdog>=2.1.5
  Downloading watchdog-3.0.0-py3-none-manylinux2014_x86_64.whl (82 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.1/82.1 KB 115.8 MB/s eta 0:00:00[2023-11-28 09:32:04.971798] 
Collecting protobuf<5,>=3.20
  Downloading protobuf-4.25.1-cp37-abi3-manylinux2014_x86_64.whl (294 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 294.6/294.6 KB 188.8 MB/s eta 0:00:00[2023-11-28 09:32:05.727009] 
Collecting importlib-metadata<7,>=1.4
  Downloading importlib_metadata-6.8.0-py3-none-any.whl (22 kB)
Collecting tornado<7,>=6.0.3
  Downloading tornado-6.3.3-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (427 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 427.7/427.7 KB 278.9 MB/s eta 0:00:00[2023-11-28 09:32:05.939797] 
Collecting toml<2,>=0.10.1
  Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting tenacity<9,>=8.1.0
  Downloading tenacity-8.2.3-py3-none-any.whl (24 kB)
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 KB 192.5 MB/s eta 0:00:00[2023-11-28 09:32:06.178249] 
Collecting jsonschema>=3.0
  Downloading jsonschema-4.20.0-py3-none-any.whl (84 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 84.7/84.7 KB 148.4 MB/s eta 0:00:00[2023-11-28 09:32:06.277782] 
Collecting toolz
  Downloading toolz-0.12.0-py3-none-any.whl (55 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.8/55.8 KB 102.0 MB/s eta 0:00:00
Collecting exceptiongroup
  Downloading exceptiongroup-1.2.0-py3-none-any.whl (16 kB)
Collecting sniffio>=1.1
  Downloading sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting gitdb<5,>=4.0.1
  Downloading gitdb-4.0.11-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 KB 100.4 MB/s eta 0:00:00[2023-11-28 09:32:06.593460] 
Collecting httpcore==1.*
  Downloading httpcore-1.0.2-py3-none-any.whl (76 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.9/76.9 KB 99.5 MB/s eta 0:00:00[2023-11-28 09:32:06.691188] 
Collecting h11<0.15,>=0.13
  Downloading h11-0.14.0-py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 KB 124.9 MB/s eta 0:00:00[2023-11-28 09:32:06.760773] 
Collecting zipp>=0.5
  Downloading zipp-3.17.0-py3-none-any.whl (7.4 kB)
Collecting tzdata>=2022.1
  Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 341.8/341.8 KB 149.6 MB/s eta 0:00:00[2023-11-28 09:32:07.123908] 
Collecting pytz>=2020.1
  Downloading pytz-2023.3.post1-py2.py3-none-any.whl (502 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.5/502.5 KB 93.0 MB/s eta 0:00:00[2023-11-28 09:32:07.313921] 
Collecting pydantic-core==2.14.5
  Downloading pydantic_core-2.14.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 138.8 MB/s eta 0:00:00[2023-11-28 09:32:08.997409] 
Collecting annotated-types>=0.4.0
  Downloading annotated_types-0.6.0-py3-none-any.whl (12 kB)
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting markdown-it-py>=2.2.0
  Downloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.5/87.5 KB 136.0 MB/s eta 0:00:00[2023-11-28 09:32:09.244196] 
Collecting pygments<3.0.0,>=2.13.0
  Downloading pygments-2.17.2-py3-none-any.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 110.2 MB/s eta 0:00:00[2023-11-28 09:32:09.349063] 
Collecting smmap<6,>=3.0.1
  Downloading smmap-5.0.1-py3-none-any.whl (24 kB)
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting attrs>=22.2.0
  Downloading attrs-23.1.0-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 KB 143.6 MB/s eta 0:00:00[2023-11-28 09:32:09.918170] 
Collecting referencing>=0.28.4
  Downloading referencing-0.31.0-py3-none-any.whl (25 kB)
Collecting rpds-py>=0.7.1
  Downloading rpds_py-0.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 176.8 MB/s eta 0:00:00[2023-11-28 09:32:10.730994] 
Collecting jsonschema-specifications>=2023.03.6
  Downloading jsonschema_specifications-2023.11.1-py3-none-any.whl (17 kB)
Collecting mdurl~=0.1
  Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Installing collected packages: pytz, zipp, watchdog, validators, urllib3, tzlocal, tzdata, typing-extensions, tqdm, tornado, toolz, toml, tenacity, sniffio, smmap, six, rpds-py, pygments, protobuf, pillow, packaging, numpy, mdurl, MarkupSafe, idna, h11, exceptiongroup, distro, click, charset-normalizer, certifi, cachetools, blinker, attrs, annotated-types, requests, referencing, python-dateutil, pydantic-core, pyarrow, markdown-it-py, jinja2, importlib-metadata, httpcore, gitdb, anyio, rich, pydeck, pydantic, pandas, jsonschema-specifications, httpx, gitpython, openai, jsonschema, altair, streamlit
Successfully installed MarkupSafe-2.1.3 altair-5.2.0 annotated-types-0.6.0 anyio-3.7.1 attrs-23.1.0 blinker-1.7.0 cachetools-5.3.2 certifi-2023.11.17 charset-normalizer-3.3.2 click-8.1.7 distro-1.8.0 exceptiongroup-1.2.0 gitdb-4.0.11 gitpython-3.1.40 h11-0.14.0 httpcore-1.0.2 httpx-0.25.2 idna-3.6 importlib-metadata-6.8.0 jinja2-3.1.2 jsonschema-4.20.0 jsonschema-specifications-2023.11.1 markdown-it-py-3.0.0 mdurl-0.1.2 numpy-1.26.2 openai-1.3.5 packaging-23.2 pandas-2.1.3 pillow-10.1.0 protobuf-4.25.1 pyarrow-14.0.1 pydantic-2.5.2 pydantic-core-2.14.5 pydeck-0.8.1b0 pygments-2.17.2 python-dateutil-2.8.2 pytz-2023.3.post1 referencing-0.31.0 requests-2.31.0 rich-13.7.0 rpds-py-0.13.1 six-1.16.0 smmap-5.0.1 sniffio-1.3.0 streamlit-1.28.2 tenacity-8.2.3 toml-0.10.2 toolz-0.12.0 tornado-6.3.3 tqdm-4.66.1 typing-extensions-4.8.0 tzdata-2023.3 tzlocal-5.2 urllib3-2.1.0 validators-0.22.0 watchdog-3.0.0 zipp-3.17.0
WARNING: You are using pip version 22.0.3; however, version 23.3.1 is available.
You should consider upgrading via the '/home/adminuser/venv/bin/python -m pip install --upgrade pip' command.
Checking if Streamlit is installed
Found Streamlit version 1.28.2 in the environment

────────────────────────────────────────────────────────────────────────────────────────

[09:32:38] 🐍 Python dependencies were installed from /mount/src/chatgptetbtc/requirements.txt using pip.
Check if streamlit is installed
Streamlit is already installed
[09:32:39] πŸ“¦ Processed dependencies!

Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.




[08:52:17] πŸ™ Pulling code changes from Github...
[08:52:18] πŸ“¦ Processing dependencies...
[08:52:18] πŸ“¦ Processed dependencies!
[08:52:19] πŸ”„ Updated app!
[08:53:27] πŸš€ Starting up repository: 'chatgptetbtc', branch: 'main', main module: 'app.py'
[08:53:27] πŸ™ Cloning repository...
[08:53:28] πŸ™ Cloning into '/mount/src/chatgptetbtc'...
Warning: Permanently added the ED25519 host key for IP address '192.30.255.113' to the list of known hosts.

[08:53:28] πŸ™ Cloned repository!
[08:53:28] πŸ™ Pulling code changes from Github...
[08:53:29] πŸ“¦ Processing dependencies...

──────────────────────────────────────── pip ───────────────────────────────────────────

Collecting openai
  Downloading openai-1.3.6-py3-none-any.whl (220 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 220.9/220.9 KB 11.7 MB/s eta 0:00:00[2023-11-30 08:53:30.679893] 
Collecting requests
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 KB 206.4 MB/s eta 0:00:00[2023-11-30 08:53:30.758065] 
Collecting streamlit
  Downloading streamlit-1.28.2-py2.py3-none-any.whl (8.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.4/8.4 MB 203.8 MB/s eta 0:00:00[2023-11-30 08:53:30.930568] 
Collecting httpx<1,>=0.23.0
  Downloading httpx-0.25.2-py3-none-any.whl (74 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 75.0/75.0 KB 221.7 MB/s eta 0:00:00[2023-11-30 08:53:31.011714] 
Collecting pydantic<3,>=1.9.0
  Downloading pydantic-2.5.2-py3-none-any.whl (381 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 381.9/381.9 KB 239.7 MB/s eta 0:00:00[2023-11-30 08:53:31.295274] 
Collecting tqdm>4
  Downloading tqdm-4.66.1-py3-none-any.whl (78 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.3/78.3 KB 206.0 MB/s eta 0:00:00[2023-11-30 08:53:31.402172] 
Collecting sniffio
  Downloading sniffio-1.3.0-py3-none-any.whl (10 kB)
Collecting typing-extensions<5,>=4.5
  Downloading typing_extensions-4.8.0-py3-none-any.whl (31 kB)
Collecting anyio<4,>=3.5.0
  Downloading anyio-3.7.1-py3-none-any.whl (80 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 80.9/80.9 KB 222.0 MB/s eta 0:00:00[2023-11-30 08:53:31.519776] 
Collecting distro<2,>=1.7.0
  Downloading distro-1.8.0-py3-none-any.whl (20 kB)
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 142.3/142.3 KB 231.0 MB/s eta 0:00:00[2023-11-30 08:53:31.737272] 
Collecting urllib3<3,>=1.21.1
  Downloading urllib3-2.1.0-py3-none-any.whl (104 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 104.6/104.6 KB 225.7 MB/s eta 0:00:00[2023-11-30 08:53:31.818065] 
Collecting certifi>=2017.4.17
  Downloading certifi-2023.11.17-py3-none-any.whl (162 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 162.5/162.5 KB 251.2 MB/s eta 0:00:00[2023-11-30 08:53:31.869409] 
Collecting idna<4,>=2.5
  Downloading idna-3.6-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.6/61.6 KB 139.5 MB/s eta 0:00:00[2023-11-30 08:53:31.910264] 
Collecting pandas<3,>=1.3.0
  Downloading pandas-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.3/12.3 MB 250.1 MB/s eta 0:00:00[2023-11-30 08:53:32.294939] 
Collecting tornado<7,>=6.0.3
  Downloading tornado-6.4-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (435 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 435.4/435.4 KB 269.3 MB/s eta 0:00:00[2023-11-30 08:53:32.457565] 
Collecting packaging<24,>=16.8
  Downloading packaging-23.2-py3-none-any.whl (53 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 53.0/53.0 KB 130.4 MB/s eta 0:00:00[2023-11-30 08:53:32.524770] 
Collecting click<9,>=7.0
  Downloading click-8.1.7-py3-none-any.whl (97 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 KB 225.4 MB/s eta 0:00:00[2023-11-30 08:53:32.585654] 
Collecting importlib-metadata<7,>=1.4
  Downloading importlib_metadata-6.8.0-py3-none-any.whl (22 kB)
Collecting cachetools<6,>=4.0
  Downloading cachetools-5.3.2-py3-none-any.whl (9.3 kB)
Collecting numpy<2,>=1.19.3
  Downloading numpy-1.26.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 265.1 MB/s eta 0:00:00[2023-11-30 08:53:33.237399] 
Collecting altair<6,>=4.0
  Downloading altair-5.2.0-py3-none-any.whl (996 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 996.9/996.9 KB 281.6 MB/s eta 0:00:00[2023-11-30 08:53:33.309778] 
Collecting toml<2,>=0.10.1
  Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)
Collecting rich<14,>=10.14.0
  Downloading rich-13.7.0-py3-none-any.whl (240 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 240.6/240.6 KB 260.7 MB/s eta 0:00:00[2023-11-30 08:53:33.497920] 
Collecting validators<1,>=0.2
  Downloading validators-0.22.0-py3-none-any.whl (26 kB)
Collecting pillow<11,>=7.1.0
  Downloading Pillow-10.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (3.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.6/3.6 MB 263.6 MB/s eta 0:00:00[2023-11-30 08:53:34.005322] 
Collecting tzlocal<6,>=1.1
  Downloading tzlocal-5.2-py3-none-any.whl (17 kB)
Collecting watchdog>=2.1.5
  Downloading watchdog-3.0.0-py3-none-manylinux2014_x86_64.whl (82 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.1/82.1 KB 217.2 MB/s eta 0:00:00[2023-11-30 08:53:34.166299] 
Collecting protobuf<5,>=3.20
  Downloading protobuf-4.25.1-cp37-abi3-manylinux2014_x86_64.whl (294 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 294.6/294.6 KB 263.1 MB/s eta 0:00:00[2023-11-30 08:53:34.571273] 
Collecting python-dateutil<3,>=2.7.3
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 KB 251.7 MB/s eta 0:00:00[2023-11-30 08:53:34.617292] 
Collecting tenacity<9,>=8.1.0
  Downloading tenacity-8.2.3-py3-none-any.whl (24 kB)
Collecting pyarrow>=6.0
  Downloading pyarrow-14.0.1-cp39-cp39-manylinux_2_28_x86_64.whl (38.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.0/38.0 MB 206.7 MB/s eta 0:00:00[2023-11-30 08:53:34.989684] 
Collecting blinker<2,>=1.0.0
  Downloading blinker-1.7.0-py3-none-any.whl (13 kB)
Collecting gitpython!=3.1.19,<4,>=3.0.7
  Downloading GitPython-3.1.40-py3-none-any.whl (190 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 190.6/190.6 KB 148.5 MB/s eta 0:00:00[2023-11-30 08:53:35.159300] 
Collecting pydeck<1,>=0.8.0b4
  Downloading pydeck-0.8.1b0-py2.py3-none-any.whl (4.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.8/4.8 MB 222.1 MB/s eta 0:00:00[2023-11-30 08:53:35.226802] 
Collecting toolz
  Downloading toolz-0.12.0-py3-none-any.whl (55 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.8/55.8 KB 171.9 MB/s eta 0:00:00[2023-11-30 08:53:35.300326] 
Collecting jinja2
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 KB 244.7 MB/s eta 0:00:00[2023-11-30 08:53:35.346222] 
Collecting jsonschema>=3.0
  Downloading jsonschema-4.20.0-py3-none-any.whl (84 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 84.7/84.7 KB 200.3 MB/s eta 0:00:00[2023-11-30 08:53:35.432333] 
Collecting exceptiongroup
  Downloading exceptiongroup-1.2.0-py3-none-any.whl (16 kB)
Collecting gitdb<5,>=4.0.1
  Downloading gitdb-4.0.11-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.7/62.7 KB 205.4 MB/s eta 0:00:00[2023-11-30 08:53:35.597582] 
Collecting httpcore==1.*
  Downloading httpcore-1.0.2-py3-none-any.whl (76 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.9/76.9 KB 209.2 MB/s eta 0:00:00[2023-11-30 08:53:35.665864] 
Collecting h11<0.15,>=0.13
  Downloading h11-0.14.0-py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 KB 201.4 MB/s eta 0:00:00[2023-11-30 08:53:35.708874] 
Collecting zipp>=0.5
  Downloading zipp-3.17.0-py3-none-any.whl (7.4 kB)
Collecting tzdata>=2022.1
  Downloading tzdata-2023.3-py2.py3-none-any.whl (341 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 341.8/341.8 KB 264.6 MB/s eta 0:00:00[2023-11-30 08:53:35.923453] 
Collecting pytz>=2020.1
  Downloading pytz-2023.3.post1-py2.py3-none-any.whl (502 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 502.5/502.5 KB 258.1 MB/s eta 0:00:00[2023-11-30 08:53:36.030469] 
Collecting annotated-types>=0.4.0
  Downloading annotated_types-0.6.0-py3-none-any.whl (12 kB)
Collecting pydantic-core==2.14.5
  Downloading pydantic_core-2.14.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 270.7 MB/s eta 0:00:00[2023-11-30 08:53:37.364623] 
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting pygments<3.0.0,>=2.13.0
  Downloading pygments-2.17.2-py3-none-any.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 165.0 MB/s eta 0:00:00[2023-11-30 08:53:37.533972] 
Collecting markdown-it-py>=2.2.0
  Downloading markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 87.5/87.5 KB 132.5 MB/s eta 0:00:00[2023-11-30 08:53:37.599287] 
Collecting smmap<6,>=3.0.1
  Downloading smmap-5.0.1-py3-none-any.whl (24 kB)
Collecting MarkupSafe>=2.0
  Downloading MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25 kB)
Collecting jsonschema-specifications>=2023.03.6
  Downloading jsonschema_specifications-2023.11.1-py3-none-any.whl (17 kB)
Collecting attrs>=22.2.0
  Downloading attrs-23.1.0-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 KB 190.7 MB/s eta 0:00:00[2023-11-30 08:53:38.048044] 
Collecting referencing>=0.28.4
  Downloading referencing-0.31.1-py3-none-any.whl (25 kB)
Collecting rpds-py>=0.7.1
  Downloading rpds_py-0.13.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 298.1 MB/s eta 0:00:00[2023-11-30 08:53:38.517911] 
Collecting mdurl~=0.1
  Downloading mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Installing collected packages: pytz, zipp, watchdog, validators, urllib3, tzlocal, tzdata, typing-extensions, tqdm, tornado, toolz, toml, tenacity, sniffio, smmap, six, rpds-py, pygments, protobuf, pillow, packaging, numpy, mdurl, MarkupSafe, idna, h11, exceptiongroup, distro, click, charset-normalizer, certifi, cachetools, blinker, attrs, annotated-types, requests, referencing, python-dateutil, pydantic-core, pyarrow, markdown-it-py, jinja2, importlib-metadata, httpcore, gitdb, anyio, rich, pydeck, pydantic, pandas, jsonschema-specifications, httpx, gitpython, openai, jsonschema, altair, streamlit
Successfully installed MarkupSafe-2.1.3 altair-5.2.0 annotated-types-0.6.0 anyio-3.7.1 attrs-23.1.0 blinker-1.7.0 cachetools-5.3.2 certifi-2023.11.17 charset-normalizer-3.3.2 click-8.1.7 distro-1.8.0 exceptiongroup-1.2.0 gitdb-4.0.11 gitpython-3.1.40 h11-0.14.0 httpcore-1.0.2 httpx-0.25.2 idna-3.6 importlib-metadata-6.8.0 jinja2-3.1.2 jsonschema-4.20.0 jsonschema-specifications-2023.11.1 markdown-it-py-3.0.0 mdurl-0.1.2 numpy-1.26.2 openai-1.3.6 packaging-23.2 pandas-2.1.3 pillow-10.1.0 protobuf-4.25.1 pyarrow-14.0.1 pydantic-2.5.2 pydantic-core-2.14.5 pydeck-0.8.1b0 pygments-2.17.2 python-dateutil-2.8.2 pytz-2023.3.post1 referencing-0.31.1 requests-2.31.0 rich-13.7.0 rpds-py-0.13.2 six-1.16.0 smmap-5.0.1 sniffio-1.3.0 streamlit-1.28.2 tenacity-8.2.3 toml-0.10.2 toolz-0.12.0 tornado-6.4 tqdm-4.66.1 typing-extensions-4.8.0 tzdata-2023.3 tzlocal-5.2 urllib3-2.1.0 validators-0.22.0 watchdog-3.0.0 zipp-3.17.0
WARNING: You are using pip version 22.0.3; however, version 23.3.1 is available.
You should consider upgrading via the '/home/adminuser/venv/bin/python -m pip install --upgrade pip' command.
Checking if Streamlit is installed
Found Streamlit version 1.28.2 in the environment

────────────────────────────────────────────────────────────────────────────────────────

[08:53:56] 🐍 Python dependencies were installed from /mount/src/chatgptetbtc/requirements.txt using pip.
Check if streamlit is installed
Streamlit is already installed
[08:53:57] πŸ“¦ Processed dependencies!

Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.

Thank you very much for your help.

Amr

Thank you. I’ll try running your code with my key to troubleshoot. Will get back to you soon.

Hi @tonykip, I’m also struggling to get an OpenAI API to work on Streamlit Cloud.
st.secrets works great, also I’ve been able to get the API Key from my app Settings, but can’t make it work yet.

Thanks in advance

Can you share your code?

1 Like

In your app advanced settings store like follows:-

key=β€œxxxxx”

In your coding file just use as follows:-

import streamlit as st
from google.generative as palm
palm.configue(api_key=st.secrets['key'])

Definitely the above one will work. Done add any thing in your dashboard settings except the thing which i had mentioned above.

In my application I have used like mentioned above.

If the above mentioned pattern is giving error then simply use Google palm . I have observed that your are using chat completion model of chatgpt. Then palm will works for you.

Happy Streamlit-ing :balloon:

Hi @Alejandro_Monsalve_K,

If you’re still running into this issue, call the API key from secrets file like below:

import streamlit as st
from openai import OpenAI

client = OpenAI(
    api_key=st.secrets["openai_apikey"]
)

OpenAI changed their SDK to use client and so you should now call the API as such.

Let me know if this resolve the issue.

Hey, sorry for my delay.

you can find my code in my git repository : my repo for me everything is okay but it’s a problem linked with my api key. I mean it’s linkled with the secrets toml file (i think)

import openai
import json
import requests
import streamlit as st
import os
#from dotenv import load_dotenv

#load_dotenv()
#openai.api_key= st.secrets.openaiDetails.openai_api #os.getenv("openai_api_key")
#OPENAI_API_KEY = st.secrets.openaiDetails.openai_apikey

#openai.api_key = OPENAI_API_KEY

#openai.api_key = st.secrets.openaiDetails.openai_apikey

openai.api_key = st.secrets["openai_apikey"]


def BasicGeneration(userPrompt):
    completion= openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "user", "content": userPrompt}
        ]
    )
    return completion.choices[0].message.content

st.title('Analyse du cours du BTC grΓ’ce Γ  CHATGPT')
st.subheader(
    'ECONOMISE TES LARMES T EN AURA BESOIN POUR PLUS TARD ...')

def GetBitCoinPrices():
    # Define the API endpoint and query parameters
    url = "https://coinranking1.p.rapidapi.com/coin/Qwsogvtv82FCd/history"
    querystring = {
        "referenceCurrencyUuid": "yhjMzLPhuIDl",
        "timePeriod": "7d"
    }
    # Define the request headers with API key and host
    headers = {
        "X-RapidAPI-Key": "d1e9d1f689mshde3780b3a33e51dp18d382jsnecbc336ae076",
        "X-RapidAPI-Host": "coinranking1.p.rapidapi.com"
    }
    # Send a GET request to the API endpoint with query parameters and headers
    response = requests.request(
        "GET", url, headers=headers, params=querystring)
    # Parse the response data as a JSON object
    JSONResult = json.loads(response.text)
    # Extract the "history" field from the JSON response
    history = JSONResult["data"]["history"]
    # Extract the "price" field from each element in the "history" array and add to a list
    prices = []
    for change in history:
        prices.append(change["price"])
    # Join the list of prices into a comma-separated string
    pricesList = ','.join(prices)
    # Return the comma-separated string of prices
    return pricesList

def AnalyzeBitCoin(bitcoinPrices):
    chatGPTPrompt = f"""You are an expert crypto trader with more than 10 years of experience, 
    I will provide you with a list of bitcoin prices for the last 7 days
    can you provide me with a technical analysis
    of Bitcoin based on these prices. here is what I want: 
    Price Overview, 
    Moving Averages, 
    Relative Strength Index (RSI),
    Moving Average Convergence Divergence (MACD),
    Advice and Suggestion,
    Do I buy or sell?
    Please be as detailed as you can, and explain in a way any beginner can understand. and make sure to use headings
    Here is the price list: {bitcoinPrices}"""

    try:
        completion = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[

                {"role": "user", "content": chatGPTPrompt}
            ]
        )
        message = completion.choices[0].message.content.strip()
    except Exception as e:
        print(f"Error: {e}")
        message = "Sorry, I was not able to process your request at this time. Please try again later."
    return message


if st.button('Analyze'):
    with st.spinner('Getting Bitcoin Prices...'):
        bitcoinPrices = GetBitCoinPrices()
        st.success('Done!')
    with st.spinner('Analyzing Bitcoin Prices...'):
        analysis = AnalyzeBitCoin(bitcoinPrices)
        st.text_area("Analysis", analysis,
                     height=500, max_chars=None, key=None,)
        st.success('Done!')

@tonykip my main file

the key is disabled no worry about this point.

But the main thing @Amr_Lgh is how mentioned your key is streamlit cloud dashboard. The correct structure for mentioning the keys in cloud is as follows:-

openai_apikey='xxxxx'

Many of the people use as follows:-

[openai]
openai_apikey='xxxx'

The above mentioned structure will leads to api key leakage and immediately you will receive an email from open ai that your key information is leaked.

1 Like

Did this work for you eventually?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.