pub struct ApiRequest { /* private fields */ }Expand description
A safe, chainable request builder that wraps ChatCompletionRequest.
Use with_model to set an arbitrary model string,
or the convenience constructors deepseek_chat
and deepseek_reasoner for the standard
DeepSeek models.
Implementations§
Source§impl ApiRequest
impl ApiRequest
Sourcepub fn with_model(self, name: impl Into<String>) -> Self
pub fn with_model(self, name: impl Into<String>) -> Self
Set the model by string (builder-style).
Accepts any model identifier — a named DeepSeek model or any OpenAI-compatible model string:
use ds_api::ApiRequest;
let req = ApiRequest::builder().with_model("deepseek-chat");
let req = ApiRequest::builder().with_model("gpt-4o");Sourcepub fn deepseek_chat(messages: Vec<Message>) -> Self
pub fn deepseek_chat(messages: Vec<Message>) -> Self
Convenience constructor: deepseek-chat + messages
Sourcepub fn deepseek_reasoner(messages: Vec<Message>) -> Self
pub fn deepseek_reasoner(messages: Vec<Message>) -> Self
Convenience constructor: deepseek-reasoner + messages
Sourcepub fn add_message(self, msg: Message) -> Self
pub fn add_message(self, msg: Message) -> Self
Add a message to the request.
Sourcepub fn temperature(self, t: f32) -> Self
pub fn temperature(self, t: f32) -> Self
Set temperature.
Sourcepub fn max_tokens(self, n: u32) -> Self
pub fn max_tokens(self, n: u32) -> Self
Set max tokens.
Sourcepub fn tool_choice_auto(self) -> Self
pub fn tool_choice_auto(self) -> Self
Set tool choice to Auto.
Sourcepub fn extra_body(self, map: Map<String, Value>) -> Self
pub fn extra_body(self, map: Map<String, Value>) -> Self
Merge arbitrary top-level JSON into the request body.
Pass a serde_json::Map<String, serde_json::Value> of key/value pairs which
will be flattened into the top-level request JSON via the raw request’s
extra_body field.
Sourcepub fn add_extra_field(&mut self, key: impl Into<String>, value: Value)
pub fn add_extra_field(&mut self, key: impl Into<String>, value: Value)
Add a single extra top-level field to the request body (in-place).
This method mutates the internal ChatCompletionRequest’s extra_body
map, creating it if necessary, and inserts the provided key/value
pair. Values in extra_body are flattened into the top-level request
JSON when serialised due to #[serde(flatten)], so they appear as peers
to fields such as messages and model.
Use this when you hold a mutable ApiRequest and want to add
provider-specific or experimental top-level fields without constructing a
full Map first.
Example:
let mut req = ApiRequest::builder();
req.add_extra_field("x_flag", json!(true));Sourcepub fn with_extra_field(self, key: impl Into<String>, value: Value) -> Self
pub fn with_extra_field(self, key: impl Into<String>, value: Value) -> Self
Builder-style helper that consumes the ApiRequest, adds an extra field,
and returns the modified request for chaining.
This is convenient for fluent construction:
let req = ApiRequest::builder()
.with_extra_field("provider_opt", json!("x"))
.with_model("deepseek-chat");Sourcepub fn extra_field(self, key: impl Into<String>, value: Value) -> Self
pub fn extra_field(self, key: impl Into<String>, value: Value) -> Self
Compatibility alias for the single-field helper (builder-style).
Historically the builder exposed extra_field(...). This method is kept
as an alias for compatibility but prefer with_extra_field or
add_extra_field for clearer intent.