providers

package
v0.2.18 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthTypeBearer  = "bearer"
	AuthTypeXheader = "xheader"
	AuthTypeQuery   = "query"
	AuthTypeNone    = "none"
)

The authentication type of the specific provider

View Source
const (
	AnthropicDefaultBaseURL  = "https://api.anthropic.com"
	CloudflareDefaultBaseURL = "https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}"
	CohereDefaultBaseURL     = "https://api.cohere.com"
	GroqDefaultBaseURL       = "https://api.groq.com"
	OllamaDefaultBaseURL     = "http://ollama:8080"
	OpenaiDefaultBaseURL     = "https://api.openai.com"
)

The default base URLs of each provider

View Source
const (
	AnthropicID  = "anthropic"
	CloudflareID = "cloudflare"
	CohereID     = "cohere"
	GroqID       = "groq"
	OllamaID     = "ollama"
	OpenaiID     = "openai"
)

The ID's of each provider

View Source
const (
	AnthropicDisplayName  = "Anthropic"
	CloudflareDisplayName = "Cloudflare"
	CohereDisplayName     = "Cohere"
	GroqDisplayName       = "Groq"
	OllamaDisplayName     = "Ollama"
	OpenaiDisplayName     = "Openai"
)

Display names for providers

View Source
const (
	MessageRoleSystem    = "system"
	MessageRoleUser      = "user"
	MessageRoleAssistant = "assistant"
	MessageRoleTool      = "tool"
)
View Source
const (
	Event = "event"
	Done  = "[DONE]"
	Data  = "data"
	Retry = "retry"
)
View Source
const (
	// Ollama endpoints
	OllamaListEndpoint     = "/api/tags"
	OllamaGenerateEndpoint = "/api/chat"

	// OpenAI endpoints
	OpenAIListEndpoint     = "/v1/models"
	OpenAIGenerateEndpoint = "/v1/chat/completions"

	// Groq endpoints
	GroqListEndpoint     = "/openai/v1/models"
	GroqGenerateEndpoint = "/openai/v1/chat/completions"

	// Cohere endpoints
	CohereListEndpoint     = "/v1/models"
	CohereGenerateEndpoint = "/v2/chat"

	// Cloudflare endpoints
	CloudflareListEndpoint     = "/ai/finetunes/public"
	CloudflareGenerateEndpoint = "/ai/run/@cf/meta/{model}"

	// Anthropic endpoints
	AnthropicListEndpoint     = "/v1/models"
	AnthropicGenerateEndpoint = "/v1/messages"
)

Variables

View Source
var AnthropicExtraHeaders = map[string][]string{
	"anthropic-version": {"2023-06-01"},
}

Extra headers for Anthropic provider

View Source
var Registry = map[string]Config{
	AnthropicID: {
		ID:       AnthropicID,
		Name:     AnthropicDisplayName,
		URL:      AnthropicDefaultBaseURL,
		AuthType: AuthTypeXheader,
		ExtraHeaders: map[string][]string{
			"anthropic-version": {"2023-06-01"},
		},
		Endpoints: Endpoints{
			List:     AnthropicListEndpoint,
			Generate: AnthropicGenerateEndpoint,
		},
	},
	CloudflareID: {
		ID:       CloudflareID,
		Name:     CloudflareDisplayName,
		URL:      CloudflareDefaultBaseURL,
		AuthType: AuthTypeBearer,
		Endpoints: Endpoints{
			List:     CloudflareListEndpoint,
			Generate: CloudflareGenerateEndpoint,
		},
	},
	CohereID: {
		ID:       CohereID,
		Name:     CohereDisplayName,
		URL:      CohereDefaultBaseURL,
		AuthType: AuthTypeBearer,
		Endpoints: Endpoints{
			List:     CohereListEndpoint,
			Generate: CohereGenerateEndpoint,
		},
	},
	GroqID: {
		ID:       GroqID,
		Name:     GroqDisplayName,
		URL:      GroqDefaultBaseURL,
		AuthType: AuthTypeBearer,
		Endpoints: Endpoints{
			List:     GroqListEndpoint,
			Generate: GroqGenerateEndpoint,
		},
	},
	OllamaID: {
		ID:       OllamaID,
		Name:     OllamaDisplayName,
		URL:      OllamaDefaultBaseURL,
		AuthType: AuthTypeNone,
		Endpoints: Endpoints{
			List:     OllamaListEndpoint,
			Generate: OllamaGenerateEndpoint,
		},
	},
	OpenaiID: {
		ID:       OpenaiID,
		Name:     OpenaiDisplayName,
		URL:      OpenaiDefaultBaseURL,
		AuthType: AuthTypeBearer,
		Endpoints: Endpoints{
			List:     OpenAIListEndpoint,
			Generate: OpenAIGenerateEndpoint,
		},
	},
}

