modelsdev

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: AGPL-3.0 Imports: 19 Imported by: 0

README

modelsdev

Internal package modelsdev provides integration with the models.dev community repository.

modelsdev

import "github.com/agentstation/starmap/internal/sources/modelsdev"

Index

Constants

const (
    // ModelsDevRepoURL is the URL for the models.dev git repository.
    ModelsDevRepoURL = "https://github.com/sst/models.dev.git"
    // DefaultBranch is the default branch to use for models.dev.
    DefaultBranch = "dev"
)

const (
    // ModelsDevAPIURL is the URL for the models.dev API.
    ModelsDevAPIURL = "https://models.dev/api.json"
    // HTTPCacheTTL is the cache time-to-live for HTTP responses.
    HTTPCacheTTL = 1 * time.Hour
)

func ConvertToStarmapModel

func ConvertToStarmapModel(mdModel Model) *catalogs.Model

ConvertToStarmapModel converts a models.dev model to a starmap model. This is shared between GitSource and HTTPSource to avoid duplication.

func CopyAuthorLogos

func CopyAuthorLogos(outputDir string, authors []catalogs.Author, providers *catalogs.Providers) error

CopyAuthorLogos copies author logos from models.dev provider logos to author directories. Since models.dev doesn't have a separate authors directory, we copy from the provider directory when the author ID matches a provider ID (or alias).

func CopyProviderLogos

func CopyProviderLogos(outputDir string, providers []*catalogs.Provider) error

CopyProviderLogos copies provider logos from models.dev to output directory. It tries the provider ID first, then checks aliases if the primary ID isn't found.

type API

API represents the structure of models.dev api.json.

type API map[string]Provider

func ParseAPI
func ParseAPI(apiPath string) (*API, error)

ParseAPI parses the api.json file and returns an API.

func (*API) GetProvider
func (api *API) GetProvider(providerID catalogs.ProviderID) (*Provider, bool)

GetProvider returns a specific provider from the API data.

type Catalog

Catalog implements starmap.Catalog interface for models.dev data.

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

func NewCatalog
func NewCatalog(api *API) (*Catalog, error)

NewCatalog creates a new models.dev catalog from parsed API data.

func (*Catalog) Author
func (c *Catalog) Author(id catalogs.AuthorID) (*catalogs.Author, error)

Author implements starmap.Catalog.

func (*Catalog) Authors
func (c *Catalog) Authors() *catalogs.Authors

Authors implements starmap.Catalog.

func (*Catalog) DeleteAuthor
func (c *Catalog) DeleteAuthor(id catalogs.AuthorID) error

DeleteAuthor implements starmap.Catalog.

func (*Catalog) DeleteEndpoint
func (c *Catalog) DeleteEndpoint(id string) error

DeleteEndpoint implements starmap.Catalog.

func (*Catalog) DeleteProvider
func (c *Catalog) DeleteProvider(id catalogs.ProviderID) error

DeleteProvider implements starmap.Catalog.

func (*Catalog) Endpoint
func (c *Catalog) Endpoint(id string) (*catalogs.Endpoint, error)

Endpoint implements starmap.Catalog.

func (*Catalog) Endpoints
func (c *Catalog) Endpoints() *catalogs.Endpoints

Endpoints implements starmap.Catalog.

func (*Catalog) Provider
func (c *Catalog) Provider(id catalogs.ProviderID) (*catalogs.Provider, error)

Provider implements starmap.Catalog.

func (*Catalog) Providers
func (c *Catalog) Providers() *catalogs.Providers

Providers implements starmap.Catalog.

func (*Catalog) SetAuthor
func (c *Catalog) SetAuthor(author catalogs.Author) error

SetAuthor implements starmap.Catalog.

func (*Catalog) SetEndpoint
func (c *Catalog) SetEndpoint(endpoint catalogs.Endpoint) error

SetEndpoint implements starmap.Catalog.

