From a193710a7f88de12ef11c5a5c66a5591150fe247 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 25 Apr 2024 14:03:16 +0800 Subject: refactor: extract common catch_error (#437) --- src/client/ollama.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/client/ollama.rs') diff --git a/src/client/ollama.rs b/src/client/ollama.rs index 1394ced..f2340c6 100644 --- a/src/client/ollama.rs +++ b/src/client/ollama.rs @@ -1,6 +1,6 @@ use super::{ - message::*, Client, ExtraConfig, Model, ModelConfig, OllamaClient, PromptType, ReplyHandler, - SendData, + catch_error, message::*, Client, ExtraConfig, Model, ModelConfig, OllamaClient, PromptType, + ReplyHandler, SendData, }; use crate::utils::PromptKind; @@ -191,11 +191,3 @@ fn build_body(data: SendData, model: &Model) -> Result { Ok(body) } - -fn catch_error(data: &Value, status: u16) -> Result<()> { - debug!("Invalid response, status: {status}, data: {data}"); - if let Some(error) = data["error"].as_str() { - bail!("{error}"); - } - bail!("Invalid response, status: {status}, data: {data}"); -} -- cgit v1.2.3