Code Generation

Code

1from kern.agent import Agent
2from kern.models.vllm import VLLM
3
4agent = Agent(
5 model=VLLM(id="deepseek-ai/deepseek-coder-6.7b-instruct"),
6 description="You are an expert Python developer.",
7 markdown=True,
8)
9
10agent.print_response(
11 "Write a Python function that returns the nth Fibonacci number using dynamic programming."
12)

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install Libraries

1uv pip install -U kern-ai openai vllm

Start vLLM server

1vllm serve deepseek-ai/deepseek-coder-6.7b-instruct \
2 --dtype float32 \
3 --tool-call-parser pythonic

Run Agent

1python cookbook/11_models/vllm/code_generation.py