XU XUv0.16.0

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

导入方式: openai #github.com/xulang-org/packages/openai

公开 API: 27 函数, 25 方法, 22 类型, 1 常量, 0 方法集

扩展包 `openai #github.com/xulang-org/packages/openai`,由模块 github.com/xulang-org/packages 提供。

github.com/xulang-org/packages · 1.17.2 · 安装与使用

const DEFAULT_TIMEOUT_NS

XuAPI
pub const DEFAULT_TIMEOUT_NS = 60000000000

用途

常量 DEFAULT_TIMEOUT_NS,定义了相关的协议或算法配置参数。

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
}

用途

Openai 客户端会话实例,维护与服务端的连接并提供操作接口。

公开字段

base_url string
字段(string)
api_key string
字段(string)
timeout_ns int
超时(纳秒)
max_retries int
字段(int)
extra_headers []string
字段([]string)

struct ToolCall

XuAPI
pub struct ToolCall {
    pub id string
    pub kind string
    pub name string
    pub arguments string
}

用途

承载 id、kind、name、arguments 等属性的结构体。

公开字段

id string
字段(string)
kind string
类型标签
name string
名字
arguments string
字段(string)

struct ContentPart

XuAPI
pub struct ContentPart {
    pub kind string
    pub text string
    pub image_url string
    pub detail string
}

用途

承载 kind、text、image_url、detail 等属性的结构体。

公开字段

kind string
类型标签
text string
文本
image_url string
字段(string)
detail string
字段(string)

struct Message

XuAPI
pub struct Message {
    pub role string
    pub content string
    pub parts []ContentPart
    pub tool_call_id string
    pub tool_calls []ToolCall
}

用途

承载 role、content、parts、tool_call_id、tool_calls 等属性的结构体。

公开字段

role string
字段(string)
content string
字段(string)
parts []ContentPart
各段
tool_call_id string
字段(string)
tool_calls []ToolCall
字段([]ToolCall)

struct ToolDef

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

用途

承载 name、description、parameters_json 等属性的结构体。

公开字段

name string
名字
description string
字段(string)
parameters_json string
字段(string)

struct ChatRequest

XuAPI
pub struct ChatRequest {
    pub model string
    pub messages []Message
    pub tools []ToolDef
    pub temperature f64
    pub has_temperature bool
    pub top_p f64
    pub has_top_p bool
    pub presence_penalty f64
    pub has_presence_penalty bool
    pub frequency_penalty f64
    pub has_frequency_penalty bool
    pub max_tokens int
    pub max_completion_tokens int
    pub seed int
    pub has_seed bool
    pub stop []string
    pub tool_choice string
    pub response_format_json string
    pub extra_body_json string
    pub include_usage bool
}

用途

承载 model、messages、tools、temperature、has_temperature 等属性的结构体。

公开字段

model string
字段(string)
messages []Message
字段([]Message)
tools []ToolDef
字段([]ToolDef)
temperature f64
字段(f64)
has_temperature bool
字段(bool)
top_p f64
字段(f64)
has_top_p bool
字段(bool)
presence_penalty f64
字段(f64)
has_presence_penalty bool
字段(bool)
frequency_penalty f64
字段(f64)
has_frequency_penalty bool
字段(bool)
max_tokens int
字段(int)
max_completion_tokens int
字段(int)
seed int
随机种子
has_seed bool
字段(bool)
stop []string
字段([]string)
tool_choice string
字段(string)
response_format_json string
字段(string)
extra_body_json string
字段(string)
include_usage bool
字段(bool)

struct CompletionRequest

XuAPI
pub struct CompletionRequest {
    pub model string
    pub prompt string
    pub temperature f64
    pub has_temperature bool
    pub top_p f64
    pub has_top_p bool
    pub max_tokens int
    pub seed int
    pub has_seed bool
    pub stop []string
    pub echo bool
    pub extra_body_json string
}

用途

