pub enum FinishReason {
Stop,
ToolUse,
Truncated {
reason: Option<String>,
},
Other(String),
}Expand description
Semantic finish reason, replacing scattered Option<String> matching.
Each variant captures a distinct end-of-turn signal from the LLM provider.
Conversion helpers (FinishReason::from_openai, FinishReason::from_anthropic,
FinishReason::from_responses) normalise the provider-specific strings.
Variants§
Stop
Model finished naturally (OpenAI "stop" / Anthropic "end_turn").
ToolUse
Model requested tool calls (Anthropic "tool_use").
OpenAI’s "tool_calls" is consumed at the client layer as
StreamChunk::ToolCall and never reaches the react loop.
Truncated
Output was truncated by the token limit.
- OpenAI:
"length" - Anthropic:
"max_tokens" - Responses API:
"incomplete"
Other(String)
Any other / unknown finish reason.
Implementations§
Source§impl FinishReason
impl FinishReason
Sourcepub fn from_openai(s: Option<&str>) -> Self
pub fn from_openai(s: Option<&str>) -> Self
Normalise an OpenAI Chat Completions finish_reason value.
Sourcepub fn from_anthropic(s: Option<&str>) -> Self
pub fn from_anthropic(s: Option<&str>) -> Self
Normalise an Anthropic stop_reason value.
Sourcepub fn from_responses(reason: Option<&str>) -> Self
pub fn from_responses(reason: Option<&str>) -> Self
Normalise an OpenAI Responses API status / incomplete reason.
Sourcepub fn from_raw(s: Option<&str>) -> Self
pub fn from_raw(s: Option<&str>) -> Self
Unified conversion when the provider is unknown at compile time.
Handles the union of OpenAI Chat and Anthropic stop-reason strings,
as well as the Responses API "incomplete:reason" format.
OpenAI "tool_calls" is consumed client-side and never reaches here,
so it is not matched.
Sourcepub fn is_truncated(&self) -> bool
pub fn is_truncated(&self) -> bool
Returns true if the response was truncated by the token limit.
Trait Implementations§
Source§impl Clone for FinishReason
impl Clone for FinishReason
Source§fn clone(&self) -> FinishReason
fn clone(&self) -> FinishReason
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 FinishReason
impl Debug for FinishReason
impl Eq for FinishReason
Source§impl PartialEq for FinishReason
impl PartialEq for FinishReason
impl StructuralPartialEq for FinishReason
Auto Trait Implementations§
impl Freeze for FinishReason
impl RefUnwindSafe for FinishReason
impl Send for FinishReason
impl Sync for FinishReason
impl Unpin for FinishReason
impl UnsafeUnpin for FinishReason
impl UnwindSafe for FinishReason
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.