provider

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2025 License: MIT Imports: 16 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

View Source
var ProviderRegistry = make(map[_const.ProviderType]ProviderFactory)

ProviderRegistry stores all available providers

Functions

func RegisterProvider

func RegisterProvider(providerType _const.ProviderType, factory ProviderFactory)

RegisterProvider registers a new provider factory

Types

type ChatCompletionChoice

type ChatCompletionChoice struct {
	// Index is the choice index
	Index int `json:"index"`
	// Message is the message content
	Message Message `json:"message"`
	// FinishReason is the reason for finishing
	FinishReason string `json:"finish_reason"`
	// LogProbs is the log probabilities
	LogProbs map[string]interface{} `json:"logprobs,omitempty"`
}

ChatCompletionChoice represents a choice in a chat completion response

type ChatCompletionResponse

type ChatCompletionResponse struct {
	// ID is the response ID
	ID string `json:"id"`
	// Object is the object type
	Object string `json:"object"`
	// Created is the creation time
	Created int64 `json:"created"`
	// Model is the model used
	Model string `json:"model"`
	// SystemFingerprint is the system fingerprint
	SystemFingerprint string `json:"system_fingerprint,omitempty"`
	// Choices is the list of choices
	Choices []ChatCompletionChoice `json:"choices"`
	// Usage is the usage information
	Usage Usage `json:"usage"`
}

ChatCompletionResponse represents a chat completion response

type Message

type Message struct {
	// Role is the role of the message sender
	Role string `json:"role"`
	// Content is the content of the message
	Content string `json:"content"`
	// Images is the image data for multimodal models
	Images [][]byte `json:"-"`
	// Name is the name of the message sender
	Name string `json:"name,omitempty"`
	// Meta is the metadata
	Meta map[string]interface{} `json:"-"`
}

Message represents a chat message

type MessageArrayContentItem

type MessageArrayContentItem struct {
	// Type is the type of the content item
	Type string `json:"type"`
	// Text is the text content
	Text string `json:"text,omitempty"`
	// ImageURL is the image URL
	ImageURL MessageArrayContentItemImageURL `json:"image_url,omitempty"`
}

MessageArrayContentItem represents a content item in a message array

type MessageArrayContentItemImageURL

type MessageArrayContentItemImageURL struct {
	// URL is the image URL
	URL string `json:"url,omitempty"`
}

MessageArrayContentItemImageURL represents the image URL in a message array content item

type OpenAICompatibility

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

/ OpenAICompatibility implements the Provider interface for OpenAI models.

func (*OpenAICompatibility) Close

func (p *OpenAICompatibility) Close() error

/ Close closes the provider.

func (*OpenAICompatibility) CreateChatCompletion

func (p *OpenAICompatibility) CreateChatCompletion(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) ([]byte, error, []byte)

/ CreateChatCompletion creates a chat completion.

func (*OpenAICompatibility) CreateChatCompletionStream

func (p *OpenAICompatibility) CreateChatCompletionStream(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) (io.ReadCloser, error, []byte)

/ CreateChatCompletionStream creates a streaming chat completion.

func (*OpenAICompatibility) CreateChatCompletionUseStream

func (p *OpenAICompatibility) CreateChatCompletionUseStream(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) ([]byte, error, []byte)

/ CreateChatCompletionUseStream creates a chat completion using streaming.

func (*OpenAICompatibility) GetProviderType

func (p *OpenAICompatibility) GetProviderType() _const.ProviderType

/ GetProviderType returns the provider's type.

func (*OpenAICompatibility) SetBaseUrl

func (p *OpenAICompatibility) SetBaseUrl(url string, direct ...bool)

/ SetBaseUrl sets the base URL for the API.

type Provider

type Provider interface {
	// GetProviderType returns the type of the provider
	GetProviderType() _const.ProviderType

	// CreateChatCompletion creates a chat completion
	CreateChatCompletion(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) ([]byte, error, []byte)

	// CreateChatCompletionStream creates a streaming chat completion
	CreateChatCompletionStream(ctx context.Context, cancel context.CancelFunc, request []byte, model models.Model, usage *Usage) (io.ReadCloser, error, []byte)

	// Close closes any resources used by the provider
	Close() error
}

Provider defines the interface that all AI providers must implement

func NewProviderOpenAICompatibility

func NewProviderOpenAICompatibility(_ *config.Config) (Provider, error)

/ NewProviderOpenAICompatibility creates a new OpenAICompatibility provider.

type ProviderFactory

type ProviderFactory func(cfg *config.Config) (Provider, error)

ProviderFactory is a function that creates a new provider instance

type Usage

type Usage struct {
	// PromptTokens is the number of prompt tokens
	PromptTokens int `json:"prompt_tokens"`
	// CompletionTokens is the number of completion tokens
	CompletionTokens int `json:"completion_tokens"`
	// TotalTokens is the total number of tokens
	TotalTokens int `json:"total_tokens"`
	// PromptTokensDetails is the detailed prompt token usage information
	PromptTokensDetails UsagePromptTokensDetails `json:"prompt_tokens_details"`
	// CompletionTokensDetails is the detailed completion token usage information
	CompletionTokensDetails UsageCompletionTokensDetails `json:"completion_tokens_details"`
}

Usage represents token usage information

type UsageCompletionTokensDetails

type UsageCompletionTokensDetails struct {
	// AudioTokens is the number of audio tokens
	AudioTokens int `json:"audio_tokens"`
	// ReasoningTokens is the number of reasoning tokens
	ReasoningTokens int `json:"reasoning_tokens"`
}

UsageCompletionTokensDetails represents detailed completion token usage information

type UsagePromptTokensDetails

type UsagePromptTokensDetails struct {
	// CachedTokens is the number of cached tokens
	CachedTokens int `json:"cached_tokens"`
	// AudioTokens is the number of audio tokens
	AudioTokens int `json:"audio_tokens"`
}

UsagePromptTokensDetails represents detailed prompt token usage information

Jump to

Keyboard shortcuts

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