modelprovider

package module
v0.0.12 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: 16 Imported by: 1

README

modelprovider

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("operation not supported")

ErrNotSupported is returned when an operation is not supported.

Functions

func SetupOllamaLocalInstance added in v0.0.8

func SetupOllamaLocalInstance(ctx context.Context, tag string) (string, testcontainers.Container, func(), error)

func SetupVLLMLocalInstance added in v0.0.12

func SetupVLLMLocalInstance(ctx context.Context, model string, tag string) (string, testcontainers.Container, func(), error)

SetupVLLMLocalInstance creates a vLLM container for testing.

Types

type CapabilityConfig added in v0.0.4

type CapabilityConfig struct {
	ContextLength int
	CanChat       bool
	CanEmbed      bool
	CanStream     bool
	CanPrompt     bool
	CanThink      bool
}

CapabilityConfig holds the required capability information

type ChatOption

type ChatOption interface {
	SetTemperature(float64)
	SetMaxTokens(int)
}

func WithMaxTokens added in v0.0.8

func WithMaxTokens(tokens int) ChatOption

func WithTemperature added in v0.0.8

func WithTemperature(temp float64) ChatOption

Functional option constructors

type GeminiProvider

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

func NewGeminiProvider

func NewGeminiProvider(apiKey string, modelName string, baseURLs []string, cap CapabilityConfig, httpClient *http.Client) *GeminiProvider

func (*GeminiProvider) CanChat

func (p *GeminiProvider) CanChat() bool

func (*GeminiProvider) CanEmbed

func (p *GeminiProvider) CanEmbed() bool

func (*GeminiProvider) CanPrompt

func (p *GeminiProvider) CanPrompt() bool

CanPrompt returns true if the model supports prompting.

func (*GeminiProvider) CanStream

func (p *GeminiProvider) CanStream() bool

func (*GeminiProvider) CanThink added in v0.0.8

func (p *GeminiProvider) CanThink() bool

func (*GeminiProvider) GetBackendIDs

func (p *GeminiProvider) GetBackendIDs() []string

func (*GeminiProvider) GetChatConnection

func (p *GeminiProvider) GetChatConnection(ctx context.Context, backendID string) (LLMChatClient, error)

GetChatConnection returns an LLMChatClient for the specified backend ID.

func (*GeminiProvider) GetContextLength

func (p *GeminiProvider) GetContextLength() int

func (*GeminiProvider) GetEmbedConnection

func (p *GeminiProvider) GetEmbedConnection(ctx context.Context, backendID string) (LLMEmbedClient, error)

GetEmbedConnection returns an LLMEmbedClient for the specified backend ID.

func (*GeminiProvider) GetID

func (p *GeminiProvider) GetID() string

func (*GeminiProvider) GetPromptConnection

func (p *GeminiProvider) GetPromptConnection(ctx context.Context, backendID string) (LLMPromptExecClient, error)

GetPromptConnection returns an LLMPromptExecClient for the specified backend ID.

func (*GeminiProvider) GetStreamConnection

func (p *GeminiProvider) GetStreamConnection(ctx context.Context, backendID string) (LLMStreamClient, error)

GetStreamConnection returns an LLMStreamClient for the specified backend ID.

func (*GeminiProvider) GetType

func (p *GeminiProvider) GetType() string

func (*GeminiProvider) ModelName

func (p *GeminiProvider) ModelName() string

type LLMChatClient

type LLMChatClient interface {
	Chat(ctx context.Context, Messages []Message, opts ...ChatOption) (Message, error)
}

Client interfaces for different capabilities

func NewVLLMChatClient

func NewVLLMChatClient(ctx context.Context, baseURL, modelName string, contextLength int, httpClient *http.Client, apiKey string) (LLMChatClient, error)

type LLMEmbedClient

type LLMEmbedClient interface {
	Embed(ctx context.Context, prompt string) ([]float64, error)
}

type LLMPromptExecClient

type LLMPromptExecClient interface {
	Prompt(ctx context.Context, systeminstruction string, temperature float32, prompt string) (string, error)
}

func NewVLLMPromptClient

