use crate::chat_client::openai_api::{client::Error as OpenAiClientError, message};
use eventsource_stream::EventStreamError;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("API error: {0}")]
OpenAiClient(#[from] OpenAiClientError),
#[error("Response contains no choices")]
NoChoices,
#[error("Invalid message: {0}")]
InvalidMessage(#[from] message::Error),
#[error("Assistant message contains no `content`")]
NoContent,
#[error("Model refused the request: \"{0}\"")]
Refusal(String),
#[error("Failed to initialize tokenizer: {0}")]
TokenizerInit(String),
#[error("Stream error: {0}")]
StreamError(#[from] EventStreamError<reqwest::Error>),
#[error("Completion delta JSON parsing error: {0}")]
DeltaJsonError(#[from] serde_json::Error),
#[error("Unexpected stream event: {0}")]
UnexpectedStreamEvent(&'static str),
#[error("Content is not a text")]
NonTextContent,
#[error("Internal error: {0}. This is a bug")]
InternalError(&'static str),
#[error("Body serialization error: {0}. This is a bug.")]
BodySerializationError(serde_json::Error),
}