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

40
src/error.rs Normal file
View File

@@ -0,0 +1,40 @@
use std::fmt::Display;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Env(std::env::VarError),
HttpClient(reqwest::Error),
Token(gcp_auth::Error),
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self {
Error::Env(e) => write!(f, "Environment variable error: {}", e),
Error::HttpClient(e) => write!(f, "HTTP Client error: {}", e),
Error::Token(e) => write!(f, "Token error: {}", e),
}
}
}
impl std::error::Error for Error {}
impl From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Self {
Error::HttpClient(e)
}
}
impl From<std::env::VarError> for Error {
fn from(e: std::env::VarError) -> Self {
Error::Env(e)
}
}
impl From<gcp_auth::Error> for Error {
fn from(e: gcp_auth::Error) -> Self {
Error::Token(e)
}
}