func (*Catalog) SetProvider
func (c *Catalog) SetProvider(provider catalogs.Provider) error

SetProvider implements starmap.Catalog.

type Client

Client is an alias for backward compatibility.

type Client = GitClient

func NewClient
func NewClient(outputDir string) *Client

NewClient creates a new models.dev git client.

type Cost

Cost represents pricing information.

type Cost struct {
    Input      *float64 `json:"input,omitempty"`
    Output     *float64 `json:"output,omitempty"`
    Cache      *float64 `json:"cache,omitempty"`       // Legacy cache field
    CacheRead  *float64 `json:"cache_read,omitempty"`  // Cache read costs
    CacheWrite *float64 `json:"cache_write,omitempty"` // Cache write costs
}

type GitClient

GitClient handles models.dev repository operations.

type GitClient struct {
    RepoPath string
}

func NewGitClient
func NewGitClient(outputDir string) *GitClient

NewGitClient creates a new models.dev git client.

func (*GitClient) BuildAPI
func (c *GitClient) BuildAPI(ctx context.Context) error

BuildAPI runs the build process to generate api.json.

func (*GitClient) Cleanup
func (c *GitClient) Cleanup() error

Cleanup removes the models.dev repository.

func (*GitClient) EnsureRepository
func (c *GitClient) EnsureRepository(ctx context.Context) error

EnsureRepository ensures the models.dev repository is available and up to date.

func (*GitClient) GetAPIPath
func (c *GitClient) GetAPIPath() string

GetAPIPath returns the path to the generated api.json file.

func (*GitClient) GetProvidersPath
func (c *GitClient) GetProvidersPath() string

GetProvidersPath returns the path to the providers directory.

type GitSource

GitSource enhances models with models.dev data.

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

func NewGitSource
func NewGitSource(opts ...GitSourceOption) *GitSource

NewGitSource creates a new models.dev git source.

func (*GitSource) Catalog
func (s *GitSource) Catalog() catalogs.Catalog

Catalog returns the catalog of this source.

func (*GitSource) Cleanup
func (s *GitSource) Cleanup() error

Cleanup releases any resources.

func (*GitSource) Dependencies
func (s *GitSource) Dependencies() []sources.Dependency

Dependencies returns the list of external dependencies required by this source. Git source requires bun (for building) and git (for cloning).

func (*GitSource) Fetch
func (s *GitSource) Fetch(ctx context.Context, _ ...sources.Option) error

Fetch creates a catalog with models that have pricing/limits data from models.dev.

func (*GitSource) ID
func (s *GitSource) ID() sources.ID

ID returns the ID of this source.

func (*GitSource) IsOptional
func (s *GitSource) IsOptional() bool

IsOptional returns whether this source is optional. Git source is optional - HTTP source provides the same data without dependencies.

func (*GitSource) Name
func (s *GitSource) Name() string

Name returns the human-friendly name of this source.

func (*GitSource) Setup
func (s *GitSource) Setup(providers *catalogs.Providers) error

Setup initializes the source with dependencies.

type GitSourceOption

GitSourceOption configures a GitSource.

type GitSourceOption func(*GitSource)

func WithGitSourcesDir
func WithGitSourcesDir(dir string) GitSourceOption

WithGitSourcesDir is an alias for WithSourcesDir for backward compatibility.

func WithSourcesDir
func WithSourcesDir(dir string) GitSourceOption

WithSourcesDir configures the sources directory for the git source.

type HTTPClient

HTTPClient handles HTTP downloading of models.dev api.json.

type HTTPClient struct {
    CacheDir string
    APIURL   string
    Client   *http.Client
}

func NewHTTPClient
func NewHTTPClient(outputDir string) *HTTPClient

NewHTTPClient creates a new models.dev HTTP client.

func (*HTTPClient) Cleanup
func (c *HTTPClient) Cleanup() error

Cleanup removes the cache directory.

func (*HTTPClient) EnsureAPI
func (c *HTTPClient) EnsureAPI(ctx context.Context) error