func NewVLLMPromptClient(ctx context.Context, baseURL, modelName string, contextLength int, httpClient *http.Client, apiKey string) (LLMPromptExecClient, error)

NewVLLMPromptClient creates a new prompt client

type LLMStreamClient

type LLMStreamClient interface {
	Stream(ctx context.Context, prompt string) (<-chan *StreamParcel, error)
}

func NewVLLMStreamClient added in v0.0.11

func NewVLLMStreamClient(ctx context.Context, baseURL, modelName string, contextLength int, httpClient *http.Client, apiKey string) (LLMStreamClient, error)

NewVLLMStreamClient creates a new streaming client

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type MockChatClient

type MockChatClient struct{}

MockChatClient is a mock implementation of LLMChatClient for testing.

func (*MockChatClient) Chat

func (m *MockChatClient) Chat(ctx context.Context, messages []Message, opts ...ChatOption) (Message, error)

Chat returns a mock response.

func (*MockChatClient) Close added in v0.0.10

func (m *MockChatClient) Close() error

Close is a no-op for the mock client.

type MockEmbedClient

type MockEmbedClient struct{}

MockEmbedClient is a mock implementation of LLMEmbedClient for testing.

func (*MockEmbedClient) Close added in v0.0.10

func (m *MockEmbedClient) Close() error

Close is a no-op for the mock client.

func (*MockEmbedClient) Embed

func (m *MockEmbedClient) Embed(ctx context.Context, prompt string) ([]float64, error)

Embed returns a mock embedding.

type MockPromptClient

type MockPromptClient struct{}

MockPromptClient is a mock implementation of LLMPromptExecClient for testing.

func (*MockPromptClient) Close added in v0.0.10

func (m *MockPromptClient) Close() error

Close is a no-op for the mock client.

func (*MockPromptClient) Prompt

func (m *MockPromptClient) Prompt(ctx context.Context, systemInstruction string, temperature float32, prompt string) (string, error)

Prompt returns a mock response.

type MockProvider

type MockProvider struct {
	ID            string
	Name          string
	ContextLength int
	CanChatFlag   bool
	CanEmbedFlag  bool
	CanStreamFlag bool
	CanPromptFlag bool
	Backends      []string
}

MockProvider is a mock implementation of the Provider interface for testing.

func (*MockProvider) CanChat

func (m *MockProvider) CanChat() bool

CanChat returns whether the mock provider can chat.

func (*MockProvider) CanEmbed

func (m *MockProvider) CanEmbed() bool

CanEmbed returns whether the mock provider can embed.

func (*MockProvider) CanPrompt

func (m *MockProvider) CanPrompt() bool

CanPrompt returns whether the mock provider can prompt.

func (*MockProvider) CanStream

func (m *MockProvider) CanStream() bool

CanStream returns whether the mock provider can stream.

func (*MockProvider) CanThink added in v0.0.9

func (m *MockProvider) CanThink() bool

CanThink returns whether the mock provider can think.

func (*MockProvider) GetBackendIDs

func (m *MockProvider) GetBackendIDs() []string

GetBackendIDs returns the backend IDs for the mock provider.

func (*MockProvider) GetChatConnection

func (m *MockProvider) GetChatConnection(ctx context.Context, backendID string) (LLMChatClient, error)

GetChatConnection returns a mock chat client.

func (*MockProvider) GetContextLength

func (m *MockProvider) GetContextLength() int

GetContextLength returns the context length for the mock provider.

func (*MockProvider) GetEmbedConnection

func (m *MockProvider) GetEmbedConnection(ctx context.Context, backendID string) (LLMEmbedClient, error)

GetEmbedConnection returns a mock embed client.

func (*MockProvider) GetID

func (m *MockProvider) GetID() string

GetID returns the ID for the mock provider.

func (*MockProvider) GetPromptConnection

func (m *MockProvider) GetPromptConnection(ctx context.Context, backendID string) (LLMPromptExecClient, error)

GetPromptConnection returns a mock prompt client.

func (*MockProvider) GetStreamConnection

func (m *MockProvider) GetStreamConnection(ctx context.Context, backendID string) (LLMStreamClient, error)