承载 model、prompt、temperature、has_temperature、top_p 等属性的结构体。

公开字段

model string
字段(string)
prompt string
字段(string)
temperature f64
字段(f64)
has_temperature bool
字段(bool)
top_p f64
字段(f64)
has_top_p bool
字段(bool)
max_tokens int
字段(int)
seed int
随机种子
has_seed bool
字段(bool)
stop []string
字段([]string)
echo bool
字段(bool)
extra_body_json string
字段(string)

struct CompletionResponse

XuAPI
pub struct CompletionResponse {
    pub id string
    pub model string
    pub text string
    pub finish_reason string
    pub usage Usage
}

用途

Openai 服务端响应结果,包含状态码、响应头与正文数据。

公开字段

id string
字段(string)
model string
字段(string)
text string
文本
finish_reason string
字段(string)
usage Usage
用法说明

struct Usage

XuAPI
pub struct Usage {
    pub prompt_tokens int
    pub completion_tokens int
    pub total_tokens int
}

用途

承载 prompt_tokens、completion_tokens、total_tokens 等属性的结构体。

公开字段

prompt_tokens int
字段(int)
completion_tokens int
字段(int)
total_tokens int
字段(int)

struct ChatResponse

XuAPI
pub struct ChatResponse {
    pub id string
    pub model string
    pub content string
    pub reasoning_content string
    pub finish_reason string
    pub tool_calls []ToolCall
    pub usage Usage
}

用途

Openai 服务端响应结果,包含状态码、响应头与正文数据。

公开字段

id string
字段(string)
model string
字段(string)
content string
字段(string)
reasoning_content string
字段(string)
finish_reason string
字段(string)
tool_calls []ToolCall
字段([]ToolCall)
usage Usage
用法说明

struct StreamDelta

XuAPI
pub struct StreamDelta {
    pub content string
    pub reasoning_content string
    pub finish_reason string
    pub tool_calls []ToolCall
    pub has_usage bool
    pub usage Usage
    pub done bool
}

用途

承载 content、reasoning_content、finish_reason、tool_calls、has_usage 等属性的结构体。

公开字段

content string
字段(string)
reasoning_content string
字段(string)
finish_reason string
字段(string)
tool_calls []ToolCall
字段([]ToolCall)
has_usage bool
字段(bool)
usage Usage
用法说明
done bool
字段(bool)

struct EmbedRequest

XuAPI
pub struct EmbedRequest {
    pub model string
    pub inputs []string
}

用途

承载 model、inputs 等属性的结构体。

公开字段

model string
字段(string)
inputs []string
字段([]string)

struct EmbedResponse

XuAPI
pub struct EmbedResponse {
    pub model string
    pub embeddings [][]f64
    pub usage Usage
}

用途

Openai 服务端响应结果,包含状态码、响应头与正文数据。

公开字段

model string
字段(string)
embeddings [][]f64
字段([][]f64)
usage Usage
用法说明

struct ModelInfo

XuAPI
pub struct ModelInfo {
    pub id string
    pub object string
}

用途

承载 id、object 等属性的结构体。

公开字段

id string
字段(string)
object string
字段(string)

struct ResponsesToolCall

XuAPI
pub struct ResponsesToolCall {
    pub id string
    pub call_id string
    pub name string
    pub arguments string
}

用途

承载 id、call_id、name、arguments 等属性的结构体。

公开字段

id string
字段(string)
call_id string
字段(string)
name string
名字
arguments string
字段(string)

struct ResponsesRequest

XuAPI
pub struct ResponsesRequest {
    pub model string
    pub input string
    pub input_json string
    pub instructions string
    pub previous_response_id string
    pub tools []ToolDef
    pub temperature f64
    pub has_temperature bool
    pub top_p f64
    pub has_top_p bool
    pub max_output_tokens int
    pub tool_choice string
    pub extra_body_json string
}

用途

承载 model、input、input_json、instructions、previous_response_id 等属性的结构体。

