XU XUv0.16.0

#github.com/xulang-org/packages/anthropic

import: anthropic #github.com/xulang-org/packages/anthropic

counts: 10 functions, 6 methods, 9 types, 2 constants, 0 method sets

External package `anthropic #github.com/xulang-org/packages/anthropic`, provided by github.com/xulang-org/packages.

github.com/xulang-org/packages · 1.17.2 · Install and use

const DEFAULT_TIMEOUT_NS

XuAPI
pub const DEFAULT_TIMEOUT_NS = 60000000000

Purpose

Constant DEFAULT_TIMEOUT_NS, defining protocol or algorithm parameters.

const DEFAULT_VERSION

XuAPI
pub const DEFAULT_VERSION = "2023-06-01"

Purpose

Constant DEFAULT_VERSION, defining protocol or algorithm parameters.

struct Client

XuAPI
pub 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
}

Purpose

Anthropic Client session maintaining connection and operations.

Public fields

base_url string
field (string)
api_key string
field (string)
api_version string
field (string)
timeout_ns int
timeout in nanoseconds
max_retries int
field (int)
extra_headers []string
field ([]string)

struct ContentBlock

XuAPI
pub 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
}

Purpose

Structure encapsulating kind, text, thinking, id, name.

Public fields

kind string
kind tag
text string
text
thinking string
field (string)
id string
field (string)
name string
name
input_json string
field (string)
media_type string
field (string)
data string
data
cache_control string
field (string)

struct Message

XuAPI
pub struct Message {
    pub role string
    pub content string
    pub blocks []ContentBlock
}

Purpose

Structure encapsulating role, content, blocks.

Public fields

role string
field (string)
content string
field (string)
blocks []ContentBlock
field ([]ContentBlock)

struct Tool

XuAPI
pub struct Tool {
    pub name string
    pub description string
    pub input_schema_json string
}

Purpose

Structure encapsulating name, description, input_schema_json.

Public fields

name string
name
description string
field (string)
input_schema_json string
field (string)

struct ToolUse

XuAPI
pub struct ToolUse {
    pub id string
    pub name string
    pub input_json string
}

Purpose

Structure encapsulating id, name, input_json.

Public fields

id string
field (string)
name string
name
input_json string
field (string)

struct Usage

XuAPI
pub struct Usage {
    pub input_tokens int
    pub output_tokens int
    pub cache_creation_input_tokens int
    pub cache_read_input_tokens int
}

Purpose

Structure encapsulating input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens.

Public fields

input_tokens int
field (int)
output_tokens int
field (int)
cache_creation_input_tokens int
field (int)
cache_read_input_tokens int
field (int)

struct MessagesRequest

XuAPI
pub 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
}

Purpose

Structure encapsulating model, system, cache_system, messages, tools.

Public fields

model string
field (string)
system string
field (string)
cache_system bool
field (bool)
messages []Message
field ([]Message)
tools []Tool
field ([]Tool)
max_tokens int
field (int)
temperature f64
field (f64)
has_temperature bool
field (bool)
top_p f64
field (f64)
has_top_p bool
field (bool)
stop_sequences []string
field ([]string)
thinking_budget_tokens int
field (int)
tool_choice_json string
field (string)
extra_body_json string
field (string)

struct MessagesResponse

XuAPI
pub 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
}

Purpose

Anthropic Server response payload containing status, headers, and body.

Public fields

id string
field (string)
model string
field (string)
role string
field (string)
stop_reason string
field (string)
content string
field (string)
thinking string
field (string)
tool_uses []ToolUse
field ([]ToolUse)
blocks []ContentBlock
field ([]ContentBlock)
usage Usage
usage text

struct StreamEvent

XuAPI
pub 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
}

Purpose

Structure encapsulating event_type, text_delta, thinking_delta, stop_reason, tool_use.

Public fields

event_type string
field (string)
text_delta string
field (string)
thinking_delta string
field (string)
stop_reason string
field (string)
tool_use ToolUse
field (ToolUse)
has_tool_use bool
field (bool)
usage Usage
usage text
done bool
field (bool)

new_client

XuAPI
pub fn new_client(api_key string) Client

Purpose

Construct client.

