const DEFAULT_TIMEOUT_NS
pub const DEFAULT_TIMEOUT_NS = 60000000000用途
常量 DEFAULT_TIMEOUT_NS,定义了相关的协议或算法配置参数。
#github.com/xulang-org/packages/anthropic扩展包 `anthropic #github.com/xulang-org/packages/anthropic`,由模块 github.com/xulang-org/packages 提供。
github.com/xulang-org/packages · 1.17.2 · 安装与使用
const DEFAULT_TIMEOUT_NSpub const DEFAULT_TIMEOUT_NS = 60000000000常量 DEFAULT_TIMEOUT_NS,定义了相关的协议或算法配置参数。
const DEFAULT_VERSIONpub const DEFAULT_VERSION = "2023-06-01"常量 DEFAULT_VERSION,定义了相关的协议或算法配置参数。
struct Clientpub struct Client {
pub base_url string
pub api_key string
pub api_version string
pub timeout_ns int
pub max_retries int
pub extra_headers []string
}Anthropic 客户端会话实例,维护与服务端的连接并提供操作接口。
base_url stringapi_key stringapi_version stringtimeout_ns intmax_retries intextra_headers []stringstruct ContentBlockpub struct ContentBlock {
pub kind string
pub text string
pub thinking string
pub id string
pub name string
pub input_json string
pub media_type string
pub data string
pub cache_control string
}承载 kind、text、thinking、id、name 等属性的结构体。
kind stringtext stringthinking stringid stringname stringinput_json stringmedia_type stringdata stringcache_control stringstruct Messagepub struct Message {
pub role string
pub content string
pub blocks []ContentBlock
}承载 role、content、blocks 等属性的结构体。
role stringcontent stringblocks []ContentBlockstruct Toolpub struct Tool {
pub name string
pub description string
pub input_schema_json string
}承载 name、description、input_schema_json 等属性的结构体。
name stringdescription stringinput_schema_json stringstruct ToolUsepub struct ToolUse {
pub id string
pub name string
pub input_json string
}承载 id、name、input_json 等属性的结构体。
id stringname stringinput_json stringstruct Usagepub struct Usage {
pub input_tokens int
pub output_tokens int
pub cache_creation_input_tokens int
pub cache_read_input_tokens int
}承载 input_tokens、output_tokens、cache_creation_input_tokens、cache_read_input_tokens 等属性的结构体。
input_tokens intoutput_tokens intcache_creation_input_tokens intcache_read_input_tokens intstruct MessagesRequestpub struct MessagesRequest {
pub model string
pub system string
pub cache_system bool
pub messages []Message
pub tools []Tool
pub max_tokens int
pub temperature f64
pub has_temperature bool
pub top_p f64
pub has_top_p bool
pub stop_sequences []string
pub thinking_budget_tokens int
pub tool_choice_json string
pub extra_body_json string
}承载 model、system、cache_system、messages、tools 等属性的结构体。
model stringsystem stringcache_system boolmessages []Messagetools []Toolmax_tokens inttemperature f64has_temperature booltop_p f64has_top_p boolstop_sequences []stringthinking_budget_tokens inttool_choice_json stringextra_body_json stringstruct MessagesResponsepub struct MessagesResponse {
pub id string
pub model string
pub role string
pub stop_reason string
pub content string
pub thinking string
pub tool_uses []ToolUse
pub blocks []ContentBlock
pub usage Usage
}Anthropic 服务端响应结果,包含状态码、响应头与正文数据。
id stringmodel stringrole stringstop_reason stringcontent stringthinking stringtool_uses []ToolUseblocks []ContentBlockusage Usagestruct StreamEventpub struct StreamEvent {
pub event_type string
pub text_delta string
pub thinking_delta string
pub stop_reason string
pub tool_use ToolUse
pub has_tool_use bool
pub usage Usage
pub done bool
}承载 event_type、text_delta、thinking_delta、stop_reason、tool_use 等属性的结构体。
event_type stringtext_delta stringthinking_delta stringstop_reason stringtool_use ToolUsehas_tool_use boolusage Usagedone boolnew_clientpub fn new_client(api_key string) Client构造 client。
api_key stringClient — 该类型的值
new_client_with_basepub fn new_client_with_base(base_url string, api_key string) Client构造 client with base。
base_url stringapi_key stringClient — 该类型的值
($&Client) set_max_retriespub fn (c $&Client) set_max_retries(n int)$&Client 上的操作:设置 max retries。
c $&ClientClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。n int不返回值。
($&Client) add_headerpub fn (c $&Client) add_header(name string, value string)$&Client 上的操作:增加头。
c $&ClientClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。name stringvalue string不返回值。
(&Client) clone_clientpub fn (c &Client) clone_client() Client&Client 上的操作:拷贝客户端。
c &ClientClient 实例;以只读借用传入,调用方仍持有实例。Client — 该类型的值
text_blockpub fn text_block(text string) ContentBlock文本块。
text stringContentBlock — 该类型的值
image_base64_blockpub fn image_base64_block(media_type string, b64_data string) ContentBlock执行 image base64 block 操作。
media_type stringb64_data stringContentBlock — 该类型的值
image_url_blockpub fn image_url_block(url string) ContentBlock执行 image url block 操作。
url stringContentBlock — 该类型的值
messagepub fn message(role string, content string) Message执行 message 处理。
role stringcontent stringMessage — 该类型的值
message_blockspub fn message_blocks(role string, blocks []ContentBlock) Message执行 message blocks 操作。
role stringblocks []ContentBlockMessage — 该类型的值
tool_result_messagepub fn tool_result_message(tool_use_id string, content string, is_error bool) Message执行 tool result message 操作。
tool_use_id stringcontent stringis_error boolMessage — 该类型的值
toolpub fn tool(name string, description string, input_schema_json string) Tool执行 tool 处理。
name stringdescription stringinput_schema_json stringTool — 该类型的值
messages_requestpub fn messages_request(model string, messages []Message, max_tokens int) MessagesRequest执行 messages request 操作。
model stringmessages []Messagemax_tokens intMessagesRequest — 该类型的值
(&Client) messagespub fn (c &Client) messages(req &MessagesRequest) MessagesResponse在 &Client 上执行 messages 操作。失败时抛出错误,调用方需处理或继续传播。
c &ClientClient 实例;以只读借用传入,调用方仍持有实例。req &MessagesRequestMessagesResponse — 该类型的值
(&Client) messages_streampub fn (c &Client) messages_stream(req &MessagesRequest, on_event fn(StreamEvent) bool) MessagesResponse&Client 上的操作:执行 messages stream 操作。失败时抛出错误,调用方需处理或继续传播。
c &ClientClient 实例;以只读借用传入,调用方仍持有实例。req &MessagesRequeston_event fn(StreamEvent) boolMessagesResponse — 该类型的值
(&Client) messages_stream_chanpub fn (c &Client) messages_stream_chan(req &MessagesRequest, ch chan StreamEvent) MessagesResponse&Client 上的操作:执行 messages stream chan 操作。失败时抛出错误,调用方需处理或继续传播。
c &ClientClient 实例;以只读借用传入,调用方仍持有实例。req &MessagesRequestch chan StreamEventMessagesResponse — 该类型的值