-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathbasic.rs
More file actions
37 lines (32 loc) · 1.09 KB
/
Copy pathbasic.rs
File metadata and controls
37 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Basic example: simple text prompt with Anthropic.
//!
//! Run with: ANTHROPIC_API_KEY=sk-... cargo run --example basic
use yoagent::agent::Agent;
use yoagent::provider::ModelConfig;
use yoagent::*;
#[tokio::main]
async fn main() {
// The Anthropic provider is selected from the config's protocol, and the
// API key is read from ANTHROPIC_API_KEY. Add `.with_api_key(key)` to
// pass one explicitly.
let mut agent = Agent::from_config(ModelConfig::anthropic("claude-sonnet-5", "Sonnet 5"))
.with_system_prompt("You are a helpful assistant. Be concise.");
println!("Sending prompt...");
let mut rx = agent
.prompt("What is Rust's ownership model in 2 sentences?")
.await;
while let Some(event) = rx.recv().await {
match event {
AgentEvent::MessageUpdate {
delta: StreamDelta::Text { delta },
..
} => {
print!("{}", delta);
}
AgentEvent::AgentEnd { .. } => {
println!("\n\n--- Done ---");
}
_ => {}
}
}
}