Help us shape the future of Go! Take the 2026 Go Developer Survey

model

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewChatModel deprecated

func NewChatModel(opts ...OptionFunc) (model.AgenticModel, error)

NewChatModel 创建 OpenAI 兼容的聊天模型。

Deprecated: 请使用 NewChatModelContext,避免模型构造脱离调用方 context。

func NewChatModelContext added in v0.3.3

func NewChatModelContext(ctx context.Context, opts ...OptionFunc) (model.AgenticModel, error)

NewChatModelContext 创建 OpenAI 兼容的聊天模型。 ctx 用于底层 HTTP client 的构造与请求关联;Model 与 APIKey 必填。 BaseURL 可选,缺省时使用 OpenAI 官方地址。

func NewEmbModel

func NewEmbModel(opts ...OptionFunc) (embedding.Embedder, error)

Types

type Option

type Option struct {
	Platform   string
	Model      string
	BaseUrl    string
	APIKey     string `json:"apiKey"`
	Dimensions int
	MaxTokens  int

	//openai参数
	ReasoningEffortLevel openai.ReasoningEffortLevel

	// HTTPClient 设置后 Timeout 不生效,由 client 自行控制超时
	HTTPClient *http.Client
	// Timeout 单次请求超时,<=0 时不设置
	Timeout time.Duration
	// CustomHeaders 附加到每个请求的自定义 HTTP 头
	CustomHeaders map[string]string
	// ExtraFields 透传给底层 provider 的额外参数
	// (ReasoningEffortLevel 之外的手动扩展字段,键冲突时以后设置者为准)
	ExtraFields map[string]any
}

type OptionFunc

type OptionFunc func(option *Option)

func WithAPIKey

func WithAPIKey(apiKey string) OptionFunc

func WithBaseURL added in v0.3.3

func WithBaseURL(baseURL string) OptionFunc

WithBaseURL 设置 OpenAI 兼容服务地址(WithBaseUrl 的规范命名版本)。

func WithBaseUrl deprecated

func WithBaseUrl(baseUrl string) OptionFunc

WithBaseUrl 设置 OpenAI 兼容服务地址。

Deprecated: 命名不符合 Go initialism 约定,请使用 WithBaseURL。

func WithCustomHeaders added in v0.3.3

func WithCustomHeaders(headers map[string]string) OptionFunc

WithCustomHeaders 附加自定义 HTTP 头到每个请求。

func WithDimensions

func WithDimensions(dimensions int) OptionFunc

func WithExtraFields added in v0.3.3

func WithExtraFields(fields map[string]any) OptionFunc

WithExtraFields 设置透传给底层 provider 的额外参数。

func WithHTTPClient added in v0.3.3

func WithHTTPClient(client *http.Client) OptionFunc

WithHTTPClient 设置自定义 HTTP 客户端(设置后 Timeout 选项不生效)。

func WithMaxTokens

func WithMaxTokens(maxTokens int) OptionFunc

func WithModel

func WithModel(model string) OptionFunc

func WithPlatform

func WithPlatform(platform string) OptionFunc

WithPlatform 保留兼容;当前实现仅支持 OpenAI 兼容协议,该字段不生效。

func WithReasoningEffortLevel

func WithReasoningEffortLevel(reasoningEffortLevel openai.ReasoningEffortLevel) OptionFunc

func WithTimeout added in v0.3.3

func WithTimeout(timeout time.Duration) OptionFunc

WithTimeout 设置单次请求超时。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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