XU XUv0.16.0

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

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

counts: 3 functions, 6 methods, 5 types, 2 constants, 0 method sets

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

Cohere 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 ChatMessage

XuAPI
pub struct ChatMessage {
    pub role string
    pub content string
}

Purpose

Structure encapsulating role, content.

Public fields

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

struct ChatResponse

XuAPI
pub struct ChatResponse {
    pub id string
    pub text string
    pub finish_reason string
    pub input_tokens int
    pub output_tokens int
}

Purpose

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

Public fields

id string
field (string)
text string
text
finish_reason string
field (string)
input_tokens int
field (int)
output_tokens int
field (int)

struct EmbedResponse

XuAPI
pub struct EmbedResponse {
    pub id string
    pub embeddings [][]f64
}

Purpose

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

Public fields

id string
field (string)
embeddings [][]f64
field ([][]f64)

struct RerankResult

XuAPI
pub struct RerankResult {
    pub index int
    pub relevance_score f64
    pub document string
}

Purpose

Structure encapsulating index, relevance_score, document.

Public fields

index int
field (int)
relevance_score f64
field (f64)
document string
field (string)

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

message

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

Purpose

Execute message.

Parameters

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

Returns

ChatMessage — a value of this type

(&Client) chat

XuAPI
pub fn (c &Client) chat(model string, messages &[]ChatMessage, max_tokens int, temperature f64) ChatResponse

Purpose

Execute chat 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)
messages &[]ChatMessage
messages (read-only borrow; caller keeps the original; type &[]ChatMessage)
max_tokens int
max_tokens (int)
temperature f64
temperature (f64)

Returns

ChatResponse — a value of this type

(&Client) embed

XuAPI
pub fn (c &Client) embed(model string, texts &[]string, input_type string) EmbedResponse

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)
texts &[]string
texts (read-only borrow; caller keeps the original; type &[]string)
input_type string
input_type (string)

Returns

EmbedResponse — a value of this type

(&Client) rerank

XuAPI
pub fn (c &Client) rerank(model string, query string, documents &[]string, top_n int) []RerankResult

Purpose

Execute rerank 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)
query string
query (string)
documents &[]string
documents (read-only borrow; caller keeps the original; type &[]string)
top_n int
top_n (int)

Returns

[]RerankResult — slice result