Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientBuilder ¶
type ClientBuilder interface {
Config(opts ...Option) ClientBuilder // 用Option去设置 core.config
Messages(messages ...core.Message) ClientBuilder // 批量设置消息
Temperature(temp float64) ClientBuilder // 采样温度,控制模型生成文本的多样性。temperature越高,生成的文本更多样,反之,生成的文本更确定。
Model(model string) ClientBuilder // 用于指定模型名称
MaxTokens(max int) ClientBuilder // 用于限制模型输出的最大 Token 数。若生成内容超过此值,生成将提前停止,且返回的finish_reason为length。
Stop(stop ...string) ClientBuilder // 用于指定停止词。当模型生成的文本中出现stop 指定的字符串或token_id时,生成将立即终止。
TopP(top float64) ClientBuilder // 核采样的概率阈值,控制模型生成文本的多样性。
TopK(top int) ClientBuilder // 指定生成过程中用于采样的候选 Token 数量。值越大,输出越随机;值越小,输出越确定。若设为 null 或大于 100,则禁用 top_k 策略,仅 top_p 策略生效。取值必须为大于或等于 0 的整数。
EnableThinking(think bool) ClientBuilder // 启用扩展思考/推理功能
ThinkingBudget(budget int) ClientBuilder
EnableSearch(search bool) ClientBuilder // 启用搜索功能
IncrementalOutput(enabled bool) ClientBuilder // 流式增量输出(DeepSeek, Qwen)
Format(format string) ClientBuilder // 响应格式,如 "json"(Ollama)
KeepAlive(duration string) ClientBuilder // 模型内存保持时长(Ollama)
UsageCallback(fn func(core.Usage)) ClientBuilder // 获取用量的返回值
Attach(attachments ...core.Attachment) ClientBuilder
UserMessage(msg string) ClientBuilder
SystemMessage(msg string) ClientBuilder // 独立设置系统消息
DeveloperMessage(msg string) ClientBuilder // 独立设置开发者消息 (OpenAI o1/o3)
AssistantMessage(msg string) ClientBuilder
Tools(tool ...core.Tool) ClientBuilder
ToolChoice(choice interface{}) ClientBuilder // 设置工具选择策略,支持 string (如 "auto") 或具体对象
ParallelToolCalls(parallel bool) ClientBuilder // 是否开启并行工具调用
PresencePenalty(penalty float64) ClientBuilder
FrequencyPenalty(penalty float64) ClientBuilder // 频率惩罚
ResponseFormat(format string) ClientBuilder // 设置响应格式, "json" / "text"
GetResponse() (*core.Response, error) // 获取默认(OpenAI)的响应
GetResponseFor(clientType ClientType) (*core.Response, error)
GetStream() (*core.Stream, error) // 获取默认(OpenAI)的流
GetStreamFor(clientType ClientType) (*core.Stream, error)
Build() (core.Client, error) // 构建并返回客户端(openai)
BuildFor(clientType ClientType) (core.Client, error)
}
type ClientType ¶
type ClientType int
const ( OpenAIClient ClientType = iota AnthropicClient DeepSeekClient AzureClient OllamaClient QwenClient // 阿里云通义千问(使用 DashScope API) )
type Option ¶ added in v0.2.4
Option defines the configuration options for ClientBuilder
func WithAuthToken ¶ added in v0.2.4
WithAuthToken sets the auth token
func WithBaseURL ¶ added in v0.2.4
WithBaseURL sets the base URL
func WithMaxRetries ¶ added in v0.2.4
WithMaxRetries sets the maximum number of retries
func WithTimeout ¶ added in v0.2.4
WithTimeout sets the request timeout
Directories
¶
| Path | Synopsis |
|---|---|
|
client
|
|
|
examples
|
|
|
01_basic_chat
command
Basic example demonstrating simple chat completion with OpenAI.
|
Basic example demonstrating simple chat completion with OpenAI. |
|
02_multi_turn
command
Multi-turn conversation example.
|
Multi-turn conversation example. |
|
03_streaming
command
Streaming response example.
|
Streaming response example. |
|
04_tool_calling
command
Tool calling example.
|
Tool calling example. |
|
05_multiple_providers
command
Multiple providers example.
|
Multiple providers example. |
|
06_image_input
command
Multimodal input example - sending images to the model.
|
Multimodal input example - sending images to the model. |
|
07_document_analysis
command
Document analysis example - analyzing PDF, text files, or other documents.
|
Document analysis example - analyzing PDF, text files, or other documents. |
|
08_multiple_images
command
Multiple images example - analyzing multiple images in one request.
|
Multiple images example - analyzing multiple images in one request. |
|
09_helper_utilities
command
Helper utilities for common use cases.
|
Helper utilities for common use cases. |
|
10_integration_test
command
|
|
Click to show internal directories.
Click to hide internal directories.