const DEFAULT_TIMEOUT_NS
pub const DEFAULT_TIMEOUT_NS = 60000000000Purpose
Constant DEFAULT_TIMEOUT_NS, defining protocol or algorithm parameters.
#github.com/xulang-org/packages/geminiExternal 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_NSpub const DEFAULT_TIMEOUT_NS = 60000000000Constant DEFAULT_TIMEOUT_NS, defining protocol or algorithm parameters.
const DEFAULT_BASE_URLpub const DEFAULT_BASE_URL = "https:Constant DEFAULT_BASE_URL, defining protocol or algorithm parameters.
struct Clientpub struct Client {
pub base_url string
pub api_key string
pub timeout_ns int
pub max_retries int
pub extra_headers []string
}Gemini Client session maintaining connection and operations.
base_url stringapi_key stringtimeout_ns intmax_retries intextra_headers []stringstruct Partpub 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
}Structure encapsulating kind, text, mime_type, data, name.
kind stringtext stringmime_type stringdata stringname stringargs_json stringresponse_json stringthought boolstruct Contentpub struct Content {
pub role string
pub parts []Part
}Structure encapsulating role, parts.
role stringparts []Partstruct FunctionDeclpub struct FunctionDecl {
pub name string
pub description string
pub parameters_json string
}Structure encapsulating name, description, parameters_json.
name stringdescription stringparameters_json stringstruct GenerateRequestpub 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
}Structure encapsulating model, system_instruction, contents, tools, temperature.
model stringsystem_instruction stringcontents []Contenttools []FunctionDecltemperature f64has_temperature booltop_p f64has_top_p boolmax_output_tokens intstop_sequences []stringresponse_mime_type stringresponse_schema_json stringthinking_budget intsafety_settings_json stringextra_body_json stringstruct FunctionCallpub struct FunctionCall {
pub name string
pub args_json string
}Structure encapsulating name, args_json.
name stringargs_json stringstruct Usagepub struct Usage {
pub prompt_token_count int
pub candidates_token_count int
pub total_token_count int
pub thoughts_token_count int
}Structure encapsulating prompt_token_count, candidates_token_count, total_token_count, thoughts_token_count.
prompt_token_count intcandidates_token_count inttotal_token_count intthoughts_token_count intstruct GenerateResponsepub struct GenerateResponse {
pub text string
pub thoughts string
pub function_calls []FunctionCall
pub finish_reason string
pub usage Usage
}Gemini Server response payload containing status, headers, and body.
text stringthoughts stringfunction_calls []FunctionCallfinish_reason stringusage Usagestruct StreamChunkpub struct StreamChunk {
pub text_delta string
pub thought_delta string
pub function_calls []FunctionCall
pub finish_reason string
pub usage Usage
pub done bool
}Structure encapsulating text_delta, thought_delta, function_calls, finish_reason, usage.
text_delta stringthought_delta stringfunction_calls []FunctionCallfinish_reason stringusage Usagedone boolnew_clientpub fn new_client(api_key string) ClientConstruct client.
api_key stringClient — a value of this type
new_client_with_basepub fn new_client_with_base(base_url string, api_key string) ClientConstruct client with base.
base_url stringapi_key stringClient — a value of this type
($&Client) set_max_retriespub fn (c $&Client) set_max_retries(n int)Operation on $&Client: set max retries.
c $&ClientClient instance used by this call (exclusive borrow).n intThis call does not return a value.
($&Client) add_headerpub fn (c $&Client) add_header(name string, value string)Operation on $&Client: add header.
c $&ClientClient instance used by this call (exclusive borrow).name stringvalue stringThis call does not return a value.
(&Client) clone_clientpub fn (c &Client) clone_client() ClientOperation on &Client: clone client.
c &ClientClient instance used by this call (borrow).Client — a value of this type
text_partpub fn text_part(text string) PartText part.
text stringPart — a value of this type
inline_data_partpub fn inline_data_part(mime_type string, data_base64 string) PartInline data part.
mime_type stringdata_base64 stringPart — a value of this type
function_call_partpub fn function_call_part(name string, args_json string) PartFunction call part.
name stringargs_json stringPart — a value of this type
function_response_partpub fn function_response_part(name string, response_json string) PartFunction response part.
name stringresponse_json stringPart — a value of this type
contentpub fn content(role string, parts []Part) ContentExecute content.
role stringparts []PartContent — a value of this type
user_textpub fn user_text(text string) ContentUser text.
text stringContent — a value of this type
model_textpub fn model_text(text string) ContentModel text.
text stringContent — a value of this type
function_declpub fn function_decl(name string, description string, parameters_json string) FunctionDeclFunction decl.
name stringdescription stringparameters_json stringFunctionDecl — a value of this type
generate_requestpub fn generate_request(model string, contents []Content) GenerateRequestGenerate request.
model stringcontents []ContentGenerateRequest — a value of this type
(&Client) generatepub fn (c &Client) generate(req &GenerateRequest) GenerateResponseExecute generate on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &GenerateRequestGenerateResponse — a value of this type
(&Client) embedpub fn (c &Client) embed(model string, text string) []f64Execute embed on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).model stringtext string[]f64 — slice result
(&Client) batch_embedpub fn (c &Client) batch_embed(model string, texts &[]string) [][]f64Operation on &Client: batch embed. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).model stringtexts &[]string[][]f64 — slice result
(&Client) generate_streampub fn (c &Client) generate_stream(req &GenerateRequest, on_chunk fn(StreamChunk) bool) GenerateResponseOperation on &Client: generate stream. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &GenerateRequeston_chunk fn(StreamChunk) boolGenerateResponse — a value of this type
(&Client) generate_stream_chanpub fn (c &Client) generate_stream_chan(req &GenerateRequest, ch chan StreamChunk) GenerateResponseOperation on &Client: generate stream chan. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &GenerateRequestch chan StreamChunkGenerateResponse — a value of this type