XU XUv0.16.0

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

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

counts: 11 functions, 8 methods, 9 types, 2 constants, 0 method sets

External package `gemini #github.com/xulang-org/packages/gemini`, 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_BASE_URL

XuAPI
pub const DEFAULT_BASE_URL = "https:

Purpose

Constant DEFAULT_BASE_URL, defining protocol or algorithm parameters.

struct Client

XuAPI
pub struct Client {
    pub base_url string
    pub api_key string
    pub timeout_ns int
    pub max_retries int
    pub extra_headers []string
}

Purpose

Gemini Client session maintaining connection and operations.

Public fields

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

struct Part

XuAPI
pub struct Part {
    pub kind string
    pub text string
    pub mime_type string
    pub data string
    pub name string
    pub args_json string
    pub response_json string
    pub thought bool
}

Purpose

Structure encapsulating kind, text, mime_type, data, name.

Public fields

kind string
kind tag
text string
text
mime_type string
field (string)
data string
data
name string
name
args_json string
field (string)
response_json string
field (string)
thought bool
field (bool)

struct Content

XuAPI
pub struct Content {
    pub role string
    pub parts []Part
}

Purpose

Structure encapsulating role, parts.

Public fields

role string
field (string)
parts []Part
parts

struct FunctionDecl

XuAPI
pub struct FunctionDecl {
    pub name string
    pub description string
    pub parameters_json string
}

Purpose

Structure encapsulating name, description, parameters_json.

Public fields

name string
name
description string
field (string)
parameters_json string
field (string)

struct GenerateRequest

XuAPI
pub struct GenerateRequest {
    pub model string
    pub system_instruction string
    pub contents []Content
    pub tools []FunctionDecl
    pub temperature f64
    pub has_temperature bool
    pub top_p f64
    pub has_top_p bool
    pub max_output_tokens int
    pub stop_sequences []string
    pub response_mime_type string
    pub response_schema_json string
    pub thinking_budget int
    pub safety_settings_json string
    pub extra_body_json string
}

Purpose

Structure encapsulating model, system_instruction, contents, tools, temperature.

Public fields

model string
field (string)
system_instruction string
field (string)
contents []Content
field ([]Content)
tools []FunctionDecl
field ([]FunctionDecl)
temperature f64
field (f64)
has_temperature bool
field (bool)
top_p f64
field (f64)
has_top_p bool
field (bool)
max_output_tokens int
field (int)
stop_sequences []string
field ([]string)
response_mime_type string
field (string)
response_schema_json string
field (string)
thinking_budget int
field (int)
safety_settings_json string
field (string)
extra_body_json string
field (string)

struct FunctionCall

XuAPI
pub struct FunctionCall {
    pub name string
    pub args_json string
}

Purpose

Structure encapsulating name, args_json.

Public fields

name string
name
args_json string
field (string)

struct Usage

XuAPI
pub struct Usage {
    pub prompt_token_count int
    pub candidates_token_count int
    pub total_token_count int
    pub thoughts_token_count int
}

Purpose

Structure encapsulating prompt_token_count, candidates_token_count, total_token_count, thoughts_token_count.

Public fields

prompt_token_count int
field (int)
candidates_token_count int
field (int)
total_token_count int
field (int)
thoughts_token_count int
field (int)

struct GenerateResponse

XuAPI
pub struct GenerateResponse {
    pub text string
    pub thoughts string
    pub function_calls []FunctionCall
    pub finish_reason string
    pub usage Usage
}

Purpose

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

Public fields

text string
text
thoughts string
field (string)
function_calls []FunctionCall
field ([]FunctionCall)
finish_reason string
field (string)
usage Usage
usage text

struct StreamChunk

XuAPI
pub struct StreamChunk {
    pub text_delta string
    pub thought_delta string
    pub function_calls []FunctionCall
    pub finish_reason string
    pub usage Usage
    pub done bool
}

Purpose

Structure encapsulating text_delta, thought_delta, function_calls, finish_reason, usage.

Public fields

text_delta string
field (string)
thought_delta string
field (string)
function_calls []FunctionCall
field ([]FunctionCall)
finish_reason string
field (string)
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_part

XuAPI
pub fn text_part(text string) Part

Purpose

Text part.

Parameters

text string
text (string)

Returns

Part — a value of this type

inline_data_part

XuAPI
pub fn inline_data_part(mime_type string, data_base64 string) Part

Purpose

Inline data part.

Parameters

mime_type string
mime_type (string)
data_base64 string
data_base64 (string)

Returns

Part — a value of this type

function_call_part

XuAPI
pub fn function_call_part(name string, args_json string) Part

Purpose

Function call part.

Parameters

name string
name (string)
args_json string
args_json (string)

Returns

Part — a value of this type

function_response_part

XuAPI
pub fn function_response_part(name string, response_json string) Part

Purpose

Function response part.

Parameters

name string
name (string)
response_json string
response_json (string)

Returns

Part — a value of this type

content

XuAPI
pub fn content(role string, parts []Part) Content

Purpose

Execute content.

Parameters

role string
role (string)
parts []Part
parts ([]Part)

Returns

Content — a value of this type

user_text

XuAPI
pub fn user_text(text string) Content

Purpose

User text.

Parameters

text string
text (string)

Returns

Content — a value of this type

model_text

XuAPI
pub fn model_text(text string) Content

Purpose

Model text.

Parameters

text string
text (string)

Returns

Content — a value of this type

function_decl

XuAPI
pub fn function_decl(name string, description string, parameters_json string) FunctionDecl

Purpose

Function decl.

Parameters

name string
name (string)
description string
description (string)
parameters_json string
parameters_json (string)

Returns

FunctionDecl — a value of this type

generate_request

XuAPI
pub fn generate_request(model string, contents []Content) GenerateRequest

Purpose

Generate request.

Parameters

model string
model (string)
contents []Content
contents ([]Content)

Returns

GenerateRequest — a value of this type

(&Client) generate

XuAPI
pub fn (c &Client) generate(req &GenerateRequest) GenerateResponse

Purpose

Execute generate 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 &GenerateRequest
req (read-only borrow; caller keeps the original; type &GenerateRequest)

Returns

GenerateResponse — a value of this type

(&Client) embed

XuAPI
pub fn (c &Client) embed(model string, text string) []f64

Purpose

Execute embed 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).
model string
model (string)
text string
text (string)

Returns

[]f64 — slice result

(&Client) batch_embed

XuAPI
pub fn (c &Client) batch_embed(model string, texts &[]string) [][]f64

Purpose

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

Parameters

c &Client
The Client instance used by this call (borrow).
model string
model (string)
texts &[]string
texts (read-only borrow; caller keeps the original; type &[]string)

Returns

[][]f64 — slice result

(&Client) generate_stream

XuAPI
pub fn (c &Client) generate_stream(req &GenerateRequest, on_chunk fn(StreamChunk) bool) GenerateResponse

Purpose

Operation on &Client: generate 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 &GenerateRequest
req (read-only borrow; caller keeps the original; type &GenerateRequest)
on_chunk fn(StreamChunk) bool
on_chunk (function value; type fn(StreamChunk) bool)

Returns

GenerateResponse — a value of this type

(&Client) generate_stream_chan

XuAPI
pub fn (c &Client) generate_stream_chan(req &GenerateRequest, ch chan StreamChunk) GenerateResponse

Purpose

Operation on &Client: generate 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 &GenerateRequest
req (read-only borrow; caller keeps the original; type &GenerateRequest)
ch chan StreamChunk
character code (channel; type chan StreamChunk)

Returns

GenerateResponse — a value of this type