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:
28
src/token_provider.rs
Normal file
28
src/token_provider.rs
Normal 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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user