乐闻世界logo
搜索文章和话题

What is Ollama's Modelfile and how to create custom models?

2月19日 19:50

Ollama uses Modelfile to define and customize models. Modelfile is a text file, similar to Dockerfile, used to describe how to build and configure models.

Basic Modelfile Structure:

dockerfile
FROM llama3.1 PARAMETER temperature 0.7 PARAMETER top_p 0.9 PARAMETER num_ctx 4096 SYSTEM You are a helpful assistant. TEMPLATE """ {{- range .Messages }} {{- if eq .Role "user" }}User: {{ .Content }} {{- else if eq .Role "assistant" }}Assistant: {{ .Content }} {{- end }} {{- end }} Assistant: """

Common Instructions:

  1. FROM - Specify base model
dockerfile
FROM llama3.1:8b
  1. PARAMETER - Set model parameters
dockerfile
PARAMETER temperature 0.7 PARAMETER top_p 0.9 PARAMETER num_ctx 4096 PARAMETER repeat_penalty 1.1
  1. SYSTEM - Set system prompt
dockerfile
SYSTEM You are an expert Python developer.
  1. TEMPLATE - Customize prompt template
dockerfile
TEMPLATE """ <|user|> {{ .Prompt }}<|end|> <|assistant|> """
  1. LICENSE - Add license information
dockerfile
LICENSE MIT
  1. MESSAGE - Add example conversations
dockerfile
MESSAGE user Hello MESSAGE assistant Hi there!

Creating Custom Models:

bash
# Create Modelfile cat > Modelfile << EOF FROM llama3.1 SYSTEM You are a coding assistant specialized in Python. PARAMETER temperature 0.5 EOF # Build model ollama create my-coder -f Modelfile # Run custom model ollama run my-coder

View Model's Modelfile:

bash
ollama show --modelfile my-coder
标签:Ollama