-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_claude_chat.rs
57 lines (47 loc) · 1.6 KB
/
demo_claude_chat.rs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::bedrock::model_info::{ModelInfo, ModelName};
use crate::bedrock::models::claude::claude_client::{ClaudeClient, ClaudeOptions};
use crate::bedrock::models::claude::claude_request_message::ChatOptions;
use crate::bedrock::models::claude::claude_request_message::ConversationRequest;
use crate::bedrock::models::claude::claude_request_message::Message;
pub async fn demo_chat_claude() {
let claude_options = ClaudeOptions::new()
.profile_name("bedrock")
.region("us-west-2");
let client = ClaudeClient::new(claude_options).await;
let mut conversation_request = ConversationRequest::default();
conversation_request
.messages
.push(Message::new_user_message(
"What is the capital of France ?".to_owned(),
));
println!(
"{}",
serde_json::to_string_pretty(&conversation_request).unwrap()
);
let chat_options =
ChatOptions::default()
.with_temperature(0.5)
.with_model_id(ModelInfo::from_model_name(
ModelName::AnthropicClaudeHaiku1x,
));
let response = client.chat(&conversation_request, &chat_options).await;
match response {
Ok(response) => {
println!("{:?}", response);
let json_display = serde_json::to_string_pretty(&response).unwrap();
println!("{:?}", json_display);
}
Err(e) => {
println!("Error: {:?}", e);
}
}
}
// Test
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_demo_chat_claude() {
demo_chat_claude().await;
}
}