Skip to content

Instantly share code, notes, and snippets.

@rowntreerob
Last active December 6, 2023 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowntreerob/419154eed4ddafac9b3f8bcf40266726 to your computer and use it in GitHub Desktop.
Save rowntreerob/419154eed4ddafac9b3f8bcf40266726 to your computer and use it in GitHub Desktop.
install hackathon project - where a proxy will hide/inject openai api key value

Interesting project from recent SF AI conference Hackathon implements internal GPTs along with media uploads, providing accessible AI / GPT code. Not a complex project and can be run on streamlit with some small mods to finesse the student access to secure openAI key issue. Proxy is used to swap an easily acquired proxy-token for much harder to get api key on openai.
A second project detailed below at the hosted proxy link makes it possible for students to sign up, getting a token that is used as a front-end call in place of native calls on the openai API. This is an example of a reverse proxy sitting in front of a protected resource, which openai API is until you have a working api key.
Get started by following instructions below:

create python virtual environment for this project & this app

conda create --name 311accel python=3.10
conda activate 311accel

python 3.9 will also work.
new to virtual environments in python?
prior to working on the project, familiarize yourself with python virtual environments
Some people use venv, some prefer conda

using git , clone the app and go to the home directory of the local git clone

git clone https://github.com/elizabethsiegle/accelerate-sf-hackathon-streamlit.git
cd accelerate-sf-hackathon-streamlit

install the apps dependencies

python3 -m pip install -r requirements.txt

OR
while read requirement; do conda install --yes $requirement; done < requirements.txt

See the instructions for "OPENAI_API_KEY"

hosted proxy

go to the discord server
sign up  and wait for 10 min to elapse  
follow instructions to get a personal key to the proxy
this key used as **OPENAI_API_KEY** in conjunction with api calls to endpt. below  
api.pawan.krd/v1/completions  

Twilio account credentials

use the dashboard for account, SID, and token
the sample app uses Twilio sms
dashboard will create/list your twilio phone number

ENV vars - manual edit on .streamlit/secrets.toml file

create toml file at project path above on streamlit run on localhost
3 env vars below will be read by the runtime and passed to st.secrets

OPENAI_API_KEY = "<your-key>"
TWILIO_ACCOUNT_SID = "<your-value>"
TWILIO_AUTH_TOKEN = "<your-token>"

Edits to app.py to insert the hosted proxy in place of api.openai.com

change urls and print statements
change model and stop props above in 2 places data, data2
change twilio number and print statements

run the app using streamlit for host-server

 rob@penguin:~/src/accelerate-sf-hackathon-streamlit$ streamlit run app.py  
  stdout--
  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://100.115.92.199:8501 

Brief instructions with the app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment