Add base code and examples for the Vertex API

- Add base code for the Vertex API with types and a client with helper
  methods for prompting text and conversation.
- Add examples for prompting text and conversation.
This commit is contained in:
2024-02-06 20:50:36 +00:00
parent 995d2537b9
commit 67c6ba878b
10 changed files with 530 additions and 9 deletions

28
src/token_provider.rs Normal file
View File

@@ -0,0 +1,28 @@
use std::sync::Arc;
use gcp_auth::AuthenticationManager;
use crate::error::Result;
pub trait TokenProvider {
fn get_token(&self, scope: &[&str])
-> impl std::future::Future<Output = Result<String>> + Send;
}
impl TokenProvider for Arc<AuthenticationManager> {
async fn get_token(&self, scope: &[&str]) -> Result<String> {
match AuthenticationManager::get_token(self, scope).await {
Ok(token) => Ok(token.as_str().to_string()),
Err(e) => Err(e.into()),
}
}
}
impl TokenProvider for AuthenticationManager {
async fn get_token(&self, scope: &[&str]) -> Result<String> {
match AuthenticationManager::get_token(self, scope).await {
Ok(token) => Ok(token.as_str().to_string()),
Err(e) => Err(e.into()),
}
}
}