pub struct ChatRequestBuilder { /* private fields */ }client or blocking only.Expand description
Builder for LLM proxy chat requests (async + streaming).
Implementations§
Source§impl ChatRequestBuilder
impl ChatRequestBuilder
Sourcepub fn message(self, role: MessageRole, content: impl Into<String>) -> Self
pub fn message(self, role: MessageRole, content: impl Into<String>) -> Self
Add a message with the given role and content.
Sourcepub fn messages(self, messages: Vec<ProxyMessage>) -> Self
pub fn messages(self, messages: Vec<ProxyMessage>) -> Self
Set the full message list, replacing any existing messages.
Sourcepub fn max_tokens(self, max_tokens: i64) -> Self
pub fn max_tokens(self, max_tokens: i64) -> Self
Set the maximum number of tokens to generate.
Sourcepub fn temperature(self, temperature: f64) -> Self
pub fn temperature(self, temperature: f64) -> Self
Set the sampling temperature.
Sourcepub fn metadata_entry(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn metadata_entry( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add a single metadata entry. Empty keys or values are ignored.
Sourcepub fn response_format(self, response_format: ResponseFormat) -> Self
pub fn response_format(self, response_format: ResponseFormat) -> Self
Set the response format (e.g., JSON schema for structured outputs).
Sourcepub fn tool_choice(self, tool_choice: ToolChoice) -> Self
pub fn tool_choice(self, tool_choice: ToolChoice) -> Self
Set the tool choice strategy.
Sourcepub fn request_id(self, request_id: impl Into<String>) -> Self
pub fn request_id(self, request_id: impl Into<String>) -> Self
Set a request ID for tracing.
Sourcepub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self
Add a custom header to the request.
Sourcepub fn retry(self, retry: RetryConfig) -> Self
pub fn retry(self, retry: RetryConfig) -> Self
Set retry configuration.
Source§impl ChatRequestBuilder
impl ChatRequestBuilder
Sourcepub fn new(model: impl Into<Model>) -> Self
pub fn new(model: impl Into<Model>) -> Self
Create a new chat request builder for the given model.
pub fn build_request(&self) -> Result<ProxyRequest, Error>
Sourcepub async fn send(self, client: &LLMClient) -> Result<ProxyResponse, Error>
Available on crate feature client only.
pub async fn send(self, client: &LLMClient) -> Result<ProxyResponse, Error>
client only.Execute the chat request (non-streaming, async).
Sourcepub async fn stream(self, client: &LLMClient) -> Result<StreamHandle, Error>
Available on crate features client and streaming only.
pub async fn stream(self, client: &LLMClient) -> Result<StreamHandle, Error>
client and streaming only.Execute the chat request and stream responses (async).
Sourcepub async fn stream_deltas(
self,
client: &LLMClient,
) -> Result<Pin<Box<dyn Stream<Item = Result<String, Error>> + Send>>, Error>
Available on crate features client and streaming only.
pub async fn stream_deltas( self, client: &LLMClient, ) -> Result<Pin<Box<dyn Stream<Item = Result<String, Error>> + Send>>, Error>
client and streaming only.Execute the chat request and stream text deltas (async).
Sourcepub fn structured<T>(self) -> StructuredChatBuilder<T>where
T: JsonSchema + DeserializeOwned,
Available on crate feature client only.
pub fn structured<T>(self) -> StructuredChatBuilder<T>where
T: JsonSchema + DeserializeOwned,
client only.Create a structured output builder with automatic schema generation.
This method transitions the builder to a [StructuredChatBuilder] that
automatically generates a JSON schema from the type T and handles
validation retries.
§Example
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
struct Person {
name: String,
age: u32,
}
let result = client.chat()
.model("claude-sonnet-4-20250514")
.user("Extract: John Doe, 30 years old")
.structured::<Person>()
.max_retries(2)
.send()
.await?;Sourcepub async fn stream_json<T>(
self,
client: &LLMClient,
) -> Result<StructuredJSONStream<T>, Error>where
T: DeserializeOwned,
Available on crate features client and streaming only.
pub async fn stream_json<T>(
self,
client: &LLMClient,
) -> Result<StructuredJSONStream<T>, Error>where
T: DeserializeOwned,
client and streaming only.Execute the chat request and stream structured JSON payloads (async).
The request must include a structured response_format (type=json_schema), and uses NDJSON framing per the /llm/proxy structured streaming contract.
Trait Implementations§
Source§impl Clone for ChatRequestBuilder
impl Clone for ChatRequestBuilder
Source§fn clone(&self) -> ChatRequestBuilder
fn clone(&self) -> ChatRequestBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more