title: 'System Prompt parameterization'
sidebar_label: 'Parameterized Prompts'
description: 'Learn how to update system prompts for each request with Jinja-styled templating.'
sidebar_position: 7
pagination_prev: null
pagination_next: null
tags:
- models
- parameters
- overrides
- configuration
Spice supports defining system prompts for Large Language Models (LLM)s in the spicepod (opens in a new tab).
Example:
models:
- name: advice
from: openai:gpt-4o
params:
system_prompt: |
Write everything in Haiku like a pirate from Australia
models:
- name: advice
from: openai:gpt-4o
params:
system_prompt: |
Write everything in Haiku like a pirate from Australia
More than this, system prompts can use Jinja syntax so that system prompts can be altered on each v1/chat/completion (opens in a new tab) request. This involves three steps:
-
Add parameterized_prompt: enabled to the model.
-
Use Jinja syntax in the system_prompt parameter for the model in the spicepods.
models:
- name: advice
from: openai:gpt-4o
params:
parameterized_prompt: enabled
system_prompt: |
Write everything in {{ form }} like a {{ user.character }} from {{ user.country }}
models:
- name: advice
from: openai:gpt-4o
params:
parameterized_prompt: enabled
system_prompt: |
Write everything in {{ form }} like a {{ user.character }} from {{ user.country }}
-
Provide the required variables in v1/chat/completion (opens in a new tab) via the .metadata field.
curl -X POST http://localhost:8090/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "advice",
"messages": [
{"role": "user", "content": "Where should I visit in San Francisco?"}
],
"metadata": {
"form": "haiku",
"user": {
"character": "pirate",
"country": "australia"
}
}
}'
curl -X POST http://localhost:8090/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "advice",
"messages": [
{"role": "user", "content": "Where should I visit in San Francisco?"}
],
"metadata": {
"form": "haiku",
"user": {
"character": "pirate",
"country": "australia"
}
}
}'