forked from graniet/llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle_embedding_example.rs
More file actions
28 lines (24 loc) · 1002 Bytes
/
google_embedding_example.rs
File metadata and controls
28 lines (24 loc) · 1002 Bytes
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
// Import required builder types from llm
use llm::builder::{LLMBackend, LLMBuilder};
/// Example demonstrating how to generate embeddings using Google's API
///
/// This example shows how to:
/// - Configure a Google LLM provider
/// - Generate embeddings for text input
/// - Access and display the resulting embedding vector
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the LLM builder with Google configuration
let llm = LLMBuilder::new()
.backend(LLMBackend::Google)
// Get API key from environment variable or use test key
.api_key(std::env::var("GOOGLE_API_KEY").unwrap_or("YOUR-TEST-KEY".to_string()))
// Use Google's text embedding model
.model("text-embedding-004")
.build()?;
// Generate embedding vector for sample text
let vector = llm.embed(vec!["Hello world!".to_string()]).await?;
// Print embedding statistics and data
println!("Data: {:?}", &vector);
Ok(())
}