models

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package models provides a code generator for model constants from models.dev.

This package allows generating Go code for model definitions from either:

  • Local TOML files (recommended for reliable builds)
  • The models.dev GitHub repository (requires API token for rate limits)

The generated code includes:

  • Model ID constants (e.g., ModelGPT4o, ModelClaudeOpus)
  • ModelInfo slice with capabilities and API endpoints
  • Model registry for quick lookups

Usage:

To regenerate model constants from local TOML files:

go run ./cmd/gen-models -provider=openai -local=./internal/gen/models/data/openai

To regenerate from models.dev (requires GitHub token):

go run ./cmd/gen-models -provider=openai -token=$GITHUB_TOKEN

The generator is designed to produce code compatible with the existing provider implementations in the providers/ directory.

Package models provides a code generator for model constants from models.dev.

Index

Constants

This section is empty.

Variables

View Source
var ProviderMapping = map[string]string{
	"openai":      "openai",
	"anthropic":   "anthropic",
	"google":      "gemini",
	"ollama":      "ollama",
	"xai":         "xai",
	"perplexity":  "perplexity",
	"huggingface": "huggingface",
}

ProviderMapping maps models.dev provider names to Iris provider packages.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client fetches model data from models.dev GitHub repository.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient creates a new models.dev client.

func (*Client) FetchProviderModels

func (c *Client) FetchProviderModels(provider string) ([]ModelData, error)

FetchProviderModels fetches all models for a given provider.

func (*Client) FetchProviders

func (c *Client) FetchProviders() ([]string, error)

FetchProviders returns the list of available providers.

type ClientOption

type ClientOption func(*Client)

ClientOption configures the Client.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client.

func WithToken

func WithToken(token string) ClientOption

WithToken sets a GitHub API token for higher rate limits.

type CostData

type CostData struct {
	Input     float64 `toml:"input"`
	Output    float64 `toml:"output"`
	CacheRead float64 `toml:"cache_read"`
	Reasoning float64 `toml:"reasoning"`
}

CostData represents pricing information.

type GeneratedModel

type GeneratedModel struct {
	ConstName    string
	ModelID      string
	DisplayName  string
	Capabilities []string
	APIEndpoint  string
	IsImageModel bool
}

GeneratedModel represents a model ready for code generation.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator creates Go source files from model data.

func NewGenerator

func NewGenerator(provider, packageName string) *Generator

NewGenerator creates a new code generator for a provider.

func (*Generator) Generate

func (g *Generator) Generate(models []ModelData) ([]byte, error)

Generate produces Go source code for the given models.

type GitHubContent

type GitHubContent struct {
	Name        string `json:"name"`
	Path        string `json:"path"`
	Type        string `json:"type"` // "file" or "dir"
	Content     string `json:"content"`
	Encoding    string `json:"encoding"`
	DownloadURL string `json:"download_url"`
}

GitHubContent represents a file/directory from the GitHub API.

type IrisFeature

type IrisFeature string

IrisFeature represents a feature constant name in Iris.

const (
	FeatureChat             IrisFeature = "core.FeatureChat"
	FeatureChatStreaming    IrisFeature = "core.FeatureChatStreaming"
	FeatureToolCalling      IrisFeature = "core.FeatureToolCalling"
	FeatureReasoning        IrisFeature = "core.FeatureReasoning"
	FeatureStructuredOutput IrisFeature = "core.FeatureStructuredOutput"
	FeatureImageGeneration  IrisFeature = "core.FeatureImageGeneration"
	FeatureEmbeddings       IrisFeature = "core.FeatureEmbeddings"
)

type LimitData

type LimitData struct {
	Context   int `toml:"context"`
	Input     int `toml:"input"`
	Output    int `toml:"output"`
	Reasoning int `toml:"reasoning"`
}

LimitData represents context and output limits.

type ModalityData

type ModalityData struct {
	Input  []string `toml:"input"`
	Output []string `toml:"output"`
}

ModalityData represents supported input/output modalities.

type ModelData

type ModelData struct {
	ID               string        `toml:"-"` // Derived from filename
	Name             string        `toml:"name"`
	Attachment       bool          `toml:"attachment"`
	Reasoning        bool          `toml:"reasoning"`
	ToolCall         bool          `toml:"tool_call"`
	StructuredOutput bool          `toml:"structured_output"`
	Temperature      bool          `toml:"temperature"`
	Knowledge        string        `toml:"knowledge"`
	ReleaseDate      string        `toml:"release_date"`
	LastUpdated      string        `toml:"last_updated"`
	OpenWeights      bool          `toml:"open_weights"`
	Status           string        `toml:"status"` // alpha, beta, deprecated
	Cost             *CostData     `toml:"cost"`
	Limit            *LimitData    `toml:"limit"`
	Modalities       *ModalityData `toml:"modalities"`
	Interleaved      any           `toml:"interleaved"` // bool or object
	API              string        `toml:"api"`         // Optional API endpoint override
}

ModelData represents a model definition from models.dev.

func LoadLocalModels

func LoadLocalModels(dir string) ([]ModelData, error)

LoadLocalModels loads model definitions from local TOML files. The directory should contain TOML files named by model ID.

type ProviderData

type ProviderData struct {
	Name        string `toml:"name"`
	URL         string `toml:"url"`
	Description string `toml:"description"`
}

ProviderData represents a provider configuration from models.dev.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL