├── .gitignore ├── README.md ├── api └── index.py ├── requirements.txt └── vercel.json /.gitignore: -------------------------------------------------------------------------------- 1 | .vercel 2 | *.log 3 | *.pyc 4 | __pycache__ 5 | 6 | # Environments 7 | .env 8 | .venv 9 | env/ 10 | venv/ 11 | ENV/ 12 | env.bak/ 13 | venv.bak/ 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fhomanp%2Fvercel-langchain) 3 | 4 | # LangChain running on Vercel 5 | 6 | A minimal example on how to run LangChain on Vercel using Flask. 7 | 8 | ## Installation 9 | 10 | #### 1. Virtualenv 11 | Create and activate `virtualenv`. 12 | 13 | ```bash 14 | virtualenv MY_ENV 15 | source MY_ENV/bin/activate 16 | ``` 17 | 18 | #### 2. Install requirements 19 | ```bash 20 | pip install requirements.txt 21 | ``` 22 | 23 | #### 3. Start development server 24 | ```bash 25 | vercel dev 26 | ``` 27 | 28 | #### 4. Example API route 29 | ```bash 30 | GET http://localhost:3000 31 | ``` 32 | 33 | ## Environment Variables 34 | 35 | To run this project, you will need to add the following environment variables to your .env file 36 | 37 | `OPENAI_API_KEY` 38 | 39 | ## One-Click Deploy 40 | 41 | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fhomanp%2Fvercel-langchain) 42 | 43 | 44 | 45 | ## Further reading 46 | 47 | Learn more about how to use LangChain by visiting the offical documentation or repo: 48 | 49 | https://langchain.readthedocs.io/en/latest/ 50 | 51 | https://github.com/hwchase17/langchain -------------------------------------------------------------------------------- /api/index.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from flask import Flask 4 | from langchain.llms import OpenAI 5 | 6 | app = Flask(__name__) 7 | 8 | @app.route('/') 9 | def home(): 10 | llm = OpenAI(temperature=0.9) 11 | text = "What would be a good company name a company that makes colorful socks?" 12 | 13 | return llm(text) 14 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.2.2 2 | langchain==0.0.113 3 | openai==0.26.4 4 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "builds": [ 3 | { 4 | "src": "api/index.py", 5 | "use": "@vercel/python" 6 | } 7 | ], 8 | "routes": [ 9 | { 10 | "src": "/(.*)", 11 | "dest": "api/index.py" 12 | } 13 | ] 14 | } --------------------------------------------------------------------------------