Exploring OpenAI via Python Packages (Streamlit, Langchain, OpenAI) and API Endpoint
- ✅ create appropriate environments for Jupyter Notebook and app(s)
- ✅ create OpenAI interactive bot script using Jupyter Notebooks
- ✅ create simple Streamlit / Langchain / OpenAI App taking text and OpenAI App Key as input
- ✅ embed .env variable for openai_api_key and incorporate check for env versus user input in app
- add ability to upload document & ask questions on data
- build on app to incorporate career history:
- pre-defined personal context: my resume, linkedin and github readme
- set prompt for users to ask questions regarding my personal data
- How to use ChatGPT API Python for Beginners - Full ChatBOT Tutorial
- Build an LLM Powered App with Langchain, Streamlit & OpenAI
- OpenAI Documentation - API Reference
- Open the Anaconda PowerShell prompt.
- Create a new environment with Python 3.9:
conda create --name envpy39 python=3.9
- Activate the environment:
conda activate envpy39
- Install required packages:
pip install -q openai python-dotenv notebook
- Open a terminal or command prompt.
- Navigate to your project directory:
cd <path>
- Create a new virtual environment:
python -m venv venv
- Activate the environment:
- On Windows (PowerShell):
.\venv\Scripts\Activate
- On macOS/Linux (bash):
source venv/bin/activate
- Install required packages:
pip install streamlit openai langchain langchain[llms]
orpip install -r requirements.txt
orpython -m pip install langchain streamlit openai
- On Windows (PowerShell):
pip list --user
(specific packages I installed)pip list
(all packages installed)
- Open the Anaconda PowerShell prompt.
- Navigate to your project directory:
cd <path>
- Activate the environment:
conda activate envpy39
- Start Jupyter Notebook:
jupyter notebook
- Open a terminal or command prompt.
- Navigate to your project directory:
cd <path>
- Activate the environment:
- On Windows (PowerShell):
.\venv\Scripts\Activate
- On macOS/Linux (bash):
source venv/bin/activate
- On Windows (PowerShell):
- Run the server using Framework:
- DRF:
python manage.py runserver
- Streamlit:
streamlit run <projectname.py>
view: http://localhost:8501/
- DRF:
Don't have an OpenAI API Key? Get one here.
- Create a file called:
.env
- Enter the following:
OPENAI_API_KEY = <yourkeyhere>
- Run the app
- Enter the OpenAI API Key in the window to the left
See:
- take pdf as input
- break into smaller pieces (chunks <=512 tokens)
- allows receiving smaller responses based on queries
- take chunks and embed one by one (1536 dimension vectors ADA-002)
- put each chunk/embedding into vector db (FAISS) -> ready for recall when user queries
- allow user to query database
- take in user query
- put through embedding model
- get back number of matched docs/embeddings
- parse through LLM (GPT3.5)
- send answer back to user
- need to upload documents to reports folder
See:
- LLM App with Langchain: Jupyter Notebook