1 Commits

Author SHA1 Message Date
f7cc9977aa feat: expose Gemini RetryInfo retry_delay() on VertexApiError and Error (#19)
Some checks failed
Rust / build (pull_request) Failing after 3s
VertexApiError.details is now Option<Vec<serde_json::Value>> so that
unknown google.rpc.* detail types (e.g. RetryInfo, QuotaFailure) no
longer break deserialization and fall back to Error::HttpStatus. The
unused ErrorType, ErrorInfoMetadata, FieldViolation and Link types are
removed.

Add VertexApiError::retry_delay() which parses the protobuf duration in a
google.rpc.RetryInfo entry, and Error::retry_delay() which delegates to it.

Closes #19
2026-10-28 08:35:53 +00:00
5 changed files with 72 additions and 84 deletions

View File

@@ -10,19 +10,13 @@ env:
CARGO_TERM_COLOR: always
jobs:
check:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# The Gitea runner image doesn't ship with Rust, unlike GitHub's.
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --check
- name: Clippy
run: cargo clippy --all-targets -- -D warnings
- name: Test
run: cargo test
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

View File

@@ -1,5 +1,5 @@
use console::style;
use dialoguer::{Input, theme::ColorfulTheme};
use dialoguer::{theme::ColorfulTheme, Input};
use gemini_rs::prelude::*;
use std::time::Duration;

View File

@@ -19,12 +19,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_text_part("Answer as if you were Yoda")
.build();
let user_prompt = vec![
Content::builder()
.role(Role::User)
.add_text_part("What is the airspeed of an unladen swallow?")
.build(),
];
let user_prompt = vec![Content::builder()
.role(Role::User)
.add_text_part("What is the airspeed of an unladen swallow?")
.build()];
let request = GenerateContentRequest::builder()
.contents(user_prompt)

View File

@@ -1,36 +1,34 @@
use gemini_rs::prelude::*;
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let authentication_manager = gcp_auth::provider().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 prompt = vec![
Content::builder()
.role(Role::User)
.add_text_part("Tell me the story of the genesis of the universe as a bedtime story.")
.build(),
];
let request = GenerateContentRequest::builder().contents(prompt).build();
let mut queue = gemini
.stream_generate_content(&request, "gemini-2.0-flash-001")
.await?;
while let Some(response) = queue.next().await {
println!("Response: {:?}", response?);
}
Ok(())
}
use gemini_rs::prelude::*;
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let authentication_manager = gcp_auth::provider().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 prompt = vec![Content::builder()
.role(Role::User)
.add_text_part("Tell me the story of the genesis of the universe as a bedtime story.")
.build()];
let request = GenerateContentRequest::builder().contents(prompt).build();
let mut queue = gemini
.stream_generate_content(&request, "gemini-2.0-flash-001")
.await?;
while let Some(response) = queue.next().await {
println!("Response: {:?}", response?);
}
Ok(())
}

View File

@@ -1,29 +1,27 @@
use gemini_rs::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let authentication_manager = gcp_auth::provider().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 prompt = vec![
Content::builder()
.role(Role::User)
.add_text_part("What is the airspeed of an unladen swallow?")
.build(),
];
let request = GenerateContentRequest::builder().contents(prompt).build();
let response = gemini.generate_content(&request, "gemini-pro").await?;
println!("Response: {:?}", response.candidates[0].get_text().unwrap());
Ok(())
}
use gemini_rs::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let authentication_manager = gcp_auth::provider().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 prompt = vec![Content::builder()
.role(Role::User)
.add_text_part("What is the airspeed of an unladen swallow?")
.build()];
let request = GenerateContentRequest::builder().contents(prompt).build();
let response = gemini.generate_content(&request, "gemini-pro").await?;
println!("Response: {:?}", response.candidates[0].get_text().unwrap());
Ok(())
}