Skip to content

Commit

Permalink
loom error in api
Browse files Browse the repository at this point in the history
  • Loading branch information
snowmead committed Sep 27, 2024
1 parent f0874b1 commit cf1fff4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use types::{LoomError, SummaryModelTokens, WeaveError};

use crate::types::{PromptModelTokens, WrapperRole};

pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
pub type Result<T> = std::result::Result<T, LoomError>;

/// Represents a unique identifier for any arbitrary entity.
///
Expand Down
7 changes: 2 additions & 5 deletions src/loom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ impl<T: Config> Loom<T> {
tapestry_id: TID,
instructions: String,
mut msgs: Vec<ContextMessage<T>>,
) -> Result<
(<<T as Config>::PromptModel as Llm<T>>::Response, u64, bool),
Box<dyn std::error::Error + Send + Sync>,
> {
) -> Result<(<<T as Config>::PromptModel as Llm<T>>::Response, u64, bool), LoomError> {
let instructions_ctx_msg =
Self::build_context_message(SYSTEM_ROLE.into(), instructions, None);
let instructions_req_msg: PromptModelRequest<T> = instructions_ctx_msg.clone().into();
Expand Down Expand Up @@ -211,7 +208,7 @@ impl<T: Config> Loom<T> {
summary_model_config: &LlmConfig<T, T::SummaryModel>,
tapestry_fragment: &TapestryFragment<T>,
summary_max_tokens: SummaryModelTokens<T>,
) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
) -> Result<String, LoomError> {
trace!(
"Generating summary with max tokens: {:?}, for tapestry fragment: {:?}",
summary_max_tokens,
Expand Down
15 changes: 5 additions & 10 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ pub enum LoomError {
#[error("Storage error: {0}")]
Storage(#[from] StorageError),
#[error("Error: {0}")]
Error(String),
}

impl From<Box<dyn std::error::Error + Send + Sync>> for LoomError {
fn from(error: Box<dyn std::error::Error + Send + Sync>) -> Self {
match error.downcast::<LoomError>() {
Ok(loom_error) => *loom_error,
Err(error) => LoomError::Error(error.to_string()),
}
}
UnknownError(String),
}

#[derive(Debug, thiserror::Error)]
Expand All @@ -83,6 +74,10 @@ pub enum WeaveError {
MaxCompletionTokensIsZero,
#[error("Bad configuration: {0}")]
BadConfig(String),
#[error("Not enough credits to cover cost")]
NotEnoughCredits,
#[error("Unknown error: {0}")]
Unknown(String),
}

#[derive(Debug, thiserror::Error)]
Expand Down

0 comments on commit cf1fff4

Please sign in to comment.