-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.rs
31 lines (27 loc) · 1.08 KB
/
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
use endpoints::chat::{
ChatCompletionRequestMessage, ChatCompletionSystemMessage, ChatCompletionUserMessage,
ChatCompletionUserMessageContent,
};
use llamaedge::{params::ChatParams, Client};
#[tokio::main]
async fn main() {
const SERVER_BASE_URL: &str = "http://localhost:8080";
// Create a client
let client = Client::new(SERVER_BASE_URL).unwrap();
// create messages
let mut messages = Vec::new();
let system_message = ChatCompletionRequestMessage::System(ChatCompletionSystemMessage::new(
"You are a helpful assistant. Answer questions as concisely and accurately as possible.",
None,
));
messages.push(system_message);
let user_message = ChatCompletionRequestMessage::User(ChatCompletionUserMessage::new(
ChatCompletionUserMessageContent::Text("What is the capital of France?".to_string()),
None,
));
messages.push(user_message);
// send chat completion request
if let Ok(generation) = client.chat(&messages[..], &ChatParams::default()).await {
println!("AI response: {}", generation);
}
}