use midstream::{Midstream, HyprSettings, HyprServiceImpl, StreamProcessor, LLMClient};
use bytes::Bytes;
use futures::stream::BoxStream;
use futures::stream::iter;
use std::time::Duration;
struct ExampleLLMClient;
impl LLMClient for ExampleLLMClient {
fn stream(&self) -> BoxStream<'static, Bytes> {
Box::pin(iter(vec![
Bytes::from_static(b"URGENT: What's the weather like?"),
Bytes::from_static(b"Schedule a meeting for tomorrow"),
Bytes::from_static(b"Just a normal message"),
]))
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let settings = HyprSettings::new()?;
let hypr_service = HyprServiceImpl::new(&settings).await?;
let llm_client = ExampleLLMClient;
let midstream = Midstream::new(
Box::new(llm_client),
Box::new(hypr_service),
);
let messages = midstream.process_stream().await?;
println!("\nProcessed messages:");
for msg in &messages {
println!("- Content: {}", msg.content_str());
println!(" Intent: {:?}", msg.intent);
if let Some(response) = &msg.tool_response {
println!(" Tool Response: {}", response);
}
println!();
}
let metrics = midstream.get_metrics().await;
println!("\nCollected metrics:");
for metric in &metrics {
println!("- Name: {}", metric.name);
println!(" Value: {}", metric.value);
println!(" Labels: {:?}", metric.labels);
println!();
}
let avg = midstream.get_average_sentiment(Duration::from_secs(300)).await?;
println!("\nAverage sentiment: {}", avg);
Ok(())
}