The registry of all providers

Functions

func BoolPtr added in v0.1.13

func BoolPtr(v bool) *bool

func Float64Ptr added in v0.1.13

func Float64Ptr(v float64) *float64

func IntPtr added in v0.1.13

func IntPtr(v int) *int

Types

type AnthropicContent added in v0.1.6

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

type AnthropicModel added in v0.1.6

type AnthropicModel struct {
	Type        string `json:"type"`
	ID          string `json:"id"`
	DisplayName string `json:"display_name"`
	CreatedAt   string `json:"created_at"`
}

type AnthropicStreamParser added in v0.1.11

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

func (*AnthropicStreamParser) ParseChunk added in v0.1.11

func (p *AnthropicStreamParser) ParseChunk(reader *bufio.Reader) (*SSEvent, error)

type AnthropicUsage added in v0.1.6

type AnthropicUsage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

type Client added in v0.1.6

type Client interface {
	Do(req *http.Request) (*http.Response, error)
	Get(url string) (*http.Response, error)
	Post(url string, bodyType string, body string) (*http.Response, error)
}

func NewHTTPClient added in v0.1.10

func NewHTTPClient(cfg *ClientConfig, scheme, hostname, port string) Client

type ClientConfig added in v0.1.10

type ClientConfig struct {
	ClientTimeout             time.Duration `env:"CLIENT_TIMEOUT, default=30s" description:"Client timeout"`
	ClientMaxIdleConns        int           `env:"CLIENT_MAX_IDLE_CONNS, default=20" description:"Maximum idle connections"`
	ClientMaxIdleConnsPerHost int           `env:"CLIENT_MAX_IDLE_CONNS_PER_HOST, default=20" description:"Maximum idle connections per host"`
	ClientIdleConnTimeout     time.Duration `env:"CLIENT_IDLE_CONN_TIMEOUT, default=30s" description:"Idle connection timeout"`
	ClientTlsMinVersion       string        `env:"CLIENT_TLS_MIN_VERSION, default=TLS12" description:"Minimum TLS version"`
}

func NewClientConfig added in v0.1.10

func NewClientConfig() (*ClientConfig, error)

type ClientImpl added in v0.1.6

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

func (*ClientImpl) Do added in v0.1.6

func (c *ClientImpl) Do(req *http.Request) (*http.Response, error)

func (*ClientImpl) Get added in v0.1.6

func (c *ClientImpl) Get(url string) (*http.Response, error)

func (*ClientImpl) Post added in v0.1.6

func (c *ClientImpl) Post(url string, bodyType string, body string) (*http.Response, error)

type CloudflareModel added in v0.1.6

type CloudflareModel struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	CreatedAt   string `json:"created_at"`
	ModifiedAt  string `json:"modified_at"`
	Public      int    `json:"public"`
	Model       string `json:"model"`
}

type CloudflareResult added in v0.1.6

type CloudflareResult struct {
	Response string `json:"response"`
}

type CloudflareStreamParser added in v0.1.11

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

func (*CloudflareStreamParser) ParseChunk added in v0.1.11

func (p *CloudflareStreamParser) ParseChunk(reader *bufio.Reader) (*SSEvent, error)

type CohereCitationOptions added in v0.1.6

type CohereCitationOptions struct {
	Content interface{} `json:"content,omitempty"`
}

type CohereContent added in v0.1.6

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

type CohereContentItem added in v0.1.11

type CohereContentItem struct {
	Type string `json:"type,omitempty"`
	Text string `json:"text,omitempty"`
}

type CohereDelta added in v0.1.11

type CohereDelta struct {
	Message CohereDeltaMessage `json:"message,omitempty"`
}

type CohereDeltaMessage added in v0.1.11

type CohereDeltaMessage struct {
	Role      string          `json:"role,omitempty"`
	Content   json.RawMessage `json:"content,omitempty"`
	ToolPlan  string          `json:"tool_plan,omitempty"`
	ToolCalls []interface{}   `json:"tool_calls,omitempty"`
	Citations []interface{}   `json:"citations,omitempty"`
}

