provider

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Stream 发起一轮流式调用;事件通道在结束或出错后关闭。
	Stream(ctx context.Context, messages []Message, tools []Tool) <-chan Event
}

Client 是一个模型厂商的流式调用客户端。

func New

func New(opts Options) (Client, error)

New 按厂商类型创建对应的协议客户端。

目前支持:

  • OpenAI 及 OpenAI 兼容网关(deepseek / groq / openrouter / xai / local);
  • Anthropic(Claude);
  • Google Gemini。

azure / vertexai / bedrock 需要额外的认证与部署参数,暂未迁移,调用时返回明确错误。

type Event

type Event struct {
	Type     EventType
	Content  string
	Thinking string
	Response *Response
	Error    error
}

Event 是流式响应中的一个事件。

type EventType

type EventType string

EventType 是流式事件类型。

const (
	EventContentDelta  EventType = "content_delta"
	EventThinkingDelta EventType = "thinking_delta"
	EventComplete      EventType = "complete"
	EventError         EventType = "error"
)

type FinishReason

type FinishReason string

FinishReason 是一轮调用的终止原因。

const (
	FinishEndTurn  FinishReason = "end_turn"
	FinishMaxToken FinishReason = "max_tokens"
	FinishToolUse  FinishReason = "tool_use"
	FinishUnknown  FinishReason = "unknown"
)

type Message

type Message struct {
	Role        Role
	Content     string
	ToolCalls   []ToolCall
	ToolResults []ToolResult
}

Message 是发给模型的对话消息。

与 gobrave 的 message.Message 不同,它额外承载工具调用 / 结果,用于在 Agent 循环内部维护「assistant(tool_calls) → tool(results)」的完整往返。

type Options

type Options struct {
	Provider        models.ModelProvider
	BaseURL         string
	APIKey          string
	SystemPrompt    string
	Model           models.Model
	MaxTokens       int64
	ReasoningEffort string
}

Options 描述一次调用的连接与模型参数。

type Response

type Response struct {
	Content      string
	ToolCalls    []ToolCall
	Usage        Usage
	FinishReason FinishReason
}

Response 是一轮调用的聚合结果。

type Role

type Role string

Role 是对话消息角色。

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type Tool

type Tool struct {
	Name        string
	Description string
	// InputSchema 是完整的 object JSON Schema(type / properties / required)。
	InputSchema map[string]any
}

Tool 是暴露给模型的工具定义。

type ToolCall

type ToolCall struct {
	ID    string
	Name  string
	Input string // JSON 参数
}

ToolCall 是模型发起的一次工具调用。

type ToolResult

type ToolResult struct {
	ToolCallID string
	Content    string
	IsError    bool
}

ToolResult 是一条工具调用结果(Role == RoleTool 的消息按 ToolResults 回填)。

type Usage

type Usage struct {
	InputTokens         int64
	OutputTokens        int64
	CacheCreationTokens int64
	CacheReadTokens     int64
}

Usage 是 token 用量统计。

Jump to

Keyboard shortcuts

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