pub struct ChatResponse {
pub id: String,
pub model: String,
pub choices: Vec<ChatChoice>,
pub usage: UsageBlock,
}Expand description
The top-level response from a chat/completions call.
Why: wraps the choices array and usage so callers receive one typed value
from super::super::adapter::InferenceAdapter::chat.
What: id is the provider response id; model is the RESOLVED model slug the
provider actually served (may differ from the request under routing/fallback);
choices holds the generated turns; usage is the normalized Usage
(parsed from the wire UsageBlock).
Test: deserialises_text_fixture, usage_flows_through.
Fields§
§id: StringOpaque provider response identifier.
model: StringResolved model slug the provider actually used. Empty when the response
omits it — use Self::resolved_model rather than this field directly.
choices: Vec<ChatChoice>Generated choices (one per n; we always request n = 1).
usage: UsageBlockToken + cost accounting for this call.
Implementations§
Source§impl ChatResponse
impl ChatResponse
Sourcepub fn first_text(&self) -> Option<String>
pub fn first_text(&self) -> Option<String>
The first choice’s text content, if any.
Why: most calls want the assistant’s text; this avoids repetitive
indexing at every call site.
What: choices[0].message.content, or None when absent.
Test: deserialises_text_fixture, first_text_empty_choices.
Sourcepub fn first_tool_calls(&self) -> &[ToolCall]
pub fn first_tool_calls(&self) -> &[ToolCall]
The first choice’s tool calls.
Why: tool-call workflows need the emitted calls without nested indexing.
What: choices[0].message.tool_calls, or an empty slice.
Test: deserialises_tool_call.
Sourcepub fn stop_reason(&self) -> Option<StopReason>
pub fn stop_reason(&self) -> Option<StopReason>
The typed stop reason from the first choice.
Why: callers decide whether to continue the tool loop or surface the
response; the typed enum is safer than string comparison.
What: parses choices[0].finish_reason via StopReason::from_wire;
None when there is no choice or no finish reason.
Test: stop_reason_maps_variants.
Sourcepub fn usage(&self) -> Usage
pub fn usage(&self) -> Usage
The normalized Usage for this call.
Why: callers speak Usage, not the wire UsageBlock.
What: clones and converts self.usage via UsageBlock::into_usage.
Test: usage_flows_through.
Sourcepub fn resolved_model<'a>(&'a self, requested: &'a str) -> &'a str
pub fn resolved_model<'a>(&'a self, requested: &'a str) -> &'a str
The model slug to attribute this turn to: the resolved model the provider reports, falling back to the requested slug when the response omits one.
Why: recorders/pricing must attribute what the provider actually ran, not
merely what was asked — a routing/fallback slug can resolve differently.
What: &self.model when non-empty, else requested.
Test: resolved_model_prefers_response_then_requested.
Trait Implementations§
Source§impl Clone for ChatResponse
impl Clone for ChatResponse
Source§fn clone(&self) -> ChatResponse
fn clone(&self) -> ChatResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChatResponse
impl Debug for ChatResponse
Source§impl<'de> Deserialize<'de> for ChatResponse
impl<'de> Deserialize<'de> for ChatResponse
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatResponse, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ChatResponse, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for ChatResponse
impl Serialize for ChatResponse
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for ChatResponse
impl RefUnwindSafe for ChatResponse
impl Send for ChatResponse
impl Sync for ChatResponse
impl Unpin for ChatResponse
impl UnsafeUnpin for ChatResponse
impl UnwindSafe for ChatResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more