langchain v0.3.10 based gpt service with python v3.12 + streamlit v1.41 + openai v1.57
- install python 3.10 ~ 3.12 LTS and add system path on python & pip
$ python --version
Python 3.12.7 (or 3.10.11 or 3.11.9 or 3.12.8)
$ pip --version
pip 24.2 from /usr/lib/python3/dist-packages/pip (python 3.12)
- set runtime environment
$ cat .env
OPENAI_API_KEY="..."
- load runtime environment
from dotenv import dotenv_values
from langchain_openai import ChatOpenAI
config = dotenv_values(".env")
chat = ChatOpenAI(
openai_api_key=config['OPENAI_API_KEY'],
...
)
- run jupyter app in virtual environment
$ python -m venv .venv
$ source env/bin/activate
$ pip install -r requirements.txt
$ pip list
$ touch main.ipynb && code .
$ deactivate
- run jupyter app in poertry environment
$ poetry init
$ poetry shell
$ poetry install
$ poetry show
$ touch main.ipynb && code .
$ exit
- run streamlit app in root environment
$ streamlit run main.py
You can now view your Streamlit app in your browser.
Local URL: http://localhost:8501