-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresponse.rs
More file actions
44 lines (33 loc) · 1.4 KB
/
response.rs
File metadata and controls
44 lines (33 loc) · 1.4 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
38
39
40
41
42
43
44
// Example: Blocking response generation with instructions
//
// This example demonstrates using the `response()` method to get a complete
// response from the Foundation Model, with custom instructions.
//
// Usage: cargo run --example response
use fm_bindings::LanguageModelSession;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== Foundation Models - Blocking Response Example ===\n");
// Create a new session with instructions
println!("Creating session with instructions...");
let session = LanguageModelSession::with_instructions(
"You are a helpful assistant. Provide concise, accurate answers.",
)?;
println!("Session created!\n");
// Define the prompt
let prompt = "What is Rust programming language? Please explain in 2-3 sentences.";
println!("Prompt: \"{}\"\n", prompt);
println!("Generating response...\n");
// Get the complete response
// This blocks until the entire response is generated
let response = session.response(prompt)?;
// Print the response
println!("Response:\n{}\n", response);
// Multi-turn conversation example
println!("--- Multi-turn conversation ---\n");
let follow_up = "What are its main advantages?";
println!("Follow-up: \"{}\"\n", follow_up);
let response2 = session.response(follow_up)?;
println!("Response:\n{}\n", response2);
println!("=== Complete ===");
Ok(())
}