modelinfo

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheFileProvider

type CacheFileProvider[T any] struct {
	// contains filtered or unexported fields
}

CacheFileProvider implements the CacheProvider interface using a file as the cache.

func NewCacheFileProvider

func NewCacheFileProvider[T any](
	ctx context.Context,
	url, cacheFile string,
	cacheTTL time.Duration,
) (*CacheFileProvider[T], error)

NewCacheFileProvider creates a new CacheFileProvider instance.

func (*CacheFileProvider[T]) Clear

func (p *CacheFileProvider[T]) Clear() error

Clear invalidates the cache by resetting the content and removing the cache file.

func (*CacheFileProvider[T]) IsValid

func (p *CacheFileProvider[T]) IsValid() bool

IsValid checks whether the cache is still valid based on the TTL.

func (*CacheFileProvider[T]) Load

func (p *CacheFileProvider[T]) Load(ctx context.Context) error

Load attempts to load the cache from the file. If the cache is invalid or absent, it does not automatically update.

func (*CacheFileProvider[T]) Refresh

func (p *CacheFileProvider[T]) Refresh(ctx context.Context) error

Refresh updates the cache by fetching fresh data.

func (*CacheFileProvider[T]) Update

func (p *CacheFileProvider[T]) Update(ctx context.Context) error

Update fetches fresh data from the URL and updates the cache.

func (*CacheFileProvider[T]) Val

func (p *CacheFileProvider[T]) Val() *T

Get retrieves the cached content.

type CacheProvider

type CacheProvider[T any] interface {
	Val() *T
	Load(ctx context.Context) error
	Update(ctx context.Context) error
	Clear() error
	IsValid() bool
	Refresh(ctx context.Context) error
}

CacheProvider defines the interface for cache operations. Expose a Val() that allow to recover the unmarshal json data

type Getter

type Getter interface {
	Get(field string) (interface{}, bool)
	GetMaxTokens() int
	GetMaxInputTokens() int
	GetMaxOutputTokens() int
	GetInputCostPerToken() float64
	GetOutputCostPerToken() float64
	GetLiteLLMProvider() string
	GetCacheCreationInputTokenCost() *float64
	GetCacheReadInputTokenCost() *float64
	GetToolUseSystemPromptTokens() *int
}

type LitellmCacheProvider

type LitellmCacheProvider struct {
	*CacheFileProvider[LitellmModelInfoMap]
}

It's used the CacheFileProvider to expose the data under Val()

func NewLitellm

func NewLitellm(
	ctx context.Context,
	cacheFile string,
) (*LitellmCacheProvider, error)

type LitellmModelInfo

type LitellmModelInfo LitellmModelInfoFull

Represents the metadata for a model provide by littlellm model info json

func (LitellmModelInfo) Get

func (mc LitellmModelInfo) Get(name string) (interface{}, bool)

Reflect the field name to the json name

func (*LitellmModelInfo) GetCacheCreationInputTokenCost

func (v *LitellmModelInfo) GetCacheCreationInputTokenCost() *float64

func (*LitellmModelInfo) GetCacheReadInputTokenCost

func (v *LitellmModelInfo) GetCacheReadInputTokenCost() *float64

func (*LitellmModelInfo) GetInputCostPerToken

func (v *LitellmModelInfo) GetInputCostPerToken() float64

func (*LitellmModelInfo) GetLiteLLMProvider

func (v *LitellmModelInfo) GetLiteLLMProvider() string

func (*LitellmModelInfo) GetMaxInputTokens

func (v *LitellmModelInfo) GetMaxInputTokens() int

func (*LitellmModelInfo) GetMaxOutputTokens

func (v *LitellmModelInfo) GetMaxOutputTokens() int

func (*LitellmModelInfo) GetMaxTokens

func (v *LitellmModelInfo) GetMaxTokens() int

func (*LitellmModelInfo) GetOutputCostPerToken

func (v *LitellmModelInfo) GetOutputCostPerToken() float64

func (*LitellmModelInfo) GetToolUseSystemPromptTokens

func (v *LitellmModelInfo) GetToolUseSystemPromptTokens() *int

type LitellmModelInfoFull

type LitellmModelInfoFull struct {
	MaxTokens          int     `json:"max_tokens"`
	MaxInputTokens     int     `json:"max_input_tokens"`
	MaxOutputTokens    int     `json:"max_output_tokens"`
	InputCostPerToken  float64 `json:"input_cost_per_token"`
	OutputCostPerToken float64 `json:"output_cost_per_token"`
	LiteLLMProvider    string  `json:"litellm_provider"`
	Mode               string  `json:"mode"`

	// Optional fields
	CacheCreationInputTokenCost *float64 `json:"cache_creation_input_token_cost,omitempty"`
	CacheReadInputTokenCost     *float64 `json:"cache_read_input_token_cost,omitempty"`
	ToolUseSystemPromptTokens   *int     `json:"tool_use_system_prompt_tokens,omitempty"`

	// Optional feature flags
	SupportsFunctionCalling         bool `json:"supports_function_calling,omitempty"`
	SupportsParallelFunctionCalling bool `json:"supports_parallel_function_calling,omitempty"`
	SupportsVision                  bool `json:"supports_vision,omitempty"`
	SupportsAudioInput              bool `json:"supports_audio_input,omitempty"`
	SupportsAudioOutput             bool `json:"supports_audio_output,omitempty"`
	SupportsPromptCaching           bool `json:"supports_prompt_caching,omitempty"`
	SupportsResponseSchema          bool `json:"supports_response_schema,omitempty"`
	SupportsSystemMessages          bool `json:"supports_system_messages,omitempty"`
	SupportsAssistantPrefill        bool `json:"supports_assistant_prefill,omitempty"`
}

LitellmModelInfoFull represents the complete Litellm model metadata.

type LitellmModelInfoMap

type LitellmModelInfoMap map[string]LitellmModelInfo

They provide map of model name to model metadata

func (*LitellmModelInfoMap) Get

func (p *LitellmModelInfoMap) Get(modelName string) (Getter, bool)

Return the metadata for a model by name

func (*LitellmModelInfoMap) UnmarshalJSON

func (p *LitellmModelInfoMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for LitellmMetadataMap Ignore the key sample_spec Ignore entry when the unmarshal fails

type Model

type Model struct {
	Provider string
	Name     string
	// contains filtered or unexported fields
}

func Get

func Get(modelStr string, infoProviders Provider) (*Model, error)

Get parses a model string in the format "provider/model"

func (*Model) Info

func (m *Model) Info() Getter

func (*Model) String

func (m *Model) String() string

String returns the string representation of the model

type Provider

type Provider interface {
	Get(modelName string) (Getter, bool)
}

A ModelInfoProvider implement the same method has CacheProvider[T] Expose the map of model name to model metadata in Val()

func New

func New(ctx context.Context, cacheFile string) (Provider, error)

Jump to

Keyboard shortcuts

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