公开字段

model string
字段(string)
input string
字段(string)
input_json string
字段(string)
instructions string
字段(string)
previous_response_id string
字段(string)
tools []ToolDef
字段([]ToolDef)
temperature f64
字段(f64)
has_temperature bool
字段(bool)
top_p f64
字段(f64)
has_top_p bool
字段(bool)
max_output_tokens int
字段(int)
tool_choice string
字段(string)
extra_body_json string
字段(string)

struct ResponsesResponse

XuAPI
pub struct ResponsesResponse {
    pub id string
    pub model string
    pub status string
    pub output_text string
    pub tool_calls []ResponsesToolCall
    pub usage Usage
}

用途

Openai 服务端响应结果,包含状态码、响应头与正文数据。

公开字段

id string
字段(string)
model string
字段(string)
status string
字段(string)
output_text string
字段(string)
tool_calls []ResponsesToolCall
字段([]ResponsesToolCall)
usage Usage
用法说明

struct ResponsesStreamEvent

XuAPI
pub struct ResponsesStreamEvent {
    pub event_type string
    pub text_delta string
    pub response_id string
    pub status string
    pub tool_calls []ResponsesToolCall
    pub has_usage bool
    pub usage Usage
    pub done bool
}

用途

承载 event_type、text_delta、response_id、status、tool_calls 等属性的结构体。

公开字段

event_type string
字段(string)
text_delta string
字段(string)
response_id string
字段(string)
status string
字段(string)
tool_calls []ResponsesToolCall
字段([]ResponsesToolCall)
has_usage bool
字段(bool)
usage Usage
用法说明
done bool
字段(bool)

struct ImageGenResult

XuAPI
pub struct ImageGenResult {
    pub url string
    pub b64_json string
    pub revised_prompt string
}

用途

承载 url、b64_json、revised_prompt 等属性的结构体。

公开字段

url string
字段(string)
b64_json string
字段(string)
revised_prompt string
字段(string)

struct RerankResult

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

用途

承载 index、relevance_score、document 等属性的结构体。

公开字段

index int
字段(int)
relevance_score f64
字段(f64)
document string
字段(string)

struct FileObject

XuAPI
pub struct FileObject {
    pub id string
    pub object string
    pub bytes int
    pub created_at int
    pub filename string
    pub purpose string
    pub status string
}

用途

承载 id、object、bytes、created_at、filename 等属性的结构体。

公开字段

id string
字段(string)
object string
字段(string)
bytes int
字段(int)
created_at int
字段(int)
filename string
字段(string)
purpose string
字段(string)
status string
字段(string)

struct BatchObject

XuAPI
pub struct BatchObject {
    pub id string
    pub object string
    pub endpoint string
    pub input_file_id string
    pub output_file_id string
    pub error_file_id string
    pub completion_window string
    pub status string
    pub created_at int
    pub request_total int
    pub request_completed int
    pub request_failed int
}

用途

承载 id、object、endpoint、input_file_id、output_file_id 等属性的结构体。

公开字段

id string
字段(string)
object string
字段(string)
endpoint string
字段(string)
input_file_id string
字段(string)
output_file_id string
字段(string)
error_file_id string
字段(string)
completion_window string
字段(string)
status string
字段(string)
created_at int
字段(int)
request_total int
字段(int)
request_completed int
字段(int)
request_failed int
字段(int)

new_client

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

用途

构造 client。

参数

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

返回值

Client — 该类型的值

new_deepseek_client

XuAPI
pub fn new_deepseek_client(api_key string) Client

用途

构造 deepseek client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_openrouter_client

XuAPI
pub fn new_openrouter_client(api_key string) Client

用途

构造 openrouter client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_groq_client

XuAPI
pub fn new_groq_client(api_key string) Client

用途

构造 groq client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_xai_client

XuAPI
pub fn new_xai_client(api_key string) Client

用途

构造 xai client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_together_client

