const DEFAULT_TIMEOUT_NS
pub const DEFAULT_TIMEOUT_NS = 60000000000用途
常量 DEFAULT_TIMEOUT_NS,定义了相关的协议或算法配置参数。
#github.com/xulang-org/packages/cohere扩展包 `cohere #github.com/xulang-org/packages/cohere`,由模块 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_BASE_URLpub const DEFAULT_BASE_URL = "https:常量 DEFAULT_BASE_URL,定义了相关的协议或算法配置参数。
struct Clientpub struct Client {
pub base_url string
pub api_key string
pub timeout_ns int
pub max_retries int
pub extra_headers []string
}Cohere 客户端会话实例,维护与服务端的连接并提供操作接口。
base_url stringapi_key stringtimeout_ns intmax_retries intextra_headers []stringstruct ChatMessagepub struct ChatMessage {
pub role string
pub content string
}承载 role、content 等属性的结构体。
role stringcontent stringstruct ChatResponsepub struct ChatResponse {
pub id string
pub text string
pub finish_reason string
pub input_tokens int
pub output_tokens int
}Cohere 服务端响应结果,包含状态码、响应头与正文数据。
id stringtext stringfinish_reason stringinput_tokens intoutput_tokens intstruct EmbedResponsepub struct EmbedResponse {
pub id string
pub embeddings [][]f64
}Cohere 服务端响应结果,包含状态码、响应头与正文数据。
id stringembeddings [][]f64struct RerankResultpub struct RerankResult {
pub index int
pub relevance_score f64
pub document string
}承载 index、relevance_score、document 等属性的结构体。
index intrelevance_score f64document stringnew_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 — 该类型的值
messagepub fn message(role string, content string) ChatMessage执行 message 处理。
role stringcontent stringChatMessage — 该类型的值
(&Client) chatpub fn (c &Client) chat(model string, messages &[]ChatMessage, max_tokens int, temperature f64) ChatResponse在 &Client 上执行 chat 操作。失败时抛出错误,调用方需处理或继续传播。
c &ClientClient 实例;以只读借用传入,调用方仍持有实例。model stringmessages &[]ChatMessagemax_tokens inttemperature f64ChatResponse — 该类型的值
(&Client) embedpub fn (c &Client) embed(model string, texts &[]string, input_type string) EmbedResponse在 &Client 上执行 embed 操作。失败时抛出错误,调用方需处理或继续传播。
c &ClientClient 实例;以只读借用传入,调用方仍持有实例。model stringtexts &[]stringinput_type stringEmbedResponse — 该类型的值
(&Client) rerankpub fn (c &Client) rerank(model string, query string, documents &[]string, top_n int) []RerankResult在 &Client 上执行 rerank 操作。失败时抛出错误,调用方需处理或继续传播。
c &ClientClient 实例;以只读借用传入,调用方仍持有实例。model stringquery stringdocuments &[]stringtop_n int[]RerankResult — 切片结果