mirror of https://github.com/0xplaygrounds/rig
fix: wasm missing generic + fmt
This commit is contained in:
parent
2920eb0a0e
commit
cad584455a
|
@ -19,13 +19,11 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
|
||||
stream_to_stdout(agent, &mut stream).await?;
|
||||
|
||||
|
||||
if let Some(response) = stream.response {
|
||||
println!("Usage: {:?} tokens", response.usage.output_tokens);
|
||||
};
|
||||
|
||||
println!("Message: {:?}", stream.message);
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -20,7 +20,10 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
stream_to_stdout(agent, &mut stream).await?;
|
||||
|
||||
if let Some(response) = stream.response {
|
||||
println!("Usage: {:?} tokens", response.usage_metadata.total_token_count);
|
||||
println!(
|
||||
"Usage: {:?} tokens",
|
||||
response.usage_metadata.total_token_count
|
||||
);
|
||||
};
|
||||
|
||||
println!("Message: {:?}", stream.message);
|
||||
|
|
|
@ -109,7 +109,10 @@ async fn main() -> Result<(), anyhow::Error> {
|
|||
stream_to_stdout(calculator_agent, &mut stream).await?;
|
||||
|
||||
if let Some(response) = stream.response {
|
||||
println!("Usage: {:?} tokens", response.usage_metadata.total_token_count);
|
||||
println!(
|
||||
"Usage: {:?} tokens",
|
||||
response.usage_metadata.total_token_count
|
||||
);
|
||||
};
|
||||
|
||||
println!("Message: {:?}", stream.message);
|
||||
|
|
|
@ -3,7 +3,6 @@ use futures::StreamExt;
|
|||
use serde::Deserialize;
|
||||
|
||||
use super::completion::{create_request_body, gemini_api_types::ContentCandidate, CompletionModel};
|
||||
use crate::providers::gemini::completion::gemini_api_types::UsageMetadata;
|
||||
use crate::{
|
||||
completion::{CompletionError, CompletionRequest},
|
||||
streaming::{self, StreamingCompletionModel},
|
||||
|
|
|
@ -183,9 +183,12 @@ pub async fn send_compatible_streaming_request(
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if let Some(content) = &choice.delta.content {
|
||||
yield Ok(streaming::RawStreamingChoice::Message(content.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let Some(usage) = data.usage {
|
||||
final_usage = usage.clone();
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ pub type StreamingResult<R> =
|
|||
Pin<Box<dyn Stream<Item = Result<RawStreamingChoice<R>, CompletionError>> + Send>>;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub type StreamingResult = Pin<Box<dyn Stream<Item = Result<RawStreamingChoice, CompletionError>>>>;
|
||||
pub type StreamingResult<R> =
|
||||
Pin<Box<dyn Stream<Item = Result<RawStreamingChoice<R>, CompletionError>>>>;
|
||||
|
||||
pub struct StreamingCompletionResponse<R: Clone + Unpin> {
|
||||
inner: StreamingResult<R>,
|
||||
|
@ -92,14 +93,13 @@ impl<R: Clone + Unpin> Stream for StreamingCompletionResponse<R> {
|
|||
match stream.inner.as_mut().poll_next(cx) {
|
||||
Poll::Pending => Poll::Pending,
|
||||
Poll::Ready(None) => {
|
||||
|
||||
let mut content = vec![];
|
||||
|
||||
stream.tool_calls.iter().for_each(|(n, d, a)| {
|
||||
content.push(AssistantContent::tool_call(n, d, a.clone()));
|
||||
});
|
||||
|
||||
if content.len() == 0 || stream.text.len() > 0 {
|
||||
if content.is_empty() || !stream.text.is_empty() {
|
||||
content.insert(0, AssistantContent::text(stream.text.clone()));
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ impl<R: Clone + Unpin> Stream for StreamingCompletionResponse<R> {
|
|||
};
|
||||
|
||||
Poll::Ready(None)
|
||||
},
|
||||
}
|
||||
Poll::Ready(Some(Err(err))) => Poll::Ready(Some(Err(err))),
|
||||
Poll::Ready(Some(Ok(choice))) => match choice {
|
||||
RawStreamingChoice::Message(text) => {
|
||||
|
|
Loading…
Reference in New Issue