XuAPI
pub fn new_together_client(api_key string) Client

用途

构造 together client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_fireworks_client

XuAPI
pub fn new_fireworks_client(api_key string) Client

用途

构造 fireworks client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_ollama_client

XuAPI
pub fn new_ollama_client(base_url string) Client

用途

构造 ollama client。

参数

base_url string
base_url(string)

返回值

Client — 该类型的值

new_cohere_client

XuAPI
pub fn new_cohere_client(api_key string) Client

用途

构造 cohere client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_qwen_client

XuAPI
pub fn new_qwen_client(api_key string) Client

用途

构造 qwen client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_mistral_client

XuAPI
pub fn new_mistral_client(api_key string) Client

用途

构造 mistral client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

new_minimax_client

XuAPI
pub fn new_minimax_client(api_key string) Client

用途

构造 minimax client。

参数

api_key string
api_key(string)

返回值

Client — 该类型的值

($&Client) set_max_retries

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

用途

$&Client 上的操作:设置 max retries。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

不返回值。

($&Client) add_header

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

用途

$&Client 上的操作:增加头。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string
名字(string)
value string
value(string)

返回值

不返回值。

(&Client) clone_client

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

用途

&Client 上的操作:拷贝客户端。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。

返回值

Client — 该类型的值

responses_input_text_item

XuAPI
pub fn responses_input_text_item(role string, text string) string

用途

执行 responses input text item 操作。

参数

role string
role(string)
text string
文本(string)

返回值

string — 结果字符串

responses_function_call_output_item

XuAPI
pub fn responses_function_call_output_item(call_id string, output string) string

用途

执行 responses function call output item 操作。

参数

call_id string
call_id(string)
output string
output(string)

返回值

string — 结果字符串

responses_input_array

XuAPI
pub fn responses_input_array(items &[]string) string

用途

执行 responses input array 操作。

参数

items &[]string
元素列表(只读借用,调用方仍持有原值;类型 &[]string)

返回值

string — 结果字符串

text_part

XuAPI
pub fn text_part(text string) ContentPart

用途

执行 text part 操作。

参数

text string
文本(string)

返回值

ContentPart — 该类型的值

image_url_part

XuAPI
pub fn image_url_part(url string, detail string) ContentPart

用途

执行 image url part 操作。

参数

url string
url(string)
detail string
detail(string)

返回值

ContentPart — 该类型的值

image_base64_part

XuAPI
pub fn image_base64_part(mime_type string, b64_data string, detail string) ContentPart

用途

执行 image base64 part 操作。

参数

mime_type string
mime_type(string)
b64_data string
b64_data(string)
detail string
detail(string)

返回值

ContentPart — 该类型的值

message

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

用途

执行 message 处理。

参数

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

返回值

Message — 该类型的值

message_parts

XuAPI
pub fn message_parts(role string, parts []ContentPart) Message

用途

执行 message parts 操作。

参数

role string
role(string)
parts []ContentPart
各段([]ContentPart)

返回值

Message — 该类型的值

tool_message

XuAPI
pub fn tool_message(tool_call_id string, content string) Message

用途

执行 tool message 操作。

参数

tool_call_id string
tool_call_id(string)
content string
content(string)

返回值

Message — 该类型的值

json_schema_format

XuAPI
pub fn json_schema_format(name string, schema_json string, strict bool) string

用途

执行 json schema format 操作。

参数

name string
名字(string)
schema_json string
schema_json(string)
strict bool
strict(bool)

返回值

string — 结果字符串

tool

XuAPI
pub fn tool(name string, description string, parameters_json string) ToolDef

用途

执行 tool 处理。

参数

name string
名字(string)
description string
description(string)
parameters_json string
parameters_json(string)

返回值

ToolDef — 该类型的值

chat_request

XuAPI
pub fn chat_request(model string, messages []Message) ChatRequest

用途

执行 chat request 操作。

参数

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

返回值

