modelsdev

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: AGPL-3.0 Imports: 18 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 CopyProviderLogos

func CopyProviderLogos(outputDir string, providerIDs []catalogs.ProviderID) error

CopyProviderLogos copies provider logos from models.dev to output directory.

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() *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) Fetch
func (s *GitSource) Fetch(ctx context.Context, opts ...sources.Option) error

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

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

Setup initializes the source with dependencies.

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

Type returns the type of this 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() *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) Fetch
func (s *HTTPSource) Fetch(ctx context.Context, opts ...sources.Option) error

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

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

Setup initializes the source with dependencies.

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

Type returns the type of this 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 CopyProviderLogos

func CopyProviderLogos(outputDir string, providerIDs []catalogs.ProviderID) error

CopyProviderLogos copies provider logos from models.dev to output directory.

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() *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) Fetch

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

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

func (*GitSource) Setup

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

Setup initializes the source with dependencies.

func (*GitSource) Type

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

Type returns the type of this 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() *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) Fetch

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

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

func (*HTTPSource) Setup

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

Setup initializes the source with dependencies.

func (*HTTPSource) Type

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

Type returns the type of this 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