Documentation
¶
Index ¶
- type CacheFileProvider
- func (p *CacheFileProvider[T]) Clear() error
- func (p *CacheFileProvider[T]) IsValid() bool
- func (p *CacheFileProvider[T]) Load(ctx context.Context) error
- func (p *CacheFileProvider[T]) Refresh(ctx context.Context) error
- func (p *CacheFileProvider[T]) Update(ctx context.Context) error
- func (p *CacheFileProvider[T]) Val() *T
- type CacheProvider
- type Getter
- type LitellmCacheProvider
- type LitellmModelInfo
- func (mc LitellmModelInfo) Get(name string) (interface{}, bool)
- func (v *LitellmModelInfo) GetCacheCreationInputTokenCost() *float64
- func (v *LitellmModelInfo) GetCacheReadInputTokenCost() *float64
- func (v *LitellmModelInfo) GetInputCostPerToken() float64
- func (v *LitellmModelInfo) GetLiteLLMProvider() string
- func (v *LitellmModelInfo) GetMaxInputTokens() int
- func (v *LitellmModelInfo) GetMaxOutputTokens() int
- func (v *LitellmModelInfo) GetMaxTokens() int
- func (v *LitellmModelInfo) GetOutputCostPerToken() float64
- func (v *LitellmModelInfo) GetToolUseSystemPromptTokens() *int
- type LitellmModelInfoFull
- type LitellmModelInfoMap
- type Model
- type Provider
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