ChatRequest — 该类型的值

new_completion_request

XuAPI
pub fn new_completion_request(model string, prompt string) CompletionRequest

用途

构造 completion request。

参数

model string
model(string)
prompt string
prompt(string)

返回值

CompletionRequest — 该类型的值

embed_request

XuAPI
pub fn embed_request(model string, inputs []string) EmbedRequest

用途

执行 embed request 操作。

参数

model string
model(string)
inputs []string
inputs([]string)

返回值

EmbedRequest — 该类型的值

new_responses_request

XuAPI
pub fn new_responses_request(model string, input string) ResponsesRequest

用途

构造 responses request。

参数

model string
model(string)
input string
input(string)

返回值

ResponsesRequest — 该类型的值

(&Client) list_models

XuAPI
pub fn (c &Client) list_models() []ModelInfo

用途

&Client 上的操作:执行 list models 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。

返回值

[]ModelInfo — 切片结果

(&Client) chat

XuAPI
pub fn (c &Client) chat(req &ChatRequest) ChatResponse

用途

在 &Client 上执行 chat 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &ChatRequest
req(只读借用,调用方仍持有原值;类型 &ChatRequest)

返回值

ChatResponse — 该类型的值

(&Client) chat_stream

XuAPI
pub fn (c &Client) chat_stream(req &ChatRequest, on_delta fn(StreamDelta) bool) ChatResponse

用途

&Client 上的操作:执行 chat stream 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &ChatRequest
req(只读借用,调用方仍持有原值;类型 &ChatRequest)
on_delta fn(StreamDelta) bool
on_delta(函数值;类型 fn(StreamDelta) bool)

返回值

ChatResponse — 该类型的值

(&Client) chat_stream_chan

XuAPI
pub fn (c &Client) chat_stream_chan(req &ChatRequest, delta_ch chan StreamDelta) ChatResponse

用途

&Client 上的操作:执行 chat stream chan 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &ChatRequest
req(只读借用,调用方仍持有原值;类型 &ChatRequest)
delta_ch chan StreamDelta
delta_ch(通道;类型 chan StreamDelta)

返回值

ChatResponse — 该类型的值

(&Client) audio_transcriptions

XuAPI
pub fn (c &Client) audio_transcriptions(model string, filename string, audio_bytes &string, language string, prompt string) string

用途

&Client 上的操作:执行 audio transcriptions 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
model string
model(string)
filename string
filename(string)
audio_bytes &string
audio_bytes(只读借用,调用方仍持有原值;类型 &string)
language string
language(string)
prompt string
prompt(string)

返回值

string — 结果字符串

(&Client) audio_speech

XuAPI
pub fn (c &Client) audio_speech(model string, voice string, input string, response_format string) string

用途

&Client 上的操作:执行 audio speech 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
model string
model(string)
voice string
voice(string)
input string
input(string)
response_format string
response_format(string)

返回值

string — 结果字符串

(&Client) images_generate

XuAPI
pub fn (c &Client) images_generate(model string, prompt string, size string, n int) []ImageGenResult

用途

&Client 上的操作:执行 images generate 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
model string
model(string)
prompt string
prompt(string)
size string
size(string)
n int
数量、长度或上限(int)

返回值

[]ImageGenResult — 切片结果

(&Client) rerank

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

用途

在 &Client 上执行 rerank 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
model string
model(string)
query string
query(string)
documents &[]string
documents(只读借用,调用方仍持有原值;类型 &[]string)
top_n int
top_n(int)

返回值

[]RerankResult — 切片结果

(&Client) embeddings

XuAPI
pub fn (c &Client) embeddings(req &EmbedRequest) EmbedResponse

用途

在 &Client 上执行 embeddings 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &EmbedRequest
req(只读借用,调用方仍持有原值;类型 &EmbedRequest)

返回值

EmbedResponse — 该类型的值

(&Client) completions

XuAPI
pub fn (c &Client) completions(req &CompletionRequest) CompletionResponse