GetStreamConnection returns a mock stream client.

func (*MockProvider) GetType

func (m *MockProvider) GetType() string

GetType returns the provider type for the mock provider.

func (*MockProvider) ModelName

func (m *MockProvider) ModelName() string

ModelName returns the model name for the mock provider.

type MockStreamClient added in v0.0.10

type MockStreamClient struct{}

MockStreamClient is a mock implementation of LLMStreamClient for testing.

func (*MockStreamClient) Close added in v0.0.10

func (m *MockStreamClient) Close() error

Close is a no-op for the mock client.

func (*MockStreamClient) Stream added in v0.0.10

func (m *MockStreamClient) Stream(ctx context.Context, prompt string) (<-chan *StreamParcel, error)

Stream returns a channel with mock stream parcels.

type OllamaChatClient

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

func (*OllamaChatClient) Chat

func (c *OllamaChatClient) Chat(ctx context.Context, messages []Message, options ...ChatOption) (Message, error)

type OllamaEmbedClient

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

func (*OllamaEmbedClient) Embed

func (c *OllamaEmbedClient) Embed(ctx context.Context, text string) ([]float64, error)

type OllamaPromptClient

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

func (*OllamaPromptClient) Prompt

func (o *OllamaPromptClient) Prompt(ctx context.Context, systeminstruction string, temperature float32, prompt string) (string, error)

Prompt implements serverops.LLMPromptClient.

type OllamaProvider

type OllamaProvider struct {
	Name           string
	ID             string
	ContextLength  int
	SupportsChat   bool
	SupportsEmbed  bool
	SupportsStream bool
	SupportsPrompt bool
	SupportsThink  bool

	Backends []string
	// contains filtered or unexported fields
}

func (*OllamaProvider) CanChat

func (p *OllamaProvider) CanChat() bool

func (*OllamaProvider) CanEmbed

func (p *OllamaProvider) CanEmbed() bool

func (*OllamaProvider) CanPrompt

func (p *OllamaProvider) CanPrompt() bool

func (*OllamaProvider) CanStream

func (p *OllamaProvider) CanStream() bool

func (*OllamaProvider) CanThink added in v0.0.8

func (p *OllamaProvider) CanThink() bool

func (*OllamaProvider) GetBackendIDs

func (p *OllamaProvider) GetBackendIDs() []string

func (*OllamaProvider) GetChatConnection

func (p *OllamaProvider) GetChatConnection(ctx context.Context, backendID string) (LLMChatClient, error)

func (*OllamaProvider) GetContextLength

func (p *OllamaProvider) GetContextLength() int

func (*OllamaProvider) GetEmbedConnection

func (p *OllamaProvider) GetEmbedConnection(ctx context.Context, backendID string) (LLMEmbedClient, error)

func (*OllamaProvider) GetID

func (p *OllamaProvider) GetID() string

func (*OllamaProvider) GetPromptConnection

func (p *OllamaProvider) GetPromptConnection(ctx context.Context, backendID string) (LLMPromptExecClient, error)

func (*OllamaProvider) GetStreamConnection

func (p *OllamaProvider) GetStreamConnection(ctx context.Context, backendID string) (LLMStreamClient, error)

func (*OllamaProvider) GetType

func (p *OllamaProvider) GetType() string

func (*OllamaProvider) ModelName

func (p *OllamaProvider) ModelName() string

type OpenAIProvider

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

func NewOpenAIProvider

func NewOpenAIProvider(apiKey, modelName string, backendURLs []string, capability CapabilityConfig, httpClient *http.Client) *OpenAIProvider

func (*OpenAIProvider) CanChat

func (p *OpenAIProvider) CanChat() bool

func (*OpenAIProvider) CanEmbed

func (p *OpenAIProvider) CanEmbed() bool

func (*OpenAIProvider) CanPrompt

func (p *OpenAIProvider) CanPrompt() bool

func (*OpenAIProvider) CanStream

func (p *OpenAIProvider) CanStream() bool

func (*OpenAIProvider) CanThink added in v0.0.8

func (p *OpenAIProvider) CanThink() bool

