summaryrefslogtreecommitdiffstats
path: root/src/client/cohere.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-25 14:03:16 +0800
committerGitHub <noreply@github.com>2024-04-25 14:03:16 +0800
commita193710a7f88de12ef11c5a5c66a5591150fe247 (patch)
tree937a64da3dad52706d155ac9191e324fd8648ccc /src/client/cohere.rs
parent4db9b309803796bc5f996d0b3713344eb44207ec (diff)
downloadaichat-a193710a7f88de12ef11c5a5c66a5591150fe247.tar.gz
refactor: extract common catch_error (#437)
Diffstat (limited to 'src/client/cohere.rs')
-rw-r--r--src/client/cohere.rs14
1 files changed, 2 insertions, 12 deletions
diff --git a/src/client/cohere.rs b/src/client/cohere.rs
index 828b799..df86843 100644
--- a/src/client/cohere.rs
+++ b/src/client/cohere.rs
@@ -1,6 +1,6 @@
use super::{
- extract_sytem_message, json_stream, message::*, Client, CohereClient, ExtraConfig, Model,
- ModelConfig, PromptType, ReplyHandler, SendData,
+ catch_error, extract_sytem_message, json_stream, message::*, Client, CohereClient, ExtraConfig,
+ Model, ModelConfig, PromptType, ReplyHandler, SendData,
};
use crate::utils::PromptKind;
@@ -184,16 +184,6 @@ fn build_body(data: SendData, model: &Model) -> Result<Value> {
Ok(body)
}
-fn catch_error(data: &Value, status: u16) -> Result<()> {
- debug!("Invalid response, status: {status}, data: {data}");
-
- if let Some(message) = data["message"].as_str() {
- bail!("{message}");
- } else {
- bail!("Invalid response, status: {status}, data: {data}");
- }
-}
-
fn extract_text(data: &Value) -> Result<&str> {
match data["text"].as_str() {
Some(text) => Ok(text),