Skip to content

Commit 8ea92fb

Browse files
committed
Implement IsError for LLMEngineOutput
1 parent 061e08c commit 8ea92fb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/llm/src/protocols/common/llm_backend.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use serde::{Deserialize, Serialize};
1818
pub use super::preprocessor::PreprocessedRequest;
1919
pub use super::FinishReason;
2020
use crate::protocols::TokenIdType;
21+
use dynamo_runtime::protocols::is_error::IsError;
2122

2223
pub type TokenType = Option<String>;
2324
pub type LogProbs = Vec<f64>;
@@ -133,3 +134,17 @@ impl LLMEngineOutput {
133134
}
134135
}
135136
}
137+
138+
impl IsError for LLMEngineOutput {
139+
fn from_err(err: Box<dyn std::error::Error>) -> Self {
140+
LLMEngineOutput::error(format!("{:?}", err))
141+
}
142+
143+
fn err(&self) -> Option<Box<dyn std::error::Error>> {
144+
if let Some(FinishReason::Error(err_msg)) = &self.finish_reason {
145+
Some(anyhow::Error::msg(err_msg.clone()).into())
146+
} else {
147+
None
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)