EnsureAPI ensures the api.json is available and up to date.

func (*HTTPClient) GetAPIPath
func (c *HTTPClient) GetAPIPath() string

GetAPIPath returns the path to the cached api.json file.

type HTTPSource

HTTPSource enhances models with models.dev data via HTTP.

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

func NewHTTPSource
func NewHTTPSource(opts ...HTTPSourceOption) *HTTPSource

NewHTTPSource creates a new models.dev HTTP source.

func (*HTTPSource) Catalog
func (s *HTTPSource) Catalog() catalogs.Catalog

Catalog returns the catalog of this source.

func (*HTTPSource) Cleanup
func (s *HTTPSource) Cleanup() error

Cleanup releases any resources.

func (*HTTPSource) Dependencies
func (s *HTTPSource) Dependencies() []sources.Dependency

Dependencies returns the list of external dependencies. HTTP source has no external dependencies.

func (*HTTPSource) Fetch
func (s *HTTPSource) Fetch(ctx context.Context, _ ...sources.Option) error

Fetch creates a catalog with models that have pricing/limits data from models.dev.

func (*HTTPSource) ID
func (s *HTTPSource) ID() sources.ID

ID returns the ID of this source.

func (*HTTPSource) IsOptional
func (s *HTTPSource) IsOptional() bool

IsOptional returns whether this source is optional. HTTP source is optional - git source provides same data, and we can work without models.dev.

func (*HTTPSource) Name
func (s *HTTPSource) Name() string

Name returns the human-friendly name of this source.

func (*HTTPSource) Setup
func (s *HTTPSource) Setup(providers *catalogs.Providers) error

Setup initializes the source with dependencies.

type HTTPSourceOption

HTTPSourceOption configures an HTTPSource.

type HTTPSourceOption func(*HTTPSource)

func WithHTTPSourcesDir
func WithHTTPSourcesDir(dir string) HTTPSourceOption

WithHTTPSourcesDir configures the sources directory for the HTTP source.

type Limit

Limit represents model limits.

type Limit struct {
    Context int `json:"context"`
    Output  int `json:"output"`
}

type Modalities

Modalities represents input/output modalities.

type Modalities struct {
    Input  []string `json:"input"`
    Output []string `json:"output"`
}

type Model

Model represents a model in models.dev.

type Model struct {
    ID          string     `json:"id"`
    Name        string     `json:"name"`
    Attachment  bool       `json:"attachment"`
    Reasoning   bool       `json:"reasoning"`
    Temperature bool       `json:"temperature"`
    ToolCall    bool       `json:"tool_call"`
    Knowledge   *string    `json:"knowledge,omitempty"`
    ReleaseDate string     `json:"release_date"`
    LastUpdated string     `json:"last_updated"`
    Modalities  Modalities `json:"modalities"`
    OpenWeights bool       `json:"open_weights"`
    Cost        *Cost      `json:"cost,omitempty"`
    Limit       Limit      `json:"limit"`
}

func (*Model) ToStarmapModel
func (m *Model) ToStarmapModel() (*catalogs.Model, error)

ToStarmapModel converts a Model to a starmap.Model.

type Provider

Provider represents a provider in models.dev.

type Provider struct {
    ID     string           `json:"id"`
    Env    []string         `json:"env"`
    NPM    string           `json:"npm"`
    API    *string          `json:"api,omitempty"`
    Name   string           `json:"name"`
    Doc    string           `json:"doc"`
    Models map[string]Model `json:"models"`
}

func (*Provider) Model
func (p *Provider) Model(modelID string) (*Model, bool)

Model returns a specific model from a provider.

func (*Provider) ToStarmapProvider
func (p *Provider) ToStarmapProvider() (*catalogs.Provider, error)

ToStarmapProvider converts a Provider to a starmap.Provider.

Generated by gomarkdoc

Documentation

Index

Constants

