From 2d0cbeaf1870c1f4f4a95068306010d9d8da2d73 Mon Sep 17 00:00:00 2001 From: Xerxes-2 Date: Sun, 3 Aug 2025 22:13:11 +1000 Subject: [PATCH] feat: update request payload type to be generic and adjust test bodies to use GeminiRequest --- src/utils/request.rs | 11 +++++++---- src/validation/key_validator.rs | 12 +++++++----- src/validation/mod.rs | 7 +++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/utils/request.rs b/src/utils/request.rs index 2004e2b..e96d74b 100644 --- a/src/utils/request.rs +++ b/src/utils/request.rs @@ -1,6 +1,6 @@ use backon::{ExponentialBuilder, Retryable}; use reqwest::Client; -use serde_json::Value; +use serde::Serialize; use tokio::time::Duration; use tracing::debug; use url::Url; @@ -8,13 +8,16 @@ use url::Url; use crate::error::ValidatorError; use crate::types::GeminiKey; -pub async fn send_request( +pub async fn send_request( client: Client, api_endpoint: &Url, key: GeminiKey, - payload: &Value, + payload: &T, max_retries: usize, -) -> Result<(), ValidatorError> { +) -> Result<(), ValidatorError> +where + T: Serialize, +{ let retry_policy = ExponentialBuilder::default() .with_max_times(max_retries) .with_min_delay(Duration::from_secs(1)) diff --git a/src/validation/key_validator.rs b/src/validation/key_validator.rs index fac9795..38a3ede 100644 --- a/src/validation/key_validator.rs +++ b/src/validation/key_validator.rs @@ -19,13 +19,16 @@ pub async fn test_generate_content_api( client, &api_endpoint, api_key.clone(), - &GENERATE_CONTENT_TEST_BODY, + &*GENERATE_CONTENT_TEST_BODY, config.max_retries, ) .await { Ok(_) => { - info!("BASIC API VALID - {}... - Passed generate content API test", &api_key.as_ref()[..10]); + info!( + "BASIC API VALID - {}... - Passed generate content API test", + &api_key.as_ref()[..10] + ); Ok(ValidatedKey::new(api_key)) } Err(e) => match &e { @@ -60,7 +63,7 @@ pub async fn test_cache_content_api( client, &api_endpoint, validated_key.key.clone(), - &CACHE_CONTENT_TEST_BODY, + &*CACHE_CONTENT_TEST_BODY, config.max_retries, ) .await @@ -88,7 +91,6 @@ pub async fn test_cache_content_api( ); validated_key } - } + }, } } - diff --git a/src/validation/mod.rs b/src/validation/mod.rs index a6db023..4c12598 100644 --- a/src/validation/mod.rs +++ b/src/validation/mod.rs @@ -63,10 +63,10 @@ pub static GENERATE_CONTENT_TEST_BODY: LazyLock = LazyLock::new(|| { }); // LazyLock for the cached content test body used in cache API validation -pub static CACHE_CONTENT_TEST_BODY: LazyLock = LazyLock::new(|| { +pub static CACHE_CONTENT_TEST_BODY: LazyLock = LazyLock::new(|| { // Generate random text content to meet the minimum 1024 tokens requirement for cache API let long_text = "You are an expert at analyzing transcripts.".repeat(150); - let cache_request = GeminiRequest { + GeminiRequest { model: Some("models/gemini-2.5-flash".to_string()), contents: vec![ContentPart { parts: vec![TextPart { text: long_text }], @@ -74,6 +74,5 @@ pub static CACHE_CONTENT_TEST_BODY: LazyLock = LazyLock::new(|| { }], generation_config: None, ttl: Some("300s".to_string()), - }; - serde_json::to_value(cache_request).unwrap() + } });