providers

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package providers defines shared types for LLM provider implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnthropicChatStream

func AnthropicChatStream(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (<-chan StreamChunk, error)

AnthropicChatStream calls the Anthropic Messages API in streaming mode. Returns a channel of StreamChunk that is closed when the stream is complete.

func GroqChatStream

func GroqChatStream(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (<-chan StreamChunk, error)

GroqChatStream calls the Groq API in streaming mode via the OpenAI-compatible endpoint.

func OllamaChatStream

func OllamaChatStream(ctx context.Context, client *http.Client, baseURL string, input ChatInput) (<-chan StreamChunk, error)

OllamaChatStream calls the Ollama API in streaming mode. Returns a channel of StreamChunk that is closed when the stream is complete.

func OpenAIChatStream

func OpenAIChatStream(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (<-chan StreamChunk, error)

OpenAIChatStream calls the OpenAI chat completions API in streaming mode. Returns a channel of StreamChunk that is closed when the stream is complete.

Types

type ChatInput

type ChatInput struct {
	Model       string    `json:"model"`
	Messages    []Message `json:"messages"`
	Temperature float64   `json:"temperature,omitempty"`
	MaxTokens   int       `json:"max_tokens,omitempty"`
	Tools       []Tool    `json:"tools,omitempty"`
	ToolChoice  string    `json:"tool_choice,omitempty"`
	System      string    `json:"system,omitempty"`
}

ChatInput is the JSON input for a chat completion request.

type ChatOutput

type ChatOutput struct {
	Choices []Choice `json:"choices"`
	Usage   Usage    `json:"usage"`
	Cost    float64  `json:"cost"`
	Model   string   `json:"model"`
	Error   string   `json:"error,omitempty"`
}

ChatOutput is the JSON output from a chat completion.

func AnthropicChat

func AnthropicChat(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (ChatOutput, error)

AnthropicChat calls the Anthropic Messages API.

func GeminiChat

func GeminiChat(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (ChatOutput, error)

GeminiChat calls the Google Gemini generateContent API.

func GroqChat

func GroqChat(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (ChatOutput, error)

GroqChat calls the Groq API, which is OpenAI-compatible.

func MistralChat

func MistralChat(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (ChatOutput, error)

MistralChat calls the Mistral API, which is OpenAI-compatible. Default base URL: https://api.mistral.ai/v1

func OllamaChat

func OllamaChat(ctx context.Context, client *http.Client, baseURL string, input ChatInput) (ChatOutput, error)

OllamaChat calls a local Ollama instance.

func OpenAIChat

func OpenAIChat(ctx context.Context, client *http.Client, apiKey, baseURL string, input ChatInput) (ChatOutput, error)

OpenAIChat calls the OpenAI chat completions API.

type Choice

type Choice struct {
	Message      ChoiceMessage `json:"message"`
	FinishReason string        `json:"finish_reason"`
}

Choice represents a single completion choice.

type ChoiceMessage

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

ChoiceMessage is the message within a choice.

type EmbedInput

type EmbedInput struct {
	Model string   `json:"model"`
	Input []string `json:"input"`
}

EmbedInput is the JSON input for an embedding request.

type EmbedOutput

type EmbedOutput struct {
	Data  []EmbeddingData `json:"data"`
	Usage Usage           `json:"usage"`
	Cost  float64         `json:"cost"`
	Error string          `json:"error,omitempty"`
}

EmbedOutput is the JSON output from an embedding request.

func OpenAIEmbed

func OpenAIEmbed(ctx context.Context, client *http.Client, apiKey, baseURL string, input EmbedInput) (EmbedOutput, error)

OpenAIEmbed calls the OpenAI embeddings API.

type EmbeddingData

type EmbeddingData struct {
	Embedding []float64 `json:"embedding"`
	Index     int       `json:"index"`
}

EmbeddingData holds a single embedding vector.

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

FunctionCall contains the name and arguments for a tool invocation.

type Message

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

Message represents a conversation message.

type StreamChunk

type StreamChunk struct {
	Content string `json:"content"`
	Index   int    `json:"index"`
	Done    bool   `json:"done"`
}

StreamChunk represents a single chunk of content from a streaming LLM response.

type Tool

type Tool struct {
	Type     string       `json:"type"`
	Function ToolFunction `json:"function"`
}

Tool defines a function tool available to the model.

type ToolCall

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type"`
	Function FunctionCall `json:"function"`
}

ToolCall represents a model's request to call a tool.

type ToolFunction

type ToolFunction struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Parameters  any    `json:"parameters"`
}

ToolFunction describes a callable function.

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Usage tracks token consumption.

Jump to

Keyboard shortcuts

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