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?;
|
stream_to_stdout(agent, &mut stream).await?;
|
||||||
|
|
||||||
|
|
||||||
if let Some(response) = stream.response {
|
if let Some(response) = stream.response {
|
||||||
println!("Usage: {:?} tokens", response.usage.output_tokens);
|
println!("Usage: {:?} tokens", response.usage.output_tokens);
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Message: {:?}", stream.message);
|
println!("Message: {:?}", stream.message);
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,10 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
stream_to_stdout(agent, &mut stream).await?;
|
stream_to_stdout(agent, &mut stream).await?;
|
||||||
|
|
||||||
if let Some(response) = stream.response {
|
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);
|
println!("Message: {:?}", stream.message);
|
||||||
|
|
|
@ -109,10 +109,13 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
stream_to_stdout(calculator_agent, &mut stream).await?;
|
stream_to_stdout(calculator_agent, &mut stream).await?;
|
||||||
|
|
||||||
if let Some(response) = stream.response {
|
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);
|
println!("Message: {:?}", stream.message);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,6 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Message: {:?}", stream.message);
|
println!("Message: {:?}", stream.message);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,11 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
stream_to_stdout(agent, &mut stream).await?;
|
stream_to_stdout(agent, &mut stream).await?;
|
||||||
|
|
||||||
if let Some(response) = stream.response {
|
if let Some(response) = stream.response {
|
||||||
println!("Usage: {:?}", response.usage)
|
println!("Usage: {:?}", response.usage)
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Message: {:?}", stream.message);
|
println!("Message: {:?}", stream.message);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -107,12 +107,12 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
println!("Calculate 2 - 5");
|
println!("Calculate 2 - 5");
|
||||||
let mut stream = calculator_agent.stream_prompt("Calculate 2 - 5").await?;
|
let mut stream = calculator_agent.stream_prompt("Calculate 2 - 5").await?;
|
||||||
stream_to_stdout(calculator_agent, &mut stream).await?;
|
stream_to_stdout(calculator_agent, &mut stream).await?;
|
||||||
|
|
||||||
if let Some(response) = stream.response {
|
if let Some(response) = stream.response {
|
||||||
println!("Usage: {:?}", response.usage)
|
println!("Usage: {:?}", response.usage)
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Message: {:?}", stream.message);
|
println!("Message: {:?}", stream.message);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ use futures::StreamExt;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::completion::{create_request_body, gemini_api_types::ContentCandidate, CompletionModel};
|
use super::completion::{create_request_body, gemini_api_types::ContentCandidate, CompletionModel};
|
||||||
use crate::providers::gemini::completion::gemini_api_types::UsageMetadata;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
completion::{CompletionError, CompletionRequest},
|
completion::{CompletionError, CompletionRequest},
|
||||||
streaming::{self, StreamingCompletionModel},
|
streaming::{self, StreamingCompletionModel},
|
||||||
|
|
|
@ -486,7 +486,7 @@ impl StreamingCompletionModel for CompletionModel {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.done {
|
if response.done {
|
||||||
yield Ok(RawStreamingChoice::FinalResponse(StreamingCompletionResponse {
|
yield Ok(RawStreamingChoice::FinalResponse(StreamingCompletionResponse {
|
||||||
total_duration: response.total_duration,
|
total_duration: response.total_duration,
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub async fn send_compatible_streaming_request(
|
||||||
prompt_tokens: 0,
|
prompt_tokens: 0,
|
||||||
total_tokens: 0
|
total_tokens: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut partial_data = None;
|
let mut partial_data = None;
|
||||||
let mut calls: HashMap<usize, (String, String)> = HashMap::new();
|
let mut calls: HashMap<usize, (String, String)> = HashMap::new();
|
||||||
|
|
||||||
|
@ -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 {
|
if let Some(usage) = data.usage {
|
||||||
final_usage = usage.clone();
|
final_usage = usage.clone();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ pub type StreamingResult<R> =
|
||||||
Pin<Box<dyn Stream<Item = Result<RawStreamingChoice<R>, CompletionError>> + Send>>;
|
Pin<Box<dyn Stream<Item = Result<RawStreamingChoice<R>, CompletionError>> + Send>>;
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[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> {
|
pub struct StreamingCompletionResponse<R: Clone + Unpin> {
|
||||||
inner: StreamingResult<R>,
|
inner: StreamingResult<R>,
|
||||||
|
@ -92,14 +93,13 @@ impl<R: Clone + Unpin> Stream for StreamingCompletionResponse<R> {
|
||||||
match stream.inner.as_mut().poll_next(cx) {
|
match stream.inner.as_mut().poll_next(cx) {
|
||||||
Poll::Pending => Poll::Pending,
|
Poll::Pending => Poll::Pending,
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
|
|
||||||
let mut content = vec![];
|
let mut content = vec![];
|
||||||
|
|
||||||
stream.tool_calls.iter().for_each(|(n, d, a)| {
|
stream.tool_calls.iter().for_each(|(n, d, a)| {
|
||||||
content.push(AssistantContent::tool_call(n, d, a.clone()));
|
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()));
|
content.insert(0, AssistantContent::text(stream.text.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ impl<R: Clone + Unpin> Stream for StreamingCompletionResponse<R> {
|
||||||
content: OneOrMany::many(content)
|
content: OneOrMany::many(content)
|
||||||
.expect("There should be at least one assistant message"),
|
.expect("There should be at least one assistant message"),
|
||||||
};
|
};
|
||||||
|
|
||||||
Poll::Ready(None)
|
Poll::Ready(None)
|
||||||
},
|
}
|
||||||
Poll::Ready(Some(Err(err))) => Poll::Ready(Some(Err(err))),
|
Poll::Ready(Some(Err(err))) => Poll::Ready(Some(Err(err))),
|
||||||
Poll::Ready(Some(Ok(choice))) => match choice {
|
Poll::Ready(Some(Ok(choice))) => match choice {
|
||||||
RawStreamingChoice::Message(text) => {
|
RawStreamingChoice::Message(text) => {
|
||||||
|
|
Loading…
Reference in New Issue