const DEFAULT_TIMEOUT_NS
pub const DEFAULT_TIMEOUT_NS = 60000000000Purpose
Constant DEFAULT_TIMEOUT_NS, defining protocol or algorithm parameters.
#github.com/xulang-org/packages/openaiExternal package `openai #github.com/xulang-org/packages/openai`, 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.
struct Clientpub struct Client {
pub base_url string
pub api_key string
pub timeout_ns int
pub max_retries int
pub extra_headers []string
}Openai Client session maintaining connection and operations.
base_url stringapi_key stringtimeout_ns intmax_retries intextra_headers []stringstruct ToolCallpub struct ToolCall {
pub id string
pub kind string
pub name string
pub arguments string
}Structure encapsulating id, kind, name, arguments.
id stringkind stringname stringarguments stringstruct ContentPartpub struct ContentPart {
pub kind string
pub text string
pub image_url string
pub detail string
}Structure encapsulating kind, text, image_url, detail.
kind stringtext stringimage_url stringdetail stringstruct Messagepub struct Message {
pub role string
pub content string
pub parts []ContentPart
pub tool_call_id string
pub tool_calls []ToolCall
}Structure encapsulating role, content, parts, tool_call_id, tool_calls.
role stringcontent stringparts []ContentParttool_call_id stringtool_calls []ToolCallstruct ToolDefpub struct ToolDef {
pub name string
pub description string
pub parameters_json string
}Structure encapsulating name, description, parameters_json.
name stringdescription stringparameters_json stringstruct ChatRequestpub 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
}Structure encapsulating model, messages, tools, temperature, has_temperature.
model stringmessages []Messagetools []ToolDeftemperature f64has_temperature booltop_p f64has_top_p boolpresence_penalty f64has_presence_penalty boolfrequency_penalty f64has_frequency_penalty boolmax_tokens intmax_completion_tokens intseed inthas_seed boolstop []stringtool_choice stringresponse_format_json stringextra_body_json stringinclude_usage boolstruct CompletionRequestpub 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
}Structure encapsulating model, prompt, temperature, has_temperature, top_p.
model stringprompt stringtemperature f64has_temperature booltop_p f64has_top_p boolmax_tokens intseed inthas_seed boolstop []stringecho boolextra_body_json stringstruct CompletionResponsepub struct CompletionResponse {
pub id string
pub model string
pub text string
pub finish_reason string
pub usage Usage
}Openai Server response payload containing status, headers, and body.
id stringmodel stringtext stringfinish_reason stringusage Usagestruct Usagepub struct Usage {
pub prompt_tokens int
pub completion_tokens int
pub total_tokens int
}Structure encapsulating prompt_tokens, completion_tokens, total_tokens.
prompt_tokens intcompletion_tokens inttotal_tokens intstruct ChatResponsepub 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 Server response payload containing status, headers, and body.
id stringmodel stringcontent stringreasoning_content stringfinish_reason stringtool_calls []ToolCallusage Usagestruct StreamDeltapub 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
}Structure encapsulating content, reasoning_content, finish_reason, tool_calls, has_usage.
content stringreasoning_content stringfinish_reason stringtool_calls []ToolCallhas_usage boolusage Usagedone boolstruct EmbedRequestpub struct EmbedRequest {
pub model string
pub inputs []string
}Structure encapsulating model, inputs.
model stringinputs []stringstruct EmbedResponsepub struct EmbedResponse {
pub model string
pub embeddings [][]f64
pub usage Usage
}Openai Server response payload containing status, headers, and body.
model stringembeddings [][]f64usage Usagestruct ModelInfopub struct ModelInfo {
pub id string
pub object string
}Structure encapsulating id, object.
id stringobject stringstruct ResponsesToolCallpub struct ResponsesToolCall {
pub id string
pub call_id string
pub name string
pub arguments string
}Structure encapsulating id, call_id, name, arguments.
id stringcall_id stringname stringarguments stringstruct ResponsesRequestpub 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
}Structure encapsulating model, input, input_json, instructions, previous_response_id.
model stringinput stringinput_json stringinstructions stringprevious_response_id stringtools []ToolDeftemperature f64has_temperature booltop_p f64has_top_p boolmax_output_tokens inttool_choice stringextra_body_json stringstruct ResponsesResponsepub struct ResponsesResponse {
pub id string
pub model string
pub status string
pub output_text string
pub tool_calls []ResponsesToolCall
pub usage Usage
}Openai Server response payload containing status, headers, and body.
id stringmodel stringstatus stringoutput_text stringtool_calls []ResponsesToolCallusage Usagestruct ResponsesStreamEventpub 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
}Structure encapsulating event_type, text_delta, response_id, status, tool_calls.
event_type stringtext_delta stringresponse_id stringstatus stringtool_calls []ResponsesToolCallhas_usage boolusage Usagedone boolstruct ImageGenResultpub struct ImageGenResult {
pub url string
pub b64_json string
pub revised_prompt string
}Structure encapsulating url, b64_json, revised_prompt.
url stringb64_json stringrevised_prompt stringstruct RerankResultpub struct RerankResult {
pub index int
pub relevance_score f64
pub document string
}Structure encapsulating index, relevance_score, document.
index intrelevance_score f64document stringstruct FileObjectpub struct FileObject {
pub id string
pub object string
pub bytes int
pub created_at int
pub filename string
pub purpose string
pub status string
}Structure encapsulating id, object, bytes, created_at, filename.
id stringobject stringbytes intcreated_at intfilename stringpurpose stringstatus stringstruct BatchObjectpub 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
}Structure encapsulating id, object, endpoint, input_file_id, output_file_id.
id stringobject stringendpoint stringinput_file_id stringoutput_file_id stringerror_file_id stringcompletion_window stringstatus stringcreated_at intrequest_total intrequest_completed intrequest_failed intnew_clientpub fn new_client(base_url string, api_key string) ClientConstruct client.
base_url stringapi_key stringClient — a value of this type
new_deepseek_clientpub fn new_deepseek_client(api_key string) ClientConstruct deepseek client.
api_key stringClient — a value of this type
new_openrouter_clientpub fn new_openrouter_client(api_key string) ClientConstruct openrouter client.
api_key stringClient — a value of this type
new_groq_clientpub fn new_groq_client(api_key string) ClientConstruct groq client.
api_key stringClient — a value of this type
new_xai_clientpub fn new_xai_client(api_key string) ClientConstruct xai client.
api_key stringClient — a value of this type
new_together_clientpub fn new_together_client(api_key string) ClientConstruct together client.
api_key stringClient — a value of this type
new_fireworks_clientpub fn new_fireworks_client(api_key string) ClientConstruct fireworks client.
api_key stringClient — a value of this type
new_ollama_clientpub fn new_ollama_client(base_url string) ClientConstruct ollama client.
base_url stringClient — a value of this type
new_cohere_clientpub fn new_cohere_client(api_key string) ClientConstruct cohere client.
api_key stringClient — a value of this type
new_qwen_clientpub fn new_qwen_client(api_key string) ClientConstruct qwen client.
api_key stringClient — a value of this type
new_mistral_clientpub fn new_mistral_client(api_key string) ClientConstruct mistral client.
api_key stringClient — a value of this type
new_minimax_clientpub fn new_minimax_client(api_key string) ClientConstruct minimax client.
api_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
responses_input_text_itempub fn responses_input_text_item(role string, text string) stringResponses input text item.
role stringtext stringstring — result string
responses_function_call_output_itempub fn responses_function_call_output_item(call_id string, output string) stringResponses function call output item.
call_id stringoutput stringstring — result string
responses_input_arraypub fn responses_input_array(items &[]string) stringResponses input array.
items &[]stringstring — result string
text_partpub fn text_part(text string) ContentPartText part.
text stringContentPart — a value of this type
image_url_partpub fn image_url_part(url string, detail string) ContentPartImage url part.
url stringdetail stringContentPart — a value of this type
image_base64_partpub fn image_base64_part(mime_type string, b64_data string, detail string) ContentPartImage base64 part.
mime_type stringb64_data stringdetail stringContentPart — a value of this type
messagepub fn message(role string, content string) MessageExecute message.
role stringcontent stringMessage — a value of this type
message_partspub fn message_parts(role string, parts []ContentPart) MessageMessage parts.
role stringparts []ContentPartMessage — a value of this type
tool_messagepub fn tool_message(tool_call_id string, content string) MessageTool message.
tool_call_id stringcontent stringMessage — a value of this type
json_schema_formatpub fn json_schema_format(name string, schema_json string, strict bool) stringJson schema format.
name stringschema_json stringstrict boolstring — result string
toolpub fn tool(name string, description string, parameters_json string) ToolDefExecute tool.
name stringdescription stringparameters_json stringToolDef — a value of this type
chat_requestpub fn chat_request(model string, messages []Message) ChatRequestChat request.
model stringmessages []MessageChatRequest — a value of this type
new_completion_requestpub fn new_completion_request(model string, prompt string) CompletionRequestConstruct completion request.
model stringprompt stringCompletionRequest — a value of this type
embed_requestpub fn embed_request(model string, inputs []string) EmbedRequestEmbed request.
model stringinputs []stringEmbedRequest — a value of this type
new_responses_requestpub fn new_responses_request(model string, input string) ResponsesRequestConstruct responses request.
model stringinput stringResponsesRequest — a value of this type
(&Client) list_modelspub fn (c &Client) list_models() []ModelInfoOperation on &Client: list models. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).[]ModelInfo — slice result
(&Client) chatpub fn (c &Client) chat(req &ChatRequest) ChatResponseExecute chat on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &ChatRequestChatResponse — a value of this type
(&Client) chat_streampub fn (c &Client) chat_stream(req &ChatRequest, on_delta fn(StreamDelta) bool) ChatResponseOperation on &Client: chat stream. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &ChatRequeston_delta fn(StreamDelta) boolChatResponse — a value of this type
(&Client) chat_stream_chanpub fn (c &Client) chat_stream_chan(req &ChatRequest, delta_ch chan StreamDelta) ChatResponseOperation on &Client: chat stream chan. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &ChatRequestdelta_ch chan StreamDeltaChatResponse — a value of this type
(&Client) audio_transcriptionspub fn (c &Client) audio_transcriptions(model string, filename string, audio_bytes &string, language string, prompt string) stringOperation on &Client: audio transcriptions. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).model stringfilename stringaudio_bytes &stringlanguage stringprompt stringstring — result string
(&Client) audio_speechpub fn (c &Client) audio_speech(model string, voice string, input string, response_format string) stringOperation on &Client: audio speech. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).model stringvoice stringinput stringresponse_format stringstring — result string
(&Client) images_generatepub fn (c &Client) images_generate(model string, prompt string, size string, n int) []ImageGenResultOperation on &Client: images generate. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).model stringprompt stringsize stringn int[]ImageGenResult — slice result
(&Client) rerankpub fn (c &Client) rerank(model string, query string, documents &[]string, top_n int) []RerankResultExecute rerank on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).model stringquery stringdocuments &[]stringtop_n int[]RerankResult — slice result
(&Client) embeddingspub fn (c &Client) embeddings(req &EmbedRequest) EmbedResponseExecute embeddings on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &EmbedRequestEmbedResponse — a value of this type
(&Client) completionspub fn (c &Client) completions(req &CompletionRequest) CompletionResponseExecute completions on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &CompletionRequestCompletionResponse — a value of this type
(&Client) responsespub fn (c &Client) responses(req &ResponsesRequest) ResponsesResponseExecute responses on &Client. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &ResponsesRequestResponsesResponse — a value of this type
(&Client) responses_streampub fn (c &Client) responses_stream(req &ResponsesRequest, on_event fn(ResponsesStreamEvent) bool) ResponsesResponseOperation on &Client: responses stream. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &ResponsesRequeston_event fn(ResponsesStreamEvent) boolResponsesResponse — a value of this type
(&Client) responses_stream_chanpub fn (c &Client) responses_stream_chan(req &ResponsesRequest, ch chan ResponsesStreamEvent) ResponsesResponseOperation on &Client: responses stream chan. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).req &ResponsesRequestch chan ResponsesStreamEventResponsesResponse — a value of this type
(&Client) upload_filepub fn (c &Client) upload_file(filename string, purpose string, content &string) FileObjectOperation on &Client: upload file. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).filename stringpurpose stringcontent &stringFileObject — a value of this type
(&Client) get_filepub fn (c &Client) get_file(file_id string) FileObjectOperation on &Client: read file. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).file_id stringFileObject — a value of this type
(&Client) list_filespub fn (c &Client) list_files(purpose string) []FileObjectOperation on &Client: list files. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).purpose string[]FileObject — slice result
(&Client) delete_filepub fn (c &Client) delete_file(file_id string) boolOperation on &Client: delete file. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).file_id stringbool — true or false
(&Client) get_file_contentpub fn (c &Client) get_file_content(file_id string) stringOperation on &Client: read file content. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).file_id stringstring — result string
(&Client) create_batchpub fn (c &Client) create_batch(input_file_id string, endpoint string, completion_window string, metadata_json string) BatchObjectOperation on &Client: create batch. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).input_file_id stringendpoint stringcompletion_window stringmetadata_json stringBatchObject — a value of this type
(&Client) get_batchpub fn (c &Client) get_batch(batch_id string) BatchObjectOperation on &Client: read batch. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).batch_id stringBatchObject — a value of this type
(&Client) cancel_batchpub fn (c &Client) cancel_batch(batch_id string) BatchObjectOperation on &Client: cancel batch. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).batch_id stringBatchObject — a value of this type
(&Client) list_batchespub fn (c &Client) list_batches(limit int) []BatchObjectOperation on &Client: list batches. Throws on failure; handle the error or propagate it to the caller.
c &ClientClient instance used by this call (borrow).limit int[]BatchObject — slice result