These examples show you how to use the AI SDK with Next.js and FastAPI.
Execute create-next-app
with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example https://github.com/vercel/ai/tree/main/examples/next-fastapi next-fastapi-app
yarn create next-app --example https://github.com/vercel/ai/tree/main/examples/next-fastapi next-fastapi-app
pnpm create next-app --example https://github.com/vercel/ai/tree/main/examples/next-fastapi next-fastapi-app
You will also need Python 3.6+ and virtualenv installed to run the FastAPI server.
To run the example locally you need to:
- Sign up at OpenAI's Developer Platform.
- Go to OpenAI's dashboard and create an API KEY.
- Set the required environment variables as shown in the example env file but in a new file called
.env.local
. virtualenv venv
to create a python virtual environment.source venv/bin/activate
to activate the python virtual environment.pip install -r requirements.txt
to install the required python dependencies.pnpm install
to install the required dependencies.pnpm dev
to launch the development server.
To learn more about the AI SDK, Next.js, and FastAPI take a look at the following resources:
- AI SDK Docs - view documentation and reference for the AI SDK.
- Vercel AI Playground - try different models and choose the best one for your use case.
- Next.js Docs - learn about Next.js features and API.
- FastAPI Docs - learn about FastAPI features and API.
Below is a brief README-style explanation for running DeepSeek-R1 locally with Ollama.
This guide explains how to run DeepSeek-R1 on your local machine using Ollama.
- Download: Visit the Ollama website and download the installer for your operating system.
- Install: Install Ollama as you would any other application.
-
Open Terminal: Launch your terminal or command prompt.
-
Run the Model:
ollama run deepseek-r1
This command automatically downloads the DeepSeek-R1 model (default size) and runs a sample prompt.
-
Alternate Model Sizes (optional):
ollama run deepseek-r1:<size>b
Replace
<size>
with1.5
,7
,8
,14
,32
,70
, or671
to download/run smaller or larger versions.
To keep DeepSeek-R1 running in the background and serve requests via an API:
ollama serve
This exposes DeepSeek-R1 at http://localhost:11434/api/chat
for integration with other applications.
- CLI: Once DeepSeek-R1 is running, simply type:
ollama run deepseek-r1
- API: Use
curl
to chat with DeepSeek-R1 via the local server:curl http://localhost:11434/api/chat -d '{ "model": "deepseek-r1", "messages": [{ "role": "user", "content": "Hello DeepSeek, how are you?" }], "stream": false }'
-
Python Integration: Use the
ollama
Python package to integrate DeepSeek-R1 into applications:import ollama response = ollama.chat( model="deepseek-r1", messages=[{"role": "user", "content": "Hi DeepSeek!"}], ) print(response["message"]["content"])
-
Gradio App: Build a simple web interface (e.g., for RAG tasks) using Gradio.
For more details on prompt construction, chunk splitting, or building retrieval-based applications (RAG), refer to the official documentation and tutorials.
- Ollama Documentation
- DeepSeek-R1 Article (replace
#
with your desired URL if available)