View Source
const (
	// ModelsDevRepoURL is the URL for the models.dev git repository.
	ModelsDevRepoURL = "https://github.com/sst/models.dev.git"
	// DefaultBranch is the default branch to use for models.dev.
	DefaultBranch = "dev"
)
View Source
const (
	// ModelsDevAPIURL is the URL for the models.dev API.
	ModelsDevAPIURL = "https://models.dev/api.json"
	// HTTPCacheTTL is the cache time-to-live for HTTP responses.
	HTTPCacheTTL = 1 * time.Hour
)

Variables

This section is empty.

Functions

func ConvertToStarmapModel

func ConvertToStarmapModel(mdModel Model) *catalogs.Model

ConvertToStarmapModel converts a models.dev model to a starmap model. This is shared between GitSource and HTTPSource to avoid duplication.

func CopyAuthorLogos added in v0.0.20

func CopyAuthorLogos(outputDir string, authors []catalogs.Author, providers *catalogs.Providers) error

CopyAuthorLogos copies author logos from models.dev provider logos to author directories. Since models.dev doesn't have a separate authors directory, we copy from the provider directory when the author ID matches a provider ID (or alias).

func CopyProviderLogos

func CopyProviderLogos(outputDir string, providers []*catalogs.Provider) error

CopyProviderLogos copies provider logos from models.dev to output directory. It tries the provider ID first, then checks aliases if the primary ID isn't found.

Types

type API

type API map[string]Provider

API represents the structure of models.dev api.json.

func ParseAPI

func ParseAPI(apiPath string) (*API, error)

ParseAPI parses the api.json file and returns an API.

func (*API) GetProvider

func (api *API) GetProvider(providerID catalogs.ProviderID) (*Provider, bool)

GetProvider returns a specific provider from the API data.

type Catalog

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

Catalog implements starmap.Catalog interface for models.dev data.

func NewCatalog

func NewCatalog(api *API) (*Catalog, error)

NewCatalog creates a new models.dev catalog from parsed API data.

func (*Catalog) Author

func (c *Catalog) Author(id catalogs.AuthorID) (*catalogs.Author, error)

Author implements starmap.Catalog.

func (*Catalog) Authors

func (c *Catalog) Authors() *catalogs.Authors

Authors implements starmap.Catalog.

func (*Catalog) DeleteAuthor

func (c *Catalog) DeleteAuthor(id catalogs.AuthorID) error

DeleteAuthor implements starmap.Catalog.

func (*Catalog) DeleteEndpoint

func (c *Catalog) DeleteEndpoint(id string) error

DeleteEndpoint implements starmap.Catalog.

func (*Catalog) DeleteProvider

func (c *Catalog) DeleteProvider(id catalogs.ProviderID) error

DeleteProvider implements starmap.Catalog.

func (*Catalog) Endpoint

func (c *Catalog) Endpoint(id string) (*catalogs.Endpoint, error)

Endpoint implements starmap.Catalog.

func (*Catalog) Endpoints

func (c *Catalog) Endpoints() *catalogs.Endpoints

Endpoints implements starmap.Catalog.

func (*Catalog) Provider

func (c *Catalog) Provider(id catalogs.ProviderID) (*catalogs.Provider, error)

Provider implements starmap.Catalog.

func (*Catalog) Providers

func (c *Catalog) Providers() *catalogs.Providers

Providers implements starmap.Catalog.

func (*Catalog) SetAuthor

func (c *Catalog) SetAuthor(author catalogs.Author) error

SetAuthor implements starmap.Catalog.

func (*Catalog) SetEndpoint

func (c *Catalog) SetEndpoint(endpoint catalogs.Endpoint) error

SetEndpoint implements starmap.Catalog.

func (*Catalog) SetProvider

func (c *Catalog) SetProvider(provider catalogs.Provider) error

SetProvider implements starmap.Catalog.

type Client

type Client = GitClient

Client is an alias for backward compatibility.

func NewClient

