provider

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatToolCall

func FormatToolCall(toolCall *ToolUseBlockParam) string

func FormatToolResult

func FormatToolResult(toolResult *ToolResultBlockParam) string

func MergeConfig

func MergeConfig(config interface{}, yamlConfig map[string]interface{})

MergeConfig merges a yaml config into a struct

Types

type AliasesModelProvider

type AliasesModelProvider interface {
	ModelAlias(model string, models []string) (string, error)
}

type Base64ImageSourceParam

type Base64ImageSourceParam struct {
	Data      string `json:"data" format:"byte"`
	MediaType string `json:"media_type"`
	Type      string `json:"type"`
}

Image Source Types

type Base64PDFSourceParam

type Base64PDFSourceParam struct {
	Data      string `json:"data" format:"byte"`
	MediaType string `json:"media_type"`
	Type      string `json:"type"`
}

Document Source Types

type CachedModels

type CachedModels struct {
	Models    []Info    `json:"models"`
	Provider  string    `json:"provider"`
	CachedAt  time.Time `json:"cached_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

CachedModels represents cached model data

type ContentBlockParamUnion

type ContentBlockParamUnion struct {
	OfText       *TextBlockParam       `json:",omitzero,inline"`
	OfImage      *ImageBlockParam      `json:",omitzero,inline"`
	OfToolUse    *ToolUseBlockParam    `json:",omitzero,inline"`
	OfToolResult *ToolResultBlockParam `json:",omitzero,inline"`
	OfThinking   *ThinkingBlockParam   `json:",omitzero,inline"`
}

Main Union Type

func NewTextBlock

func NewTextBlock(text string) ContentBlockParamUnion

func NewThinkingBlock

func NewThinkingBlock(signature string, thinking string) ContentBlockParamUnion

func NewToolResultBlock

func NewToolResultBlock(toolUseID string, content string, isError *bool) ContentBlockParamUnion

func NewToolUseBlock

func NewToolUseBlock(id string, input json.RawMessage, name string) ContentBlockParamUnion

func (*ContentBlockParamUnion) Type

type ContentBlockSourceContentUnionParam

type ContentBlockSourceContentUnionParam struct {
	OfString                    *string                               `json:",omitzero,inline"`
	OfContentBlockSourceContent []ContentBlockSourceContentUnionParam `json:",omitzero,inline"`
}

type ContentBlockSourceParam

type ContentBlockSourceParam struct {
	Content ContentBlockSourceContentUnionParam `json:"content,omitzero"`
	Type    string                              `json:"type"`
}

type ContentBlockType

type ContentBlockType string
const (
	ContentBlockTypeText       ContentBlockType = "text"
	ContentBlockTypeImage      ContentBlockType = "image"
	ContentBlockTypeToolUse    ContentBlockType = "tool_use"
	ContentBlockTypeToolResult ContentBlockType = "tool_result"
	ContentBlockTypeThinking   ContentBlockType = "thinking"
)

type GenerateContext

type GenerateContext struct {
	StepID  string
	RunID   string
	Context context.Context
}

type ImageBlockParam

type ImageBlockParam struct {
	Source ImageBlockParamSourceUnion `json:"source,omitzero"`
	Type   string                     `json:"type"` // image
}

type ImageBlockParamSourceUnion

type ImageBlockParamSourceUnion struct {
	OfBase64 *Base64ImageSourceParam `json:",omitzero,inline"`
	OfURL    *URLImageSourceParam    `json:",omitzero,inline"`
}

type Info

type Info struct {
	ID          string   `json:"id"`
	Name        string   `json:"name,omitempty"`
	Provider    string   `json:"provider"`
	CreatedAt   string   `json:"created_at,omitempty"`
	Deprecated  bool     `json:"deprecated,omitempty"`
	Description string   `json:"description,omitempty"`
	Features    []string `json:"features,omitempty"`
}

ModelInfo represents information about an available model

type LocalModelProvider

type LocalModelProvider interface {
	// contains filtered or unexported methods
}

type Message

type Message struct {
	Role        string                   `json:"role"`
	IsTruncated bool                     `json:"-"`
	Content     []ContentBlockParamUnion `json:"content"`
}

type MockProvider

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

MockModelProvider is a mock implementation for testing

func NewMockProvider

func NewMockProvider(name string, models []Info) *MockProvider

NewMockModelProvider creates a new mock model provider

func (*MockProvider) Close

func (mp *MockProvider) Close() error

Close cleans up resources

func (*MockProvider) Generate

func (mp *MockProvider) Generate(gtx GenerateContext, request *Request, progressChan chan<- pkgEvents.ExecutionEvent) ([]Message, *execcontext.TokenUsage, error)

Generate generates a mock response

func (*MockProvider) GetName

func (mp *MockProvider) GetName() string

GetName returns the provider name

func (*MockProvider) IsModelSupported

func (mp *MockProvider) IsModelSupported(model string) bool

IsModelSupported checks if a model is supported

func (*MockProvider) ListModels

func (mp *MockProvider) ListModels(ctx context.Context) ([]Info, error)

ListModels returns the supported models

func (*MockProvider) SetResponse

func (mp *MockProvider) SetResponse(prompt, response string)

SetResponse sets a mock response for a specific prompt

type ModelCache

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

ModelCache handles caching of model lists from providers

func NewModelCache

func NewModelCache(disable bool) *ModelCache

NewModelCache creates a new model cache

func (*ModelCache) GetModels

func (mc *ModelCache) GetModels(ctx context.Context, provider Provider) ([]Info, error)

GetModels retrieves cached models or fetches them from the provider

func (*ModelCache) InvalidateCache

func (mc *ModelCache) InvalidateCache(providerName string)

InvalidateCache removes cached data for a provider

type PlainTextSourceParam

type PlainTextSourceParam struct {
	Data      string `json:"data"`
	MediaType string `json:"media_type"`
	Type      string `json:"type"`
}

type Provider

type Provider interface {
	// Generate generates a response from the model
	Generate(ctx GenerateContext, request *Request, progressChan chan<- pkgEvents.ExecutionEvent) ([]Message, *execcontext.TokenUsage, error)

	// GetName returns the provider name
	GetName() string

	// ListModels dynamically queries available models from the provider API
	ListModels(ctx context.Context) ([]Info, error)

	// Close cleans up resources
	Close() error
}

Provider defines the interface for AI model providers

type Registry

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

ModelRegistry manages available model providers

func NewRegistry

func NewRegistry(disableCache bool) *Registry

NewRegistry creates a new model registry

func (*Registry) GetProviderByName

func (mr *Registry) GetProviderByName(name string) (Provider, error)

GetProviderByName returns a provider by name

func (*Registry) GetProviderForModel

func (mr *Registry) GetProviderForModel(providerName, model string) (Provider, error)

GetProviderForModel returns the provider for a specific model from a specific provider

func (*Registry) IsModelSupported

func (mr *Registry) IsModelSupported(providerName, model string) bool

IsModelSupported checks if a model is supported

func (*Registry) ModelAlias

func (mr *Registry) ModelAlias(providerName, model string) (string, error)

func (*Registry) RegisterProvider

func (mr *Registry) RegisterProvider(provider Provider) error

RegisterProvider registers a model provider

type Request

type Request struct {
	Model        string       `json:"model"`
	Messages     []Message    `json:"messages"`
	SystemPrompt string       `json:"system_prompt,omitempty"`
	Temperature  *float64     `json:"temperature,omitempty"`
	MaxTokens    *int         `json:"max_tokens,omitempty"`
	TopP         *float64     `json:"top_p,omitempty"`
	Stop         []string     `json:"stop,omitempty"`
	Tools        []tools.Tool `json:"tools,omitempty"`

	// Additional metadata
	RequestID string                 `json:"request_id,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

Request represents a request to generate text from a model

func (*Request) GetPrompt

func (mr *Request) GetPrompt() string

GetPrompt returns the first text prompt for the model request, this is used for simple agents that don't have complex messages. e.g. claude-code

type TextBlockParam

type TextBlockParam struct {
	Text string `json:"text"`
	Type string `json:"type"` // text
}

type ThinkingBlockParam

type ThinkingBlockParam struct {
	Signature string `json:"signature"`
	Thinking  string `json:"thinking"`
	Type      string `json:"type"` // thinking
}

type ToolResultBlockParam

type ToolResultBlockParam struct {
	ToolUseID string `json:"tool_use_id"`
	IsError   *bool  `json:"is_error,omitzero"`
	Content   string `json:"content,omitzero"`
	Type      string `json:"type"` // tool_result
}

type ToolUseBlockParam

type ToolUseBlockParam struct {
	ID    string          `json:"id"`
	Input json.RawMessage `json:"input,omitzero"`
	Name  string          `json:"name"`
	Type  string          `json:"type"` // tool_use
}

type URLImageSourceParam

type URLImageSourceParam struct {
	URL  string `json:"url"`
	Type string `json:"type"`
}

type URLPDFSourceParam

type URLPDFSourceParam struct {
	URL  string `json:"url"`
	Type string `json:"type"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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