summaryrefslogtreecommitdiffstats
path: root/src/client/qianwen.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/qianwen.rs')
-rw-r--r--src/client/qianwen.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/client/qianwen.rs b/src/client/qianwen.rs
index 8a5a6d5..1f23385 100644
--- a/src/client/qianwen.rs
+++ b/src/client/qianwen.rs
@@ -1,6 +1,6 @@
use super::{
- maybe_catch_error, message::*, Client, CompletionStats, ExtraConfig, Model, ModelConfig,
- PromptType, QianwenClient, ReplyHandler, SendData,
+ maybe_catch_error, message::*, Client, CompletionDetails, ExtraConfig, Model, ModelConfig,
+ PromptType, QianwenClient, SendData, SseHandler,
};
use crate::utils::{sha256sum, PromptKind};
@@ -77,7 +77,7 @@ impl Client for QianwenClient {
&self,
client: &ReqwestClient,
mut data: SendData,
- ) -> Result<(String, CompletionStats)> {
+ ) -> Result<(String, CompletionDetails)> {
let api_key = self.get_api_key()?;
patch_messages(&self.model.name, &api_key, &mut data.messages).await?;
let builder = self.request_builder(client, data)?;
@@ -87,7 +87,7 @@ impl Client for QianwenClient {
async fn send_message_streaming_inner(
&self,
client: &ReqwestClient,
- handler: &mut ReplyHandler,
+ handler: &mut SseHandler,
mut data: SendData,
) -> Result<()> {
let api_key = self.get_api_key()?;
@@ -97,7 +97,7 @@ impl Client for QianwenClient {
}
}
-async fn send_message(builder: RequestBuilder, is_vl: bool) -> Result<(String, CompletionStats)> {
+async fn send_message(builder: RequestBuilder, is_vl: bool) -> Result<(String, CompletionDetails)> {
let data: Value = builder.send().await?.json().await?;
maybe_catch_error(&data)?;
@@ -106,7 +106,7 @@ async fn send_message(builder: RequestBuilder, is_vl: bool) -> Result<(String, C
async fn send_message_streaming(
builder: RequestBuilder,
- handler: &mut ReplyHandler,
+ handler: &mut SseHandler,
is_vl: bool,
) -> Result<()> {
let mut es = builder.eventsource()?;
@@ -210,7 +210,7 @@ fn build_body(data: SendData, model: &Model, is_vl: bool) -> Result<(Value, bool
Ok((body, has_upload))
}
-fn extract_completion_text(data: &Value, is_vl: bool) -> Result<(String, CompletionStats)> {
+fn extract_completion_text(data: &Value, is_vl: bool) -> Result<(String, CompletionDetails)> {
let err = || anyhow!("Invalid response data: {data}");
let text = if is_vl {
data["output"]["choices"][0]["message"]["content"][0]["text"]
@@ -219,13 +219,13 @@ fn extract_completion_text(data: &Value, is_vl: bool) -> Result<(String, Complet
} else {
data["output"]["text"].as_str().ok_or_else(err)?
};
- let stats = CompletionStats {
+ let details = CompletionDetails {
id: data["request_id"].as_str().map(|v| v.to_string()),
input_tokens: data["usage"]["input_tokens"].as_u64(),
output_tokens: data["usage"]["output_tokens"].as_u64(),
};
- Ok((text.to_string(), stats))
+ Ok((text.to_string(), details))
}
/// Patch messsages, upload embedded images to oss