Tiles
Download
Skip to Content
Tilekit

Tilekit

CLI

Commands in this section are for developers using Modelfiles with the Tiles CLI.

Prompt optimization

The Tiles CLI includes DSRs (dspy-rs) to optimize SYSTEM prompts in Modelfiles automatically. Use tiles optimize to refine the SYSTEM prompt in your Modelfile with the COPRO optimizer.

tiles optimize <MODELFILE_PATH> [--data <path>] [--model <provider:model-name>] # Optimize SYSTEM prompt in Modelfile

By default, this will:

  • Generate 5 synthetic examples automatically if you do not provide your own training data
  • Use openai:gpt-4o-mini as the optimization model
  • Update your Modelfile in-place with the improved SYSTEM prompt

Examples

# Optimize SYSTEM prompt in a Modelfile tiles optimize path/to/Modelfile # Optimize with custom training data tiles optimize ./Modelfile --data training-data.json # Optimize using a specific model tiles optimize ./Modelfile --model anthropic:claude-3-5-sonnet-20240620

Options

  • --data <path>: Provide your own training data as a JSON file
  • --model <provider:model-name>: Specify a different model to use for optimization

Requirements

Your Modelfile must contain a starting SYSTEM prompt so the optimizer knows what to build on.

Training data format

If you supply your own data, use JSON like this:

[ { "input": "User query here", "output": "Expected AI response here" } ]

Example

Modelfile:

FROM llama3 SYSTEM "You are a helpful assistant."

Optimize using Claude:

export ANTHROPIC_API_KEY=sk-ant-... tiles optimize ./Modelfile --model anthropic:claude-3-5-sonnet-20240620

This rewrites the SYSTEM line with an improved version from the optimization run.

SDK Reference

Modelfile

The Modelfile parser is implemented in src/core/modelfile.rs using the nom parser combinator library. It parses a text-based configuration format for defining model configurations, parameters, templates, and system prompts.

Grammar

The Modelfile grammar follows this structure:

command -> Instruction arguments* Instruction -> "FROM" | "PARAMETER" | "TEMPLATE" | "SYSTEM" | "ADAPTER" | "LICENSE" | "MESSAGE" | "#" arguments -> WORD | quoted_string | multiline_string quoted_string -> "<str>" multiline_string -> """<str>"""

Supported Instructions

FROM (Required)

The FROM instruction specifies the base model to use. This is the only required instruction in a Modelfile.

Syntax:

FROM <model_name>

Examples:

FROM llama3.2 FROM llama3.2:latest FROM /path/to/model.gguf FROM mlx-community/dolphin3.0-llama3.2-1B-4Bit

Validation:

  • Only one FROM instruction is allowed per Modelfile
  • A Modelfile without a FROM instruction will fail validation
PARAMETER

The PARAMETER instruction sets model inference parameters. Multiple parameters can be specified.

Syntax:

PARAMETER <parameter_name> <value>

Supported Parameters:

Integer Parameters:

  • num_ctx - Context window size
  • repeat_last_n - Number of tokens to consider for repeat penalty
  • seed - Random seed for generation
  • num_predict - Maximum number of tokens to predict
  • top_k - Top-k sampling parameter

Float Parameters:

  • temperature - Sampling temperature (0.0 to 1.0+)
  • repeat_penalty - Penalty for repeating tokens
  • top_p - Nucleus sampling parameter
  • min_p - Minimum probability threshold

String Parameters:

  • stop - Stop sequence (can be specified multiple times)

Examples:

PARAMETER num_ctx 4096 PARAMETER temperature 0.7 PARAMETER stop "<|eot_id|>" PARAMETER stop "</s>" PARAMETER top_p 0.9 PARAMETER seed 42

Validation:

  • Parameter names are case-insensitive
  • Integer parameters must parse as valid i32 values
  • Float parameters must parse as valid f32 values
  • Invalid parameter types will result in an error
TEMPLATE

The TEMPLATE instruction defines the prompt template for the model. Only one template is allowed.

Syntax:

TEMPLATE <template_string>

Examples:

TEMPLATE """{{ if .System }}<|start_header_id|>system<|end_header_id|> {{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|> {{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|> {{ .Response }}<|eot_id|>"""

Validation:

  • Only one TEMPLATE instruction is allowed per Modelfile
  • Template can be specified as a single-line string, quoted string, or multiline string
SYSTEM

The SYSTEM instruction sets the system prompt for the model. Only one system prompt is allowed.

Syntax:

SYSTEM <system_prompt>

Examples:

SYSTEM "You are a helpful assistant." SYSTEM """ You are a bot You also not a bot """

Validation:

  • Only one SYSTEM instruction is allowed per Modelfile
  • System prompt can be specified as a single-line string, quoted string, or multiline string
ADAPTER

The ADAPTER instruction specifies a path to a LoRA adapter file. Only one adapter is allowed.

Syntax:

ADAPTER <adapter_path>

Examples:

ADAPTER /path/to/adapter.bin ADAPTER ./adapters/my_adapter.safetensors

Validation:

  • Only one ADAPTER instruction is allowed per Modelfile
LICENSE

The LICENSE instruction specifies the license text for the model. Only one license is allowed.

Syntax:

LICENSE <license_text>

Examples:

LICENSE "MIT" LICENSE """ Apache License Version 2.0, January 2004 ... """

Validation:

  • Only one LICENSE instruction is allowed per Modelfile
  • License text can be specified as a single-line string, quoted string, or multiline string
MESSAGE

The MESSAGE instruction defines example messages for few-shot learning or conversation examples. Multiple messages can be specified.

Syntax:

MESSAGE <role> <message_content>

Supported Roles:

  • system - System message
  • user - User message
  • assistant - Assistant message

Examples:

MESSAGE user """Is Toronto in Canada? or Is cologne in france""" MESSAGE assistant yes MESSAGE user Is Sacramento in Canada? MESSAGE assistant no

Validation:

  • Role must be one of: system, user, or assistant (case-insensitive)
  • Invalid roles will result in an error
Comments

Comments are supported using the # character. Comments are preserved in the parsed Modelfile.

Syntax:

# <comment_text>

Examples:

# Modelfile generated by "ollama show" # To build a new Modelfile based on this one, replace the FROM line with: FROM llama3.2 # This is a comment

String Formats

The parser supports three string formats for instruction arguments:

  1. Single-line strings: Plain text until end of line

    FROM llama3.2
  2. Quoted strings: Text enclosed in double quotes "

    SYSTEM "You are a helpful assistant."
  3. Multiline strings: Text enclosed in triple quotes """

    SYSTEM """ You are a bot You also not a bot """