Parameters

api_key string
api_key (string)

Returns

Client — a value of this type

new_client_with_base

XuAPI
pub fn new_client_with_base(base_url string, api_key string) Client

Purpose

Construct client with base.

Parameters

base_url string
base_url (string)
api_key string
api_key (string)

Returns

Client — a value of this type

($&Client) set_max_retries

XuAPI
pub fn (c $&Client) set_max_retries(n int)

Purpose

Operation on $&Client: set max retries.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

This call does not return a value.

($&Client) add_header

XuAPI
pub fn (c $&Client) add_header(name string, value string)

Purpose

Operation on $&Client: add header.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
name string
name (string)
value string
value (string)

Returns

This call does not return a value.

(&Client) clone_client

XuAPI
pub fn (c &Client) clone_client() Client

Purpose

Operation on &Client: clone client.

Parameters

c &Client
The Client instance used by this call (borrow).

Returns

Client — a value of this type

text_block

XuAPI
pub fn text_block(text string) ContentBlock

Purpose

Text block.

Parameters

text string
text (string)

Returns

ContentBlock — a value of this type

image_base64_block

XuAPI
pub fn image_base64_block(media_type string, b64_data string) ContentBlock

Purpose

Image base64 block.

Parameters

media_type string
media_type (string)
b64_data string
b64_data (string)

Returns

ContentBlock — a value of this type

image_url_block

XuAPI
pub fn image_url_block(url string) ContentBlock

Purpose

Image url block.

Parameters

url string
url (string)

Returns

ContentBlock — a value of this type

message

XuAPI
pub fn message(role string, content string) Message

Purpose

Execute message.

Parameters

role string
role (string)
content string
content (string)

Returns

Message — a value of this type

message_blocks

XuAPI
pub fn message_blocks(role string, blocks []ContentBlock) Message

Purpose

Message blocks.

Parameters

role string
role (string)
blocks []ContentBlock
blocks ([]ContentBlock)

Returns

Message — a value of this type

tool_result_message

XuAPI
pub fn tool_result_message(tool_use_id string, content string, is_error bool) Message

Purpose

Tool result message.

Parameters

tool_use_id string
tool_use_id (string)
content string
content (string)
is_error bool
is_error (bool)

Returns

Message — a value of this type

tool

XuAPI
pub fn tool(name string, description string, input_schema_json string) Tool

Purpose

Execute tool.

Parameters

name string
name (string)
description string
description (string)
input_schema_json string
input_schema_json (string)

Returns

Tool — a value of this type

messages_request

XuAPI
pub fn messages_request(model string, messages []Message, max_tokens int) MessagesRequest

Purpose

Messages request.

Parameters

model string
model (string)
messages []Message
messages ([]Message)
max_tokens int
max_tokens (int)

Returns

MessagesRequest — a value of this type

(&Client) messages

XuAPI
pub fn (c &Client) messages(req &MessagesRequest) MessagesResponse

Purpose

Execute messages on &Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Client
The Client instance used by this call (borrow).
req &MessagesRequest
req (read-only borrow; caller keeps the original; type &MessagesRequest)

Returns

MessagesResponse — a value of this type

(&Client) messages_stream

XuAPI
pub fn (c &Client) messages_stream(req &MessagesRequest, on_event fn(StreamEvent) bool) MessagesResponse

Purpose

Operation on &Client: messages stream. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Client
The Client instance used by this call (borrow).
req &MessagesRequest
req (read-only borrow; caller keeps the original; type &MessagesRequest)
on_event fn(StreamEvent) bool
on_event (function value; type fn(StreamEvent) bool)

Returns

MessagesResponse — a value of this type

(&Client) messages_stream_chan

XuAPI
pub fn (c &Client) messages_stream_chan(req &MessagesRequest, ch chan StreamEvent) MessagesResponse

Purpose

Operation on &Client: messages stream chan. Throws on failure; handle the error or propagate it to the caller.

Parameters

c &Client
The Client instance used by this call (borrow).
req &MessagesRequest
req (read-only borrow; caller keeps the original; type &MessagesRequest)
ch chan StreamEvent
character code (channel; type chan StreamEvent)

Returns

MessagesResponse — a value of this type