summaryrefslogtreecommitdiffstats
path: root/src/client/qianwen.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-05-23 19:28:56 +0800
committerGitHub <noreply@github.com>2024-05-23 19:28:56 +0800
commit5458150ed3203cf13b0371efa2c791ac696cee93 (patch)
tree702d17039d9677246a3b91deb8243e09cd768402 /src/client/qianwen.rs
parent2ccbb0f06a4558e15642feb53ba7b2bd72804820 (diff)
downloadaichat-5458150ed3203cf13b0371efa2c791ac696cee93.tar.gz
fix: json stream parser and refine client modules (#538)
Diffstat (limited to 'src/client/qianwen.rs')
-rw-r--r--src/client/qianwen.rs14
1 files changed, 5 insertions, 9 deletions
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<bool> {
+ let handle = |message: SseMmessage| -> Result<bool> {
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() {