From 5458150ed3203cf13b0371efa2c791ac696cee93 Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 23 May 2024 19:28:56 +0800 Subject: fix: json stream parser and refine client modules (#538) --- src/client/qianwen.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/client/qianwen.rs') diff --git a/src/client/qianwen.rs b/src/client/qianwen.rs index ff7f010..2063f20 100644 --- a/src/client/qianwen.rs +++ b/src/client/qianwen.rs @@ -1,7 +1,7 @@ use super::{ maybe_catch_error, message::*, sse_stream, Client, CompletionOutput, ExtraConfig, Model, - ModelData, ModelPatches, PromptAction, PromptKind, QianwenClient, SendData, SsMmessage, - SseHandler, + ModelData, ModelPatches, PromptAction, PromptKind, QianwenClient, SendData, SseHandler, + SseMmessage, }; use crate::utils::{base64_decode, sha256}; @@ -42,7 +42,7 @@ impl QianwenClient { let api_key = self.get_api_key()?; let stream = data.stream; - + let url = match self.model.supports_vision() { true => API_URL_VL, false => API_URL, @@ -64,8 +64,6 @@ impl QianwenClient { } } - - #[async_trait] impl Client for QianwenClient { client_common_fns!(); @@ -108,14 +106,12 @@ async fn send_message_streaming( model: &Model, ) -> Result<()> { let model_name = model.name(); - let handle = |message: SsMmessage| -> Result { + let handle = |message: SseMmessage| -> Result { let data: Value = serde_json::from_str(&message.data)?; maybe_catch_error(&data)?; debug!("stream-data: {data}"); if model_name == "qwen-long" { - if let Some(text) = - data["output"]["choices"][0]["message"]["content"].as_str() - { + if let Some(text) = data["output"]["choices"][0]["message"]["content"].as_str() { handler.text(text)?; } } else if model.supports_vision() { -- cgit v1.2.3