用途

在 &Client 上执行 completions 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &CompletionRequest
req(只读借用,调用方仍持有原值;类型 &CompletionRequest)

返回值

CompletionResponse — 该类型的值

(&Client) responses

XuAPI
pub fn (c &Client) responses(req &ResponsesRequest) ResponsesResponse

用途

在 &Client 上执行 responses 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &ResponsesRequest
req(只读借用,调用方仍持有原值;类型 &ResponsesRequest)

返回值

ResponsesResponse — 该类型的值

(&Client) responses_stream

XuAPI
pub fn (c &Client) responses_stream(req &ResponsesRequest, on_event fn(ResponsesStreamEvent) bool) ResponsesResponse

用途

&Client 上的操作:执行 responses stream 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &ResponsesRequest
req(只读借用,调用方仍持有原值;类型 &ResponsesRequest)
on_event fn(ResponsesStreamEvent) bool
on_event(函数值;类型 fn(ResponsesStreamEvent) bool)

返回值

ResponsesResponse — 该类型的值

(&Client) responses_stream_chan

XuAPI
pub fn (c &Client) responses_stream_chan(req &ResponsesRequest, ch chan ResponsesStreamEvent) ResponsesResponse

用途

&Client 上的操作:执行 responses stream chan 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
req &ResponsesRequest
req(只读借用,调用方仍持有原值;类型 &ResponsesRequest)
ch chan ResponsesStreamEvent
字符码(通道;类型 chan ResponsesStreamEvent)

返回值

ResponsesResponse — 该类型的值

(&Client) upload_file

XuAPI
pub fn (c &Client) upload_file(filename string, purpose string, content &string) FileObject

用途

&Client 上的操作:执行 upload file 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
filename string
filename(string)
purpose string
purpose(string)
content &string
content(只读借用,调用方仍持有原值;类型 &string)

返回值

FileObject — 该类型的值

(&Client) get_file

XuAPI
pub fn (c &Client) get_file(file_id string) FileObject

用途

&Client 上的操作:读取 file。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
file_id string
file_id(string)

返回值

FileObject — 该类型的值

(&Client) list_files

XuAPI
pub fn (c &Client) list_files(purpose string) []FileObject

用途

&Client 上的操作:执行 list files 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
purpose string
purpose(string)

返回值

[]FileObject — 切片结果

(&Client) delete_file

XuAPI
pub fn (c &Client) delete_file(file_id string) bool

用途

&Client 上的操作:删除文件。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
file_id string
file_id(string)

返回值

bool — 是否成立

(&Client) get_file_content

XuAPI
pub fn (c &Client) get_file_content(file_id string) string

用途

&Client 上的操作:读取 file content。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
file_id string
file_id(string)

返回值

string — 结果字符串

(&Client) create_batch

XuAPI
pub fn (c &Client) create_batch(input_file_id string, endpoint string, completion_window string, metadata_json string) BatchObject

用途

&Client 上的操作:执行 create batch 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
input_file_id string
input_file_id(string)
endpoint string
endpoint(string)
completion_window string
completion_window(string)
metadata_json string
metadata_json(string)

返回值

BatchObject — 该类型的值

(&Client) get_batch

XuAPI
pub fn (c &Client) get_batch(batch_id string) BatchObject

用途

&Client 上的操作:读取 batch。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
batch_id string
batch_id(string)

返回值

BatchObject — 该类型的值

(&Client) cancel_batch

XuAPI
pub fn (c &Client) cancel_batch(batch_id string) BatchObject

用途

&Client 上的操作:执行 cancel batch 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
batch_id string
batch_id(string)

返回值

BatchObject — 该类型的值

(&Client) list_batches

XuAPI
pub fn (c &Client) list_batches(limit int) []BatchObject

用途

&Client 上的操作:执行 list batches 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。
limit int
limit(int)

返回值

[]BatchObject — 切片结果