func (*OpenAIProvider) GetBackendIDs

func (p *OpenAIProvider) GetBackendIDs() []string

func (*OpenAIProvider) GetChatConnection

func (p *OpenAIProvider) GetChatConnection(ctx context.Context, backendID string) (LLMChatClient, error)

func (*OpenAIProvider) GetContextLength

func (p *OpenAIProvider) GetContextLength() int

func (*OpenAIProvider) GetEmbedConnection

func (p *OpenAIProvider) GetEmbedConnection(ctx context.Context, backendID string) (LLMEmbedClient, error)

func (*OpenAIProvider) GetID

func (p *OpenAIProvider) GetID() string

func (*OpenAIProvider) GetPromptConnection

func (p *OpenAIProvider) GetPromptConnection(ctx context.Context, backendID string) (LLMPromptExecClient, error)

func (*OpenAIProvider) GetStreamConnection

func (p *OpenAIProvider) GetStreamConnection(ctx context.Context, backendID string) (LLMStreamClient, error)

func (*OpenAIProvider) GetType

func (p *OpenAIProvider) GetType() string

func (*OpenAIProvider) ModelName

func (p *OpenAIProvider) ModelName() string

type Provider

type Provider interface {
	GetBackendIDs() []string // Available backend instances
	ModelName() string       // Model name (e.g., "llama2:latest")
	GetID() string           // unique identifier for the model provider
	GetType() string         // Type of the model provider
	GetContextLength() int   // Maximum context length supported
	CanChat() bool           // Supports chat interactions
	CanEmbed() bool          // Supports embeddings
	CanStream() bool         // Supports streaming
	CanPrompt() bool         // Supports prompting
	CanThink() bool          // Supports thinking
	GetChatConnection(ctx context.Context, backendID string) (LLMChatClient, error)
	GetPromptConnection(ctx context.Context, backendID string) (LLMPromptExecClient, error)
	GetEmbedConnection(ctx context.Context, backendID string) (LLMEmbedClient, error)
	GetStreamConnection(ctx context.Context, backendID string) (LLMStreamClient, error)
}

Provider is a provider of backend instances capable of executing requests with this Model.

func NewOllamaModelProvider

func NewOllamaModelProvider(name string, backends []string, httpClient *http.Client, caps CapabilityConfig) Provider

NewOllamaModelProvider creates a provider with explicit capabilities

func NewVLLMModelProvider

func NewVLLMModelProvider(modelName string, backends []string, client *http.Client, caps CapabilityConfig, authToken string) Provider

NewVLLMModelProvider creates a new vLLM model provider with explicit capabilities

type StreamParcel

type StreamParcel struct {
	Data  string
	Error error
}

type VLLMChatClient

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

VLLMChatClient handles chat interaction

func (*VLLMChatClient) Chat

func (c *VLLMChatClient) Chat(ctx context.Context, messages []Message, options ...ChatOption) (Message, error)

Chat implements LLMChatClient interface

func (*VLLMChatClient) Prompt added in v0.0.4

func (c *VLLMChatClient) Prompt(ctx context.Context, systeminstruction string, temperature float32, prompt string) (string, error)

Prompt implements LLMPromptExecClient interface

type VLLMPromptClient

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

VLLMPromptClient handles prompt execution

func (*VLLMPromptClient) Prompt

func (c *VLLMPromptClient) Prompt(ctx context.Context, systeminstruction string, temperature float32, prompt string) (string, error)

Prompt implements LLMPromptExecClient interface

type VLLMStreamClient added in v0.0.11

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

VLLMStreamClient handles streaming responses from vLLM

func (*VLLMStreamClient) Prompt added in v0.0.11

func (c *VLLMStreamClient) Prompt(ctx context.Context, systeminstruction string, temperature float32, prompt string) (string, error)

Prompt implements LLMPromptExecClient interface

func (*VLLMStreamClient) Stream added in v0.0.11

func (c *VLLMStreamClient) Stream(ctx context.Context, prompt string) (<-chan *StreamParcel, error)

Stream implements LLMStreamClient interface Stream implements LLMStreamClient interface

Jump to

Keyboard shortcuts

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