func NewClient(outputDir string) *Client

NewClient creates a new models.dev git client.

type Cost

type Cost struct {
	Input      *float64 `json:"input,omitempty"`
	Output     *float64 `json:"output,omitempty"`
	Cache      *float64 `json:"cache,omitempty"`       // Legacy cache field
	CacheRead  *float64 `json:"cache_read,omitempty"`  // Cache read costs
	CacheWrite *float64 `json:"cache_write,omitempty"` // Cache write costs
}

Cost represents pricing information.

type GitClient

type GitClient struct {
	RepoPath string
}

GitClient handles models.dev repository operations.

func NewGitClient

func NewGitClient(outputDir string) *GitClient

NewGitClient creates a new models.dev git client.

func (*GitClient) BuildAPI

func (c *GitClient) BuildAPI(ctx context.Context) error

BuildAPI runs the build process to generate api.json.

func (*GitClient) Cleanup

func (c *GitClient) Cleanup() error

Cleanup removes the models.dev repository.

func (*GitClient) EnsureRepository

func (c *GitClient) EnsureRepository(ctx context.Context) error

EnsureRepository ensures the models.dev repository is available and up to date.

func (*GitClient) GetAPIPath

func (c *GitClient) GetAPIPath() string

GetAPIPath returns the path to the generated api.json file.

func (*GitClient) GetProvidersPath

func (c *GitClient) GetProvidersPath() string

GetProvidersPath returns the path to the providers directory.

type GitSource

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

GitSource enhances models with models.dev data.

func NewGitSource

func NewGitSource(opts ...GitSourceOption) *GitSource

NewGitSource creates a new models.dev git source.

func (*GitSource) Catalog

func (s *GitSource) Catalog() catalogs.Catalog

Catalog returns the catalog of this source.

func (*GitSource) Cleanup

func (s *GitSource) Cleanup() error

Cleanup releases any resources.

func (*GitSource) Dependencies added in v0.0.17

func (s *GitSource) Dependencies() []sources.Dependency

Dependencies returns the list of external dependencies required by this source. Git source requires bun (for building) and git (for cloning).

func (*GitSource) Fetch

func (s *GitSource) Fetch(ctx context.Context, _ ...sources.Option) error

Fetch creates a catalog with models that have pricing/limits data from models.dev.

func (*GitSource) ID added in v0.0.15

func (s *GitSource) ID() sources.ID

ID returns the ID of this source.

func (*GitSource) IsOptional added in v0.0.17

func (s *GitSource) IsOptional() bool

IsOptional returns whether this source is optional. Git source is optional - HTTP source provides the same data without dependencies.

func (*GitSource) Name added in v0.0.17

func (s *GitSource) Name() string

Name returns the human-friendly name of this source.

func (*GitSource) Setup

func (s *GitSource) Setup(providers *catalogs.Providers) error

Setup initializes the source with dependencies.

type GitSourceOption added in v0.0.10

type GitSourceOption func(*GitSource)

GitSourceOption configures a GitSource.

func WithGitSourcesDir added in v0.0.10

func WithGitSourcesDir(dir string) GitSourceOption

WithGitSourcesDir is an alias for WithSourcesDir for backward compatibility.

func WithSourcesDir added in v0.0.10

func WithSourcesDir(dir string) GitSourceOption

WithSourcesDir configures the sources directory for the git source.

type HTTPClient

type HTTPClient struct {
	CacheDir string
	APIURL   string
	Client   *http.Client
}

HTTPClient handles HTTP downloading of models.dev api.json.

func NewHTTPClient

func NewHTTPClient(outputDir string) *HTTPClient

NewHTTPClient creates a new models.dev HTTP client.

func (*HTTPClient) Cleanup

func (c *HTTPClient) Cleanup() error

Cleanup removes the cache directory.

func (*HTTPClient) EnsureAPI

func (c *HTTPClient) EnsureAPI(ctx context.Context) error

EnsureAPI ensures the api.json is available and up to date.

