Documentation
¶
Overview ¶
Package model contains types and utilities for parsing, validating, and working with model names and digests.
Index ¶
- Constants
- Variables
- func GenerationDefaultOptions() []string
- func IsValidNamespace(s string) bool
- func Unqualified(n Name) error
- type Capability
- type ConfigV2
- type Draft
- type GenerationDefaults
- type Name
- func (n Name) BaseURL() *url.URL
- func (n Name) DisplayNamespaceModel() string
- func (n Name) DisplayShortest() string
- func (n Name) EqualFold(o Name) bool
- func (n Name) Filepath() string
- func (n Name) IsFullyQualified() bool
- func (n Name) IsValid() bool
- func (n Name) LogValue() slog.Value
- func (n Name) String() string
- type StructuredOutputFrames
- type ThinkValue
- type Thinking
Constants ¶
const ( CapabilityCompletion = Capability("completion") CapabilityTools = Capability("tools") CapabilityInsert = Capability("insert") CapabilityVision = Capability("vision") CapabilityEmbedding = Capability("embedding") CapabilityThinking = Capability("thinking") CapabilityImage = Capability("image") CapabilityAudio = Capability("audio") CapabilityDecision = Capability("decision") CapabilitySpeech = Capability("speech") )
const MissingPart = "!MISSING!"
MissingPart is used to indicate any part of a name that was "promised" by the presence of a separator, but is missing.
The value was chosen because it is deemed unlikely to be set by a user, not a valid part name valid when checked by Name.IsValid, and easy to spot in logs.
Variables ¶
var ( // ErrUnqualifiedName represents an error where a name is not fully // qualified. It is not used directly in this package, but is here // to avoid other packages inventing their own error type. // Additionally, it can be conveniently used via [Unqualified]. ErrUnqualifiedName = errors.New("unqualified name") )
Errors
Functions ¶
func GenerationDefaultOptions ¶ added in v0.33.3
func GenerationDefaultOptions() []string
GenerationDefaultOptions returns the Ollama option names that can be populated from model-authored generation defaults.
func IsValidNamespace ¶ added in v0.1.41
IsValidNamespace reports whether the provided string is a valid namespace.
func Unqualified ¶ added in v0.1.33
Unqualified is a helper function that returns an error with ErrUnqualifiedName as the cause and the name as the message.
Types ¶
type Capability ¶ added in v0.6.4
type Capability string
func (Capability) IsValid ¶ added in v0.35.1
func (c Capability) IsValid() bool
IsValid reports whether c is recognized, such as "decision"; empty or unknown labels are invalid.
func (Capability) String ¶ added in v0.6.4
func (c Capability) String() string
type ConfigV2 ¶ added in v0.13.5
type ConfigV2 struct {
ModelFormat string `json:"model_format"`
ModelFamily string `json:"model_family"`
ModelFamilies []string `json:"model_families"`
ModelType string `json:"model_type"` // shown as Parameter Size
FileType string `json:"file_type"` // shown as Quantization Level
// GenerationDefaults stores model-authored sampler defaults. These are
// lower precedence than Modelfile PARAMETERs and request options.
GenerationDefaults GenerationDefaults `json:"generation_defaults,omitempty"`
Renderer string `json:"renderer,omitempty"`
Parser string `json:"parser,omitempty"`
Requires string `json:"requires,omitempty"`
RemoteHost string `json:"remote_host,omitempty"`
RemoteModel string `json:"remote_model,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
ContextLen int `json:"context_length,omitempty"`
EmbedLen int `json:"embedding_length,omitempty"`
// Voices names the speech voices a model takes that are not stored as
// voice tensors.
Voices []string `json:"voices,omitempty"`
BaseName string `json:"base_name,omitempty"`
Draft *Draft `json:"draft,omitempty"`
}
ConfigV2 represents the configuration metadata for a model.
func (*ConfigV2) AddCapabilities ¶ added in v0.35.1
AddCapabilities preserves inherited and inferred capabilities.
type Draft ¶ added in v0.23.1
type Draft struct {
ModelFormat string `json:"model_format,omitempty"`
Architecture string `json:"architecture,omitempty"`
TensorPrefix string `json:"tensor_prefix,omitempty"`
Config string `json:"config,omitempty"`
}
Draft describes an auxiliary draft model stored in the same manifest.
type GenerationDefaults ¶ added in v0.33.3
GenerationDefaults contains model-authored sampler defaults keyed by Ollama option names.
func ParseGGUFGenerationDefaults ¶ added in v0.33.3
func ParseGGUFGenerationDefaults(intValue func(string) (int64, bool), floatValue func(string) (float64, bool)) GenerationDefaults
ParseGGUFGenerationDefaults extracts sampler defaults from GGUF metadata.
func ParseHFGenerationDefaults ¶ added in v0.33.3
func ParseHFGenerationDefaults(data []byte) (GenerationDefaults, error)
ParseHFGenerationDefaults extracts sampler defaults from Hugging Face generation_config.json data.
type Name ¶
Name is a structured representation of a model name string, as defined by [ParseNameNoDefaults].
It is not guaranteed to be valid. Use Name.IsValid to check if the name is valid.
func DefaultName ¶ added in v0.1.33
func DefaultName() Name
DefaultName returns a name with the default values for the host, namespace, tag, and protocol scheme parts. The model and digest parts are empty.
- The default host is ("registry.ollama.ai")
- The default namespace is ("library")
- The default tag is ("latest")
- The default protocol scheme is ("https")
func Merge ¶ added in v0.1.33
Merge merges the host, namespace, tag, and protocol scheme parts of the two names, preferring the non-empty parts of a.
func ParseName ¶
ParseName parses and assembles a Name from a name string. The format of a valid name string is:
s:
{ host } "/" { namespace } "/" { model } ":" { tag } "@" { digest }
{ host } "/" { namespace } "/" { model } ":" { tag }
{ host } "/" { namespace } "/" { model } "@" { digest }
{ host } "/" { namespace } "/" { model }
{ namespace } "/" { model } ":" { tag } "@" { digest }
{ namespace } "/" { model } ":" { tag }
{ namespace } "/" { model } "@" { digest }
{ namespace } "/" { model }
{ model } ":" { tag } "@" { digest }
{ model } ":" { tag }
{ model } "@" { digest }
{ model }
"@" { digest }
host:
pattern: { alphanum | "_" } { alphanum | "-" | "_" | "." | ":" }*
length: [1, 350]
namespace:
pattern: { alphanum | "_" } { alphanum | "-" | "_" }*
length: [1, 80]
model:
pattern: { alphanum | "_" } { alphanum | "-" | "_" | "." }*
length: [1, 80]
tag:
pattern: { alphanum | "_" } { alphanum | "-" | "_" | "." }*
length: [1, 80]
digest:
pattern: { alphanum | "_" } { alphanum | "-" | ":" }*
length: [1, 80]
Most users should use ParseName instead, unless need to support different defaults than DefaultName.
The name returned is not guaranteed to be valid. If it is not valid, the field values are left in an undefined state. Use Name.IsValid to check if the name is valid.
func ParseNameBare ¶ added in v0.1.33
ParseNameBare parses s as a name string and returns a Name. No merge with DefaultName is performed.
func ParseNameFromFilepath ¶
ParseNameFromFilepath parses a 4-part filepath as a Name. The parts are expected to be in the form:
{ host } "/" { namespace } "/" { model } "/" { tag }
func (Name) DisplayNamespaceModel ¶ added in v0.15.0
DisplayNamespaceModel returns the namespace and model joined by "/".
func (Name) DisplayShortest ¶
DisplayShortest returns a short string version of the name.
func (Name) Filepath ¶
Filepath returns a canonical filepath that represents the name with each part from host to tag as a directory in the form:
{host}/{namespace}/{model}/{tag}
It uses the system's filepath separator and ensures the path is clean.
It panics if the name is not fully qualified. Use Name.IsFullyQualified to check if the name is fully qualified.
func (Name) IsFullyQualified ¶ added in v0.1.33
IsFullyQualified returns true if all parts of the name are present and valid without the digest.
func (Name) IsValid ¶
IsValid reports whether all parts of the name are present and valid. The digest is a special case, and is checked for validity only if present.
Note: The digest check has been removed as is planned to be added back in at a later time.
func (Name) String ¶ added in v0.1.33
String returns the name string, in the format that [ParseNameNoDefaults] accepts as valid, if Name.IsValid reports true; otherwise the empty string is returned.
type StructuredOutputFrames ¶ added in v0.40.17
type StructuredOutputFrames struct {
ThinkingOpen string
ThinkingClose string
ThinkingExcludes []string
ContentOpen string
}
StructuredOutputFrames describes the markers a model can emit before a structured answer. A thinking close without an open continues a thought the template already opened.
type ThinkValue ¶ added in v0.34.3
type ThinkValue struct {
// Value can be a bool or string
Value any
}
ThinkValue represents a boolean or model-defined thinking level.
func (*ThinkValue) Bool ¶ added in v0.34.3
func (t *ThinkValue) Bool() bool
Bool returns the value as a bool (true if enabled in any way)
func (*ThinkValue) IsBool ¶ added in v0.34.3
func (t *ThinkValue) IsBool() bool
IsBool returns true if the value is a boolean
func (*ThinkValue) IsString ¶ added in v0.34.3
func (t *ThinkValue) IsString() bool
IsString returns true if the value is a string
func (*ThinkValue) IsValid ¶ added in v0.34.3
func (t *ThinkValue) IsValid() bool
IsValid checks the transport type. The model resolves supported effort names.
func (*ThinkValue) MarshalJSON ¶ added in v0.34.3
func (t *ThinkValue) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler
func (*ThinkValue) String ¶ added in v0.34.3
func (t *ThinkValue) String() string
String returns the value as a string
func (*ThinkValue) UnmarshalJSON ¶ added in v0.34.3
func (t *ThinkValue) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler
type Thinking ¶ added in v0.34.3
Thinking describes explicit thinking controls and the default used on omission. Values are booleans or named strings. A nil descriptor means unknown.