use crate::
{
client ::Client,
error ::Error,
models ::
{
GenerateContentRequest,
batch ::*,
},
};
use std::time::{ Duration, SystemTime };
#[ derive( Debug ) ]
pub struct BatchApi
{
}
impl BatchApi
{
#[ inline ]
pub fn new( _client : &Client ) -> Self
{
Self {}
}
pub async fn create_inline(
&self,
model : &str,
requests : Vec< GenerateContentRequest >
) -> Result< BatchJob, Error >
{
let _ = ( model, requests );
Err( Error::NotImplemented( "Batch Mode API endpoints not yet available from Gemini".to_string() ) )
}
pub async fn get_status( &self, job_id : &str ) -> Result< BatchJobStatus, Error >
{
let _ = job_id;
Err( Error::NotImplemented( "Batch Mode API endpoints not yet available from Gemini".to_string() ) )
}
pub async fn wait_and_retrieve(
&self,
job_id : &str,
timeout : Duration
) -> Result< BatchJobResults, Error >
{
let start = SystemTime::now();
let poll_interval = Duration::from_secs( 5 );
loop
{
let status = self.get_status( job_id ).await?;
match status.state
{
BatchJobState::Succeeded | BatchJobState::PartiallyCompleted =>
{
return self.retrieve_results( job_id ).await;
}
BatchJobState::Failed =>
{
return Err( Error::ApiError(
status.error.unwrap_or_else( || "Batch job failed".to_string() )
) );
}
BatchJobState::Cancelled =>
{
return Err( Error::ApiError( "Batch job was cancelled".to_string() ) );
}
BatchJobState::Pending | BatchJobState::Running =>
{
if start.elapsed().unwrap_or( Duration::ZERO ) > timeout
{
return Err( Error::ApiError( "Batch job timeout".to_string() ) );
}
tokio ::time::sleep( poll_interval ).await;
}
}
}
}
async fn retrieve_results( &self, job_id : &str ) -> Result< BatchJobResults, Error >
{
let _ = job_id;
Err( Error::NotImplemented( "Batch Mode API endpoints not yet available from Gemini".to_string() ) )
}
pub async fn cancel( &self, job_id : &str ) -> Result< (), Error >
{
let _ = job_id;
Err( Error::NotImplemented( "Batch Mode API endpoints not yet available from Gemini".to_string() ) )
}
pub async fn list( &self ) -> Result< BatchJobList, Error >
{
self.list_with_page_size( None, None ).await
}
pub async fn list_with_token( &self, page_token : &str ) -> Result< BatchJobList, Error >
{
self.list_with_page_size( None, Some( page_token.to_string() ) ).await
}
async fn list_with_page_size(
&self,
_page_size : Option< i32 >,
_page_token : Option< String >
) -> Result< BatchJobList, Error >
{
Err( Error::NotImplemented( "Batch Mode API endpoints not yet available from Gemini".to_string() ) )
}
pub async fn create_embedding_batch(
&self,
model : &str,
texts : Vec< String >
) -> Result< BatchJob, Error >
{
let _ = ( model, texts );
Err( Error::NotImplemented( "Batch Mode API endpoints not yet available from Gemini".to_string() ) )
}
pub async fn wait_and_retrieve_embeddings(
&self,
job_id : &str,
timeout : Duration
) -> Result< BatchEmbeddingResults, Error >
{
let start = SystemTime::now();
let poll_interval = Duration::from_secs( 5 );
loop
{
let status = self.get_status( job_id ).await?;
match status.state
{
BatchJobState::Succeeded | BatchJobState::PartiallyCompleted =>
{
return self.retrieve_embedding_results( job_id ).await;
}
BatchJobState::Failed =>
{
return Err( Error::ApiError(
status.error.unwrap_or_else( || "Batch job failed".to_string() )
) );
}
BatchJobState::Cancelled =>
{
return Err( Error::ApiError( "Batch job was cancelled".to_string() ) );
}
BatchJobState::Pending | BatchJobState::Running =>
{
if start.elapsed().unwrap_or( Duration::ZERO ) > timeout
{
return Err( Error::ApiError( "Batch job timeout".to_string() ) );
}
tokio ::time::sleep( poll_interval ).await;
}
}
}
}
async fn retrieve_embedding_results( &self, job_id : &str ) -> Result< BatchEmbeddingResults, Error >
{
let _ = job_id;
Err( Error::NotImplemented( "Batch Mode API endpoints not yet available from Gemini".to_string() ) )
}
}