Add the text_embeddings API

This commit is contained in:
2024-02-28 14:03:30 +00:00
parent b8f2b7e85e
commit 627ce368b4
4 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
use std::sync::Arc;
use gemini_rs::prelude::*;
use gcp_auth::AuthenticationManager;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let authentication_manager = Arc::new(AuthenticationManager::new().await?);
let api_endpoint = std::env::var("API_ENDPOINT")?;
let project_id = std::env::var("PROJECT_ID")?;
let location_id = std::env::var("LOCATION_ID")?;
let gemini = GeminiClient::new(
authentication_manager,
api_endpoint,
project_id,
location_id,
);
let embedding_request = TextEmbeddingRequest {
instances: vec![
TextEmbeddingRequestInstance {
title: String::from("Embed testing"),
content: String::from("Embed testing"),
task_type: String::from("RETRIEVAL_DOCUMENT"),
},
TextEmbeddingRequestInstance {
title: String::from("Embed testing 2"),
content: String::from("Embed testing 2"),
task_type: String::from("RETRIEVAL_DOCUMENT"),
},
],
};
let result = gemini.text_embeddings(&embedding_request).await?;
println!("Response: {:?}", result);
Ok(())
}