func (*HTTPClient) GetAPIPath

func (c *HTTPClient) GetAPIPath() string

GetAPIPath returns the path to the cached api.json file.

type HTTPSource

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

HTTPSource enhances models with models.dev data via HTTP.

func NewHTTPSource

func NewHTTPSource(opts ...HTTPSourceOption) *HTTPSource

NewHTTPSource creates a new models.dev HTTP source.

func (*HTTPSource) Catalog

func (s *HTTPSource) Catalog() catalogs.Catalog

Catalog returns the catalog of this source.

func (*HTTPSource) Cleanup

func (s *HTTPSource) Cleanup() error

Cleanup releases any resources.

func (*HTTPSource) Dependencies added in v0.0.17

func (s *HTTPSource) Dependencies() []sources.Dependency

Dependencies returns the list of external dependencies. HTTP source has no external dependencies.

func (*HTTPSource) Fetch

func (s *HTTPSource) Fetch(ctx context.Context, _ ...sources.Option) error

Fetch creates a catalog with models that have pricing/limits data from models.dev.

func (*HTTPSource) ID added in v0.0.15

func (s *HTTPSource) ID() sources.ID

ID returns the ID of this source.

func (*HTTPSource) IsOptional added in v0.0.17

func (s *HTTPSource) IsOptional() bool

IsOptional returns whether this source is optional. HTTP source is optional - git source provides same data, and we can work without models.dev.

func (*HTTPSource) Name added in v0.0.17

func (s *HTTPSource) Name() string

Name returns the human-friendly name of this source.

func (*HTTPSource) Setup

func (s *HTTPSource) Setup(providers *catalogs.Providers) error

Setup initializes the source with dependencies.

type HTTPSourceOption added in v0.0.10

type HTTPSourceOption func(*HTTPSource)

HTTPSourceOption configures an HTTPSource.

func WithHTTPSourcesDir added in v0.0.10

func WithHTTPSourcesDir(dir string) HTTPSourceOption

WithHTTPSourcesDir configures the sources directory for the HTTP source.

type Limit

type Limit struct {
	Context int `json:"context"`
	Output  int `json:"output"`
}

Limit represents model limits.

type Modalities

type Modalities struct {
	Input  []string `json:"input"`
	Output []string `json:"output"`
}

Modalities represents input/output modalities.

type Model

type Model struct {
	ID          string     `json:"id"`
	Name        string     `json:"name"`
	Attachment  bool       `json:"attachment"`
	Reasoning   bool       `json:"reasoning"`
	Temperature bool       `json:"temperature"`
	ToolCall    bool       `json:"tool_call"`
	Knowledge   *string    `json:"knowledge,omitempty"`
	ReleaseDate string     `json:"release_date"`
	LastUpdated string     `json:"last_updated"`
	Modalities  Modalities `json:"modalities"`
	OpenWeights bool       `json:"open_weights"`
	Cost        *Cost      `json:"cost,omitempty"`
	Limit       Limit      `json:"limit"`
}

Model represents a model in models.dev.

func (*Model) ToStarmapModel

func (m *Model) ToStarmapModel() (*catalogs.Model, error)

ToStarmapModel converts a Model to a starmap.Model.

type Provider

type Provider struct {
	ID     string           `json:"id"`
	Env    []string         `json:"env"`
	NPM    string           `json:"npm"`
	API    *string          `json:"api,omitempty"`
	Name   string           `json:"name"`
	Doc    string           `json:"doc"`
	Models map[string]Model `json:"models"`
}

Provider represents a provider in models.dev.

func (*Provider) Model

func (p *Provider) Model(modelID string) (*Model, bool)

Model returns a specific model from a provider.

func (*Provider) ToStarmapProvider

func (p *Provider) ToStarmapProvider() (*catalogs.Provider, error)

ToStarmapProvider converts a Provider to a starmap.Provider.

Jump to

Keyboard shortcuts

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