pub enum ResponseMessage {
Anthropic(AnthropicResponse),
OpenAI(OpenAIResponse),
}Expand description
Represents the response message received from an LLM API.
The ResponseMessage enum encapsulates the different response types from various LLM APIs,
providing a unified interface for accessing common fields and methods.
Variants§
Anthropic(AnthropicResponse)
OpenAI(OpenAIResponse)
Implementations§
Source§impl ResponseMessage
impl ResponseMessage
Sourcepub fn first_message(&self) -> String
pub fn first_message(&self) -> String
Returns the text content of the first message in the response.
§Examples
let response = ResponseMessage::Anthropic(AnthropicResponse {
id: "".to_string(),
role: "".to_string(),
content: vec![],
model: "".to_string(),
stop_reason: "".to_string(),
stop_sequence: None,
usage: Default::default(),}
);
let first_message = response.first_message();
println!("First message: {}", first_message);pub fn tools(&self) -> Option<Vec<ToolResponse>>
Sourcepub fn role(&self) -> &str
pub fn role(&self) -> &str
Returns the role of the sender in the response.
§Examples
let response = ResponseMessage::Anthropic(AnthropicResponse {
id: "".to_string(),
role: "".to_string(),
content: vec![],
model: "".to_string(),
stop_reason: "".to_string(),
stop_sequence: None,
usage: Default::default(),}
);
let role = response.role();
println!("Role: {}", role);Sourcepub fn model(&self) -> &str
pub fn model(&self) -> &str
Returns the name of the model used for generating the response.
§Examples
let response = ResponseMessage::Anthropic(AnthropicResponse {
id: "".to_string(),
role: "".to_string(),
content: vec![],
model: "".to_string(),
stop_reason: "".to_string(),
stop_sequence: None,
usage: Default::default(),}
);
let model = response.model();
println!("Model: {}", model);Sourcepub fn stop_reason(&self) -> &str
pub fn stop_reason(&self) -> &str
Returns the stop reason for the generated response.
§Examples
let response = ResponseMessage::Anthropic(AnthropicResponse {
id: "".to_string(),
role: "".to_string(),
content: vec![],
model: "".to_string(),
stop_reason: "".to_string(),
stop_sequence: None,
usage: Default::default(),}
);
let stop_reason = response.stop_reason();
println!("Stop reason: {}", stop_reason);Sourcepub fn usage(&self) -> CommonUsage
pub fn usage(&self) -> CommonUsage
Returns the usage information for the generated response.
§Examples
let response = ResponseMessage::Anthropic(AnthropicResponse {
id: "".to_string(),
role: "".to_string(),
content: vec![],
model: "".to_string(),
stop_reason: "".to_string(),
stop_sequence: None,
usage: Default::default(),}
);
let usage = response.usage();
println!("Input tokens: {}", usage.input_tokens);
println!("Output tokens: {}", usage.output_tokens);Trait Implementations§
Source§impl Debug for ResponseMessage
impl Debug for ResponseMessage
Source§impl<'de> Deserialize<'de> for ResponseMessage
impl<'de> Deserialize<'de> for ResponseMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for ResponseMessage
impl Display for ResponseMessage
Auto Trait Implementations§
impl Freeze for ResponseMessage
impl RefUnwindSafe for ResponseMessage
impl Send for ResponseMessage
impl Sync for ResponseMessage
impl Unpin for ResponseMessage
impl UnsafeUnpin for ResponseMessage
impl UnwindSafe for ResponseMessage
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
Mutably borrows from an owned value. Read more