Documentation ¶
Overview ¶
Package model contains types and utilities for parsing, validating, and working with model names and digests.
Index ¶
Constants ¶
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 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 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, and tag 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")
func Merge ¶ added in v0.1.33
Merge merges the host, namespace, and tag 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) 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.