type CohereDocument added in v0.1.6

type CohereDocument struct {
	Content  string                 `json:"content,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

type CohereMessage added in v0.1.6

type CohereMessage struct {
	Role      string          `json:"role"`
	Content   []CohereContent `json:"content,omitempty"`
	ToolPlan  string          `json:"tool_plan"`
	ToolCalls []interface{}   `json:"tool_calls"`
	Citations []interface{}   `json:"citations"`
}

type CohereModel added in v0.1.6

type CohereModel struct {
	Name             string   `json:"name"`
	Endpoints        []string `json:"endpoints"`
	Finetuned        bool     `json:"finetuned"`
	ContextLength    float64  `json:"context_length"`
	TokenizerURL     string   `json:"tokenizer_url"`
	DefaultEndpoints []string `json:"default_endpoints"`
}

type CohereResponseFormat added in v0.1.6

type CohereResponseFormat struct {
	Type       string                 `json:"type,omitempty"`
	JsonSchema map[string]interface{} `json:"json_schema,omitempty"`
}

type CohereStreamParser added in v0.1.11

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

func (*CohereStreamParser) ParseChunk added in v0.1.11

func (p *CohereStreamParser) ParseChunk(reader *bufio.Reader) (*SSEvent, error)

type CohereStreamResponse added in v0.1.11

type CohereStreamResponse struct {
	Id    string      `json:"id,omitempty"`
	Type  EventType   `json:"type,omitempty"`
	Delta CohereDelta `json:"delta,omitempty"`
}

func (*CohereStreamResponse) Transform added in v0.1.11

func (g *CohereStreamResponse) Transform() GenerateResponse

type CohereTool added in v0.1.6

type CohereTool struct {
	Description string                 `json:"description,omitempty"`
	Name        string                 `json:"name,omitempty"`
	Parameters  map[string]interface{} `json:"parameters,omitempty"`
}

type CohereUsage added in v0.1.6

type CohereUsage struct {
	BilledUnits CohereUsageUnits `json:"billed_units"`
	Tokens      CohereUsageUnits `json:"tokens"`
}

type CohereUsageUnits added in v0.1.6

type CohereUsageUnits struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
}

type Config added in v0.1.6

type Config struct {
	ID           string
	Name         string
	URL          string
	Token        string
	AuthType     string
	ExtraHeaders map[string][]string
	Endpoints    Endpoints
}

Base provider configuration

type Endpoints added in v0.1.6

type Endpoints struct {
	List     string
	Generate string
}

Endpoints exposed by each provider

type EventType added in v0.1.11

type EventType string
const (
	EventStreamStart    EventType = "stream-start"
	EventMessageStart   EventType = "message-start"
	EventContentStart   EventType = "content-start"
	EventContentDelta   EventType = "content-delta"
	EventContentEnd     EventType = "content-end"
	EventMessageEnd     EventType = "message-end"
	EventStreamEnd      EventType = "stream-end"
	EventTextGeneration EventType = "text-generation"
)

type EventTypeValue added in v0.1.11

type EventTypeValue string
const (
	EventStreamStartValue    EventTypeValue = `{"role":"assistant"}`
	EventMessageStartValue   EventTypeValue = `{}`
	EventContentStartValue   EventTypeValue = `{}`
	EventContentEndValue     EventTypeValue = `{}`
	EventMessageEndValue     EventTypeValue = `{}`
	EventStreamEndValue      EventTypeValue = `{}`
	EventTextGenerationValue EventTypeValue = `{}`
)

type FunctionTool added in v0.1.13

type FunctionTool struct {
	Name        string     `json:"name"`
	Description string     `json:"description"`
	Parameters  ToolParams `json:"parameters"`
}

FunctionTool represents a function that can be called

type FunctionToolCall added in v0.1.13

type FunctionToolCall struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	Arguments   json.RawMessage `json:"arguments"`
}

FunctionToolCall represents a function call

type GenerateRequest

type GenerateRequest struct {
	Messages  []Message `json:"messages"`
	Model     string    `json:"model"`
	Stream    bool      `json:"stream"`
	SSEvents  bool      `json:"ssevents"`
	Tools     []Tool    `json:"tools"`
	MaxTokens int       `json:"max_tokens,omitempty"`
}

Common response and request types

func (*GenerateRequest) TransformAnthropic added in v0.1.6

func (r *GenerateRequest) TransformAnthropic() GenerateRequestAnthropic

func (*GenerateRequest) TransformCloudflare added in v0.1.6

func (r *GenerateRequest) TransformCloudflare() GenerateRequestCloudflare

func (*GenerateRequest) TransformCohere added in v0.1.6

func (r *GenerateRequest) TransformCohere() GenerateRequestCohere

func (*GenerateRequest) TransformGroq added in v0.1.6

func (r *GenerateRequest) TransformGroq() GenerateRequestGroq

func (*GenerateRequest) TransformOllama added in v0.1.6

func (r *GenerateRequest) TransformOllama() GenerateRequestOllama

func (*GenerateRequest) TransformOpenai added in v0.1.6

func (r *GenerateRequest) TransformOpenai() GenerateRequestOpenai

type GenerateRequestAnthropic added in v0.1.5

type GenerateRequestAnthropic struct {
	Model     string    `json:"model"`
	MaxTokens *int      `json:"max_tokens,omitempty"`
	Messages  []Message `json:"messages"`
}

type GenerateRequestCloudflare

type GenerateRequestCloudflare struct {
	Model             string    `json:"model"`
	Messages          []Message `json:"messages"`
	FrequencyPenalty  *float64  `json:"frequency_penalty,omitempty"`
	MaxTokens         *int      `json:"max_tokens,omitempty"`
	PresencePenalty   *float64  `json:"presence_penalty,omitempty"`
	RepetitionPenalty *float64  `json:"repetition_penalty,omitempty"`
	Seed              *int      `json:"seed,omitempty"`
	Stream            *bool     `json:"stream,omitempty"`
	Temperature       *float64  `json:"temperature,omitempty"`
	TopK              *int      `json:"top_k,omitempty"`
	TopP              *float64  `json:"top_p,omitempty"`
	Functions         []struct {
		Code string `json:"code"`
		Name string `json:"name"`
	} `json:"functions,omitempty"`
	Tools []struct {
		Description string                 `json:"description,omitempty"`
		Name        string                 `json:"name,omitempty"`
		Parameters  map[string]interface{} `json:"parameters,omitempty"`
		Function    map[string]interface{} `json:"function,omitempty"`
		Type        string                 `json:"type,omitempty"`
	} `json:"tools,omitempty"`
}

type GenerateRequestCohere

type GenerateRequestCohere struct {
	Messages         []Message              `json:"messages"`
	Model            string                 `json:"model"`
	Stream           bool                   `json:"stream"`
	Tools            []CohereTool           `json:"tools,omitempty"`
	Documents        []CohereDocument       `json:"documents,omitempty"`
	CitationOptions  *CohereCitationOptions `json:"citation_options,omitempty"`
	ResponseFormat   *CohereResponseFormat  `json:"response_format,omitempty"`
	SafetyMode       string                 `json:"safety_mode,omitempty"`
	MaxTokens        *int                   `json:"max_tokens,omitempty"`
	StopSequences    []string               `json:"stop_sequences,omitempty"`
	Temperature      *float64               `json:"temperature,omitempty"`
	Seed             *int                   `json:"seed,omitempty"`
	FrequencyPenalty *float64               `json:"frequency_penalty,omitempty"`
	PresencePenalty  *float64               `json:"presence_penalty,omitempty"`
	K                *float64               `json:"k,omitempty"`
	P                *float64               `json:"p,omitempty"`
	LogProbs         *bool                  `json:"logprobs,omitempty"`
	ToolChoice       string                 `json:"tool_choice,omitempty"`
	StrictTools      *bool                  `json:"strict_tools,omitempty"`
}

type GenerateRequestGroq

type GenerateRequestGroq struct {
	Messages            []Message `json:"messages"`
	Model               string    `json:"model"`
	Temperature         *float64  `json:"temperature,omitempty"`
	MaxCompletionTokens int       `json:"max_completion_tokens,omitempty"`
	TopP                *float64  `json:"top_p,omitempty"`
	FrequencyPenalty    *float64  `json:"frequency_penalty,omitempty"`
	PresencePenalty     *float64  `json:"presence_penalty,omitempty"`
	Stream              *bool     `json:"stream,omitempty"`
	Stop                []string  `json:"stop,omitempty"`
	User                *string   `json:"user,omitempty"`
	ResponseFormat      *struct {
		Type string `json:"type"`
	} `json:"response_format,omitempty"`
	Seed        *int    `json:"seed,omitempty"`
	ServiceTier *string `json:"service_tier,omitempty"`
	Tools       []Tool  `json:"tools,omitempty"`
}

type GenerateRequestOllama

type GenerateRequestOllama struct {
	Model     string         `json:"model"`
	Messages  []Message      `json:"messages"`
	Template  string         `json:"template,omitempty"`
	Context   []int          `json:"context,omitempty"`
	Stream    bool           `json:"stream"`
	Raw       bool           `json:"raw,omitempty"`
	Format    interface{}    `json:"format,omitempty"`
	Options   *OllamaOptions `json:"options,omitempty"`
	Images    []string       `json:"images,omitempty"`
	KeepAlive string         `json:"keep_alive,omitempty"`
	Tools     []Tool         `json:"tools,omitempty"`
}

type GenerateRequestOpenai added in v0.1.6

type GenerateRequestOpenai struct {
	Model       string    `json:"model"`
	Messages    []Message `json:"messages"`
	Temperature float64   `json:"temperature,omitempty"`
}

type GenerateResponse

type GenerateResponse struct {
	Provider  string         `json:"provider"`
	Response  ResponseTokens `json:"response"`
	EventType EventType      `json:"event_type,omitempty"`
	Usage     *Usage         `json:"usage,omitempty"`
}

type GenerateResponseAnthropic added in v0.1.5

type GenerateResponseAnthropic struct {
	ID           string             `json:"id"`
	Type         string             `json:"type"`
	Role         string             `json:"role"`
	Content      []AnthropicContent `json:"content"`
	Model        string             `json:"model"`
	StopReason   string             `json:"stop_reason"`
	StopSequence interface{}        `json:"stop_sequence"`
	Usage        AnthropicUsage     `json:"usage"`
}

func (*GenerateResponseAnthropic) Transform added in v0.1.6

type GenerateResponseCloudflare

type GenerateResponseCloudflare struct {
	Result   CloudflareResult `json:"result"`
	Success  bool             `json:"success"`
	Errors   []string         `json:"errors"`
	Messages []string         `json:"messages"`
}

func (*GenerateResponseCloudflare) Transform added in v0.1.6

type GenerateResponseCohere

type GenerateResponseCohere struct {
	ID           string        `json:"id"`
	FinishReason string        `json:"finish_reason"`
	Message      CohereMessage `json:"message"`
	Usage        CohereUsage   `json:"usage,omitempty"`
	LogProbs     []interface{} `json:"logprobs,omitempty"`
}

func (*GenerateResponseCohere) Transform added in v0.1.6

type GenerateResponseGroq

type GenerateResponseGroq struct {
	ID                string       `json:"id"`
	Object            string       `json:"object"`
	Created           int64        `json:"created"`
	Model             string       `json:"model"`
	Choices           []GroqChoice `json:"choices"`
	Usage             *GroqUsage   `json:"usage,omitempty"`
	SystemFingerprint string       `json:"system_fingerprint"`
	XGroq             struct {
		ID string `json:"id"`
	} `json:"x_groq"`
}

func (*GenerateResponseGroq) Transform added in v0.1.6

func (g *GenerateResponseGroq) Transform() GenerateResponse

type GenerateResponseOllama

type GenerateResponseOllama struct {
	Model              string  `json:"model"`
	CreatedAt          string  `json:"created_at"`
	Message            Message `json:"message"`
	Response           string  `json:"response,omitempty"`
	Done               bool    `json:"done"`
	DoneReason         string  `json:"done_reason,omitempty"`
	Context            []int   `json:"context,omitempty"`
	TotalDuration      float64 `json:"total_duration,omitempty"`
	LoadDuration       float64 `json:"load_duration,omitempty"`
	PromptEvalCount    int64   `json:"prompt_eval_count,omitempty"`
	PromptEvalDuration float64 `json:"prompt_eval_duration,omitempty"`
	EvalCount          int64   `json:"eval_count,omitempty"`
	EvalDuration       float64 `json:"eval_duration,omitempty"`
}

func (*GenerateResponseOllama) Transform added in v0.1.6

type GenerateResponseOpenai added in v0.1.6

type GenerateResponseOpenai struct {
	ID      string         `json:"id"`
	Object  string         `json:"object"`
	Created int64          `json:"created"`
	Model   string         `json:"model"`
	Usage   OpenaiUsage    `json:"usage"`
	Choices []OpenaiChoice `json:"choices"`
}

func (*GenerateResponseOpenai) Transform added in v0.1.6

type GroqChoice added in v0.1.6

type GroqChoice struct {
	Index        int         `json:"index"`
	Message      Message     `json:"message"`
	Delta        GroqDelta   `json:"delta,omitempty"`
	LogProbs     interface{} `json:"logprobs"`
	FinishReason string      `json:"finish_reason"`
}

type GroqDelta added in v0.1.11

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

type GroqModel added in v0.1.6

type GroqModel struct {
	ID            string      `json:"id"`
	Object        string      `json:"object"`
	Created       int64       `json:"created"`
	OwnedBy       string      `json:"owned_by"`
	Active        bool        `json:"active"`
	ContextWindow int         `json:"context_window"`
	PublicApps    interface{} `json:"public_apps"`
}

type GroqStreamParser added in v0.1.11

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

func NewGroqStreamParser added in v0.1.13

func NewGroqStreamParser(logger logger.Logger) *GroqStreamParser

func (*GroqStreamParser) ParseChunk added in v0.1.11

func (p *GroqStreamParser) ParseChunk(reader *bufio.Reader) (*SSEvent, error)

type GroqUsage added in v0.1.6

type GroqUsage struct {
	QueueTime        float64 `json:"queue_time"`
	PromptTokens     int64   `json:"prompt_tokens"`
	PromptTime       float64 `json:"prompt_time"`
	CompletionTokens int64   `json:"completion_tokens"`
	CompletionTime   float64 `json:"completion_time"`
	TotalTokens      int64   `json:"total_tokens"`
	TotalTime        float64 `json:"total_time"`
}

type ListModelsResponse added in v0.1.6

type ListModelsResponse struct {
	Models   []Model `json:"models"`
	Provider string  `json:"provider"`
}

type ListModelsResponseAnthropic added in v0.1.6

type ListModelsResponseAnthropic struct {
	Data    []AnthropicModel `json:"data"`
	HasMore bool             `json:"has_more"`
	FirstID string           `json:"first_id"`
	LastID  string           `json:"last_id"`
}

func (*ListModelsResponseAnthropic) Transform added in v0.1.6

type ListModelsResponseCloudflare added in v0.1.6

type ListModelsResponseCloudflare struct {
	Result []CloudflareModel `json:"result"`
}

func (*ListModelsResponseCloudflare) Transform added in v0.1.6

type ListModelsResponseCohere added in v0.1.6

type ListModelsResponseCohere struct {
	Models        []CohereModel `json:"models"`
	NextPageToken string        `json:"next_page_token"`
}

func (*ListModelsResponseCohere) Transform added in v0.1.6

type ListModelsResponseGroq added in v0.1.6

type ListModelsResponseGroq struct {
	Object string      `json:"object"`
	Data   []GroqModel `json:"data"`
}

func (*ListModelsResponseGroq) Transform added in v0.1.6

type ListModelsResponseOllama added in v0.1.6

type ListModelsResponseOllama struct {
	Models []OllamaModel `json:"models"`
}

func (*ListModelsResponseOllama) Transform added in v0.1.6

type ListModelsResponseOpenai added in v0.1.6

type ListModelsResponseOpenai struct {
	Object string        `json:"object"`
	Data   []OpenaiModel `json:"data"`
}

func (*ListModelsResponseOpenai) Transform added in v0.1.6

type Message added in v0.1.6

type Message struct {
	Content    string     `json:"content"`
	Role       string     `json:"role"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
	Reasoning  string     `json:"reasoning,omitempty"`
	ToolCallID string     `json:"tool_call_id,omitempty"`
}

type Model added in v0.1.6

type Model struct {
	Name string `json:"name"`
}

type OllamaDetails added in v0.1.6

type OllamaDetails struct {
	Format            string      `json:"format"`
	Family            string      `json:"family"`
	Families          interface{} `json:"families"`
	ParameterSize     string      `json:"parameter_size"`
	QuantizationLevel string      `json:"quantization_level"`
}

type OllamaModel added in v0.1.6

type OllamaModel struct {
	Name       string        `json:"name"`
	ModifiedAt string        `json:"modified_at"`
	Size       int           `json:"size"`
	Digest     string        `json:"digest"`
	Details    OllamaDetails `json:"details"`
}

type OllamaOptions added in v0.1.6

type OllamaOptions struct {
	NumKeep          *int     `json:"num_keep,omitempty"`
	Seed             *int     `json:"seed,omitempty"`
	NumPredict       *int     `json:"num_predict,omitempty"`
	TopK             *int     `json:"top_k,omitempty"`
	TopP             *float64 `json:"top_p,omitempty"`
	MinP             *float64 `json:"min_p,omitempty"`
	TypicalP         *float64 `json:"typical_p,omitempty"`
	RepeatLastN      *int     `json:"repeat_last_n,omitempty"`
	Temperature      *float64 `json:"temperature,omitempty"`
	RepeatPenalty    *float64 `json:"repeat_penalty,omitempty"`
	PresencePenalty  *float64 `json:"presence_penalty,omitempty"`
	FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
	Mirostat         *int     `json:"mirostat,omitempty"`
	MirostatTau      *float64 `json:"mirostat_tau,omitempty"`
	MirostatEta      *float64 `json:"mirostat_eta,omitempty"`
	PenalizeNewline  *bool    `json:"penalize_newline,omitempty"`
	Stop             []string `json:"stop,omitempty"`
	NumCtx           *int     `json:"num_ctx,omitempty"`
	NumBatch         *int     `json:"num_batch,omitempty"`
	NumGPU           *int     `json:"num_gpu,omitempty"`
	MainGPU          *int     `json:"main_gpu,omitempty"`
	LowVRAM          *bool    `json:"low_vram,omitempty"`
	VocabOnly        *bool    `json:"vocab_only,omitempty"`
	UseMMap          *bool    `json:"use_mmap,omitempty"`
	UseMlock         *bool    `json:"use_mlock,omitempty"`
	NumThread        *int     `json:"num_thread,omitempty"`
}

Advanced options for Ollama model generation

type OllamaStreamParser added in v0.1.11

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

func (*OllamaStreamParser) ParseChunk added in v0.1.11

func (p *OllamaStreamParser) ParseChunk(reader *bufio.Reader) (*SSEvent, error)

type OpenaiChoice added in v0.1.6

type OpenaiChoice struct {
	Message      Message     `json:"message"`
	LogProbs     interface{} `json:"logprobs"`
	FinishReason string      `json:"finish_reason"`
	Index        int         `json:"index"`
}

type OpenaiModel added in v0.1.6

type OpenaiModel struct {
	ID         string             `json:"id"`
	Object     string             `json:"object"`
	Created    int64              `json:"created"`
	OwnedBy    string             `json:"owned_by"`
	Permission []OpenaiPermission `json:"permission"`
	Root       string             `json:"root"`
	Parent     string             `json:"parent"`
}

type OpenaiPermission added in v0.1.6

type OpenaiPermission struct {
	ID                 string `json:"id"`
	Object             string `json:"object"`
	Created            int64  `json:"created"`
	AllowCreateEngine  bool   `json:"allow_create_engine"`
	AllowSampling      bool   `json:"allow_sampling"`
	AllowLogprobs      bool   `json:"allow_logprobs"`
	AllowSearchIndices bool   `json:"allow_search_indices"`
	AllowView          bool   `json:"allow_view"`
	AllowFineTuning    bool   `json:"allow_fine_tuning"`
}

type OpenaiStreamParser added in v0.1.11

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

func (*OpenaiStreamParser) ParseChunk added in v0.1.11

func (p *OpenaiStreamParser) ParseChunk(reader *bufio.Reader) (*SSEvent, error)

type OpenaiUsage added in v0.1.6

type OpenaiUsage struct {
	PromptTokens     int                `json:"prompt_tokens"`
	CompletionTokens int                `json:"completion_tokens"`
	TotalTokens      int                `json:"total_tokens"`
	TokensDetails    OpenaiUsageDetails `json:"completion_tokens_details"`
}

type OpenaiUsageDetails added in v0.1.6

type OpenaiUsageDetails struct {
	ReasoningTokens          int `json:"reasoning_tokens"`
	AcceptedPredictionTokens int `json:"accepted_prediction_tokens"`
	RejectedPredictionTokens int `json:"rejected_prediction_tokens"`
}

type Provider added in v0.1.6

type Provider interface {
	// Getters
	GetID() string
	GetName() string
	GetURL() string
	GetToken() string
	GetAuthType() string
	GetExtraHeaders() map[string][]string

	// Fetchers
	ListModels(ctx context.Context) (ListModelsResponse, error)
	GenerateTokens(ctx context.Context, model string, messages []Message, tools []Tool, maxTokens int) (GenerateResponse, error)
	StreamTokens(ctx context.Context, model string, messages []Message) (<-chan GenerateResponse, error)
}

type ProviderImpl added in v0.1.6

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

func (*ProviderImpl) EndpointGenerate added in v0.1.6

func (p *ProviderImpl) EndpointGenerate() string

func (*ProviderImpl) EndpointList added in v0.1.6

func (p *ProviderImpl) EndpointList() string

func (*ProviderImpl) GenerateTokens added in v0.1.6

func (p *ProviderImpl) GenerateTokens(ctx context.Context, model string, messages []Message, tools []Tool, maxTokens int) (GenerateResponse, error)

func (*ProviderImpl) GetAuthType added in v0.1.6

func (p *ProviderImpl) GetAuthType() string

func (*ProviderImpl) GetExtraHeaders added in v0.1.6

func (p *ProviderImpl) GetExtraHeaders() map[string][]string

func (*ProviderImpl) GetID added in v0.1.6

func (p *ProviderImpl) GetID() string

func (*ProviderImpl) GetName added in v0.1.6

func (p *ProviderImpl) GetName() string

func (*ProviderImpl) GetToken added in v0.1.6

func (p *ProviderImpl) GetToken() string

func (*ProviderImpl) GetURL added in v0.1.6

func (p *ProviderImpl) GetURL() string

func (*ProviderImpl) ListModels added in v0.1.6

func (p *ProviderImpl) ListModels(ctx context.Context) (ListModelsResponse, error)

func (*ProviderImpl) StreamTokens added in v0.1.11

func (p *ProviderImpl) StreamTokens(ctx context.Context, model string, messages []Message) (<-chan GenerateResponse, error)

type ProviderRegistry added in v0.1.11

type ProviderRegistry interface {
	GetProviders() map[string]*Config
	BuildProvider(providerID string, client Client) (Provider, error)
}

func NewProviderRegistry added in v0.1.11

func NewProviderRegistry(cfg map[string]*Config, logger logger.Logger) ProviderRegistry

type ProviderRegistryImpl added in v0.1.11

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

func (*ProviderRegistryImpl) BuildProvider added in v0.1.11

func (p *ProviderRegistryImpl) BuildProvider(providerID string, client Client) (Provider, error)

func (*ProviderRegistryImpl) GetProviders added in v0.1.11

func (p *ProviderRegistryImpl) GetProviders() map[string]*Config

type ResponseTokens

type ResponseTokens struct {
	Content   string     `json:"content"`
	Model     string     `json:"model,omitempty"`
	Role      string     `json:"role,omitempty"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}

type SSEvent added in v0.1.11

type SSEvent struct {
	EventType EventType
	Data      []byte
}

SSEEvent represents a Server-Sent Event

func ParseSSEvents added in v0.1.11

func ParseSSEvents(line []byte) (*SSEvent, error)

ParseSSEvents parses a Server-Sent Event from a byte slice

type StreamParser added in v0.1.11

type StreamParser interface {
	ParseChunk(reader *bufio.Reader) (*SSEvent, error)
}

func NewStreamParser added in v0.1.11

func NewStreamParser(l logger.Logger, provider string) (StreamParser, error)

type Tool added in v0.1.13

type Tool struct {
	Type     string        `json:"type"`
	Function *FunctionTool `json:"function,omitempty"`
}

Tool represents a function tool that can be called by the LLM

type ToolCall added in v0.1.13

type ToolCall struct {
	ID       string           `json:"id,omitempty"`
	Type     string           `json:"type,omitempty"`
	Function FunctionToolCall `json:"function"`
}

ToolCall represents a tool invocation by the LLM

type ToolParams added in v0.1.13

type ToolParams struct {
	Type       string                  `json:"type"`
	Properties map[string]ToolProperty `json:"properties"`
	Required   []string                `json:"required"`
}

ToolParams represents the parameters for a function tool

type ToolProperty added in v0.1.13

type ToolProperty struct {
	Type        string `json:"type"`
	Description string `json:"description"`
}

ToolProperty represents a parameter property

type Usage added in v0.1.15

type Usage struct {
	QueueTime        float64 `json:"queue_time"`
	PromptTokens     int64   `json:"prompt_tokens"`
	PromptTime       float64 `json:"prompt_time"`
	CompletionTokens int64   `json:"completion_tokens"`
	CompletionTime   float64 `json:"completion_time"`
	TotalTokens      int64   `json:"total_tokens"`
	TotalTime        float64 `json:"total_time"`
}

Jump to

Keyboard shortcuts

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