This repository contains a demo application that showcases how to quickly build a Generative AI (GenAI) application using Langserve and Vercel AI SDK. The application is divided into two main parts:
- Frontend (Next.js): Located in the
app/directory, this part of the application is responsible for the user interface and interaction with the AI model. - Backend (Python with Langserve): Located in the
backend/directory, this part of the application handles the AI logic using LangChain and serves it as a REST API.
- Node.js v22
- Python 3.10
- LaTeX 最新バージョン
dockercontainerは、VSCodeによるGUIで簡単に操作可能です。
- Docker Desktopをインストールします。
- VSCodeをインストールします。
- VSCodeにdevcontainer拡張機能をインストールします。
- VSCodeでこのリポジトリを開きます。
- VSCodeの左下の「><」をクリックして、コンテナを起動します。
- コンテナで再度開くをクリックします。
- コンテナが起動し、仮想環境の中に入ることが出来ます。
-
Navigate to the
app/directory:cd app/ -
Install the required Node.js packages:
npm install
-
Create a
.env.localfile in theapp/directory and add your environment variables:NEXT_PUBLIC_API_URL=http://localhost:8000
-
Start the Next.js development server:
npm run dev
The application will be available at
http://localhost:3000.
-
Navigate to the
backend/directory:cd backend/ -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required Python packages:
pip install -r requirements.txt
-
Create a
.env.localfile in thebackend/directory and add your environment variables:OPENAI_API_KEY=your_openai_api_key
-
Start the Langserve API server:
python app.py
The API server will be available at
http://localhost:8000.
Once both the frontend and backend servers are running, you can interact with the application by navigating to http://localhost:3000 in your web browser.
- Enter a mathematical expression (e.g.,
2*10) in the input field. - Click the "Run" button.
- The result will be displayed on the page, showing the interaction between the frontend and the backend.
.
├── app/ # Next.js frontend code
│ ├── actions.tsx # Server-side actions for interacting with the backend API
│ ├── page.tsx # Main page component
│ └── ... # Other Next.js files and components
├── backend/ # Python backend code (Langserve)
│ ├── agent.py # LangChain agent definition
│ ├── app.py # FastAPI server setup with Langserve
│ └── ... # Other Python files and configurations
├── .gitignore # Git ignore file
├── README.md # This README file
└── ... # Other project files
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue if you have any suggestions or improvements.
This project is licensed under the MIT License. See the LICENSE file for more details.
This repository demonstrates how to quickly build a powerful GenAI demo application using Langserve and Vercel AI SDK. This approach is particularly useful for creating prototypes or client demos in a short amount of time. Feel free to explore and modify the code to suit your needs!