pub mod studio;
#[cfg(feature = "vertex")]
pub mod vertex;
use crate::{
batch::model::{
BatchGenerateContentRequest, BatchGenerateContentResponse, ListBatchesResponse,
},
cache::model::{
CacheExpirationRequest, CachedContent, CreateCachedContentRequest,
ListCachedContentsResponse,
},
client::Error,
embedding::{
BatchContentEmbeddingResponse, BatchEmbedContentsRequest, ContentEmbeddingResponse,
EmbedContentRequest,
},
files::model::{File, ListFilesResponse},
generation::{GenerateContentRequest, GenerationResponse},
model_info::{ListModelsResponse, ModelInfo},
};
use async_trait::async_trait;
use futures::Stream;
use mime::Mime;
use std::pin::Pin;
pub type BackendStream<T> = Pin<Box<dyn Stream<Item = Result<T, Error>> + Send>>;
#[async_trait]
pub trait GeminiBackend: Send + Sync + std::fmt::Debug {
async fn generate_content(
&self,
request: GenerateContentRequest,
) -> Result<GenerationResponse, Error>;
async fn generate_content_stream(
&self,
request: GenerateContentRequest,
) -> Result<BackendStream<GenerationResponse>, Error>;
async fn embed_content(
&self,
request: EmbedContentRequest,
) -> Result<ContentEmbeddingResponse, Error>;
async fn batch_embed_contents(
&self,
_request: BatchEmbedContentsRequest,
) -> Result<BatchContentEmbeddingResponse, Error> {
Err(Error::GoogleCloudUnsupported { operation: "batchEmbedContents" })
}
async fn batch_generate_content(
&self,
_request: BatchGenerateContentRequest,
) -> Result<BatchGenerateContentResponse, Error> {
Err(Error::GoogleCloudUnsupported { operation: "batchGenerateContent" })
}
async fn get_batch_operation(&self, _name: &str) -> Result<serde_json::Value, Error> {
Err(Error::GoogleCloudUnsupported { operation: "getBatchOperation" })
}
async fn list_batch_operations(
&self,
_page_size: Option<u32>,
_page_token: Option<String>,
) -> Result<ListBatchesResponse, Error> {
Err(Error::GoogleCloudUnsupported { operation: "listBatchOperations" })
}
async fn cancel_batch_operation(&self, _name: &str) -> Result<(), Error> {
Err(Error::GoogleCloudUnsupported { operation: "cancelBatchOperation" })
}
async fn delete_batch_operation(&self, _name: &str) -> Result<(), Error> {
Err(Error::GoogleCloudUnsupported { operation: "deleteBatchOperation" })
}
async fn upload_file(
&self,
_display_name: Option<String>,
_file_bytes: Vec<u8>,
_mime_type: Mime,
) -> Result<File, Error> {
Err(Error::GoogleCloudUnsupported { operation: "uploadFile" })
}
async fn get_file(&self, _name: &str) -> Result<File, Error> {
Err(Error::GoogleCloudUnsupported { operation: "getFile" })
}
async fn download_file(&self, _name: &str) -> Result<Vec<u8>, Error> {
Err(Error::GoogleCloudUnsupported { operation: "downloadFile" })
}
async fn list_files(
&self,
_page_size: Option<u32>,
_page_token: Option<String>,
) -> Result<ListFilesResponse, Error> {
Err(Error::GoogleCloudUnsupported { operation: "listFiles" })
}
async fn delete_file(&self, _name: &str) -> Result<(), Error> {
Err(Error::GoogleCloudUnsupported { operation: "deleteFile" })
}
async fn create_cached_content(
&self,
_request: CreateCachedContentRequest,
) -> Result<CachedContent, Error> {
Err(Error::GoogleCloudUnsupported { operation: "createCachedContent" })
}
async fn get_cached_content(&self, _name: &str) -> Result<CachedContent, Error> {
Err(Error::GoogleCloudUnsupported { operation: "getCachedContent" })
}
async fn list_cached_contents(
&self,
_page_size: Option<i32>,
_page_token: Option<String>,
) -> Result<ListCachedContentsResponse, Error> {
Err(Error::GoogleCloudUnsupported { operation: "listCachedContents" })
}
async fn update_cached_content(
&self,
_name: &str,
_expiration: CacheExpirationRequest,
) -> Result<CachedContent, Error> {
Err(Error::GoogleCloudUnsupported { operation: "updateCachedContent" })
}
async fn delete_cached_content(&self, _name: &str) -> Result<(), Error> {
Err(Error::GoogleCloudUnsupported { operation: "deleteCachedContent" })
}
async fn list_models(
&self,
_page_size: Option<u32>,
_page_token: Option<String>,
) -> Result<ListModelsResponse, Error> {
Err(Error::GoogleCloudUnsupported { operation: "listModels" })
}
async fn get_model(&self, _name: &str) -> Result<ModelInfo, Error> {
Err(Error::GoogleCloudUnsupported { operation: "getModel" })
}
}