llm_sdk/errors.rs
1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum LanguageModelError {
5 #[error("Invalid input: {0}")]
6 InvalidInput(String),
7 /// The request to the provider failed or the parsing of the response
8 /// failed.
9 #[error("Transport error: {0}")]
10 Transport(#[from] reqwest::Error),
11 /// The request returns a non-OK status code
12 #[error("Status error: {1} (Status {0})")]
13 StatusCode(reqwest::StatusCode, String),
14 /// The input is not supported by or is incompatible with the model
15 /// (e.g. using non text for assistant message parts)
16 #[error("Unsupported by {0}: {1}")]
17 Unsupported(&'static str, String),
18 /// An output from the model is not recognized by the library.
19 /// Please report this issue to the library maintainers.
20 #[error("Not implemented for {0}: {1}")]
21 NotImplemented(&'static str, String),
22 /// The response from the provider was unexpected. (e.g. no choices returned
23 /// in an `OpenAI` completion)
24 #[error("Invariant from {0}: {1}")]
25 Invariant(&'static str, String),
26 /// The model refused to process the input. (e.g. `OpenAI` refusal)
27 #[error("Refusal: {0}")]
28 Refusal(String),
29}
30
31pub type LanguageModelResult<T> = Result<T, LanguageModelError>;