Skip to main content

response/
response.rs

1// Example: Blocking response generation with instructions
2//
3// This example demonstrates using the `response()` method to get a complete
4// response from the Foundation Model, with custom instructions.
5//
6// Usage: cargo run --example response
7
8use fm_bindings::LanguageModelSession;
9
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11    println!("=== Foundation Models - Blocking Response Example ===\n");
12
13    // Create a new session with instructions
14    println!("Creating session with instructions...");
15    let session = LanguageModelSession::with_instructions(
16        "You are a helpful assistant. Provide concise, accurate answers.",
17    )?;
18    println!("Session created!\n");
19
20    // Define the prompt
21    let prompt = "What is Rust programming language? Please explain in 2-3 sentences.";
22    println!("Prompt: \"{}\"\n", prompt);
23    println!("Generating response...\n");
24
25    // Get the complete response
26    // This blocks until the entire response is generated
27    let response = session.response(prompt)?;
28
29    // Print the response
30    println!("Response:\n{}\n", response);
31
32    // Multi-turn conversation example
33    println!("--- Multi-turn conversation ---\n");
34
35    let follow_up = "What are its main advantages?";
36    println!("Follow-up: \"{}\"\n", follow_up);
37
38    let response2 = session.response(follow_up)?;
39    println!("Response:\n{}\n", response2);
40
41    println!("=== Complete ===");
42
43    Ok(())
44}