feat: add SSE streaming, thinking models, and modernized Part struct
Some checks failed
Rust / build (push) Has been cancelled

This commit is contained in:
2026-09-20 16:42:55 +01:00
parent ad82fc712b
commit 494aab6d14
18 changed files with 703 additions and 696 deletions

View File

@@ -1,90 +1,71 @@
use std::fmt::Display;
use reqwest_eventsource::CannotCloneRequestError;
use crate::types;
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),
Serde(serde_json::Error),
VertexError(types::VertexApiError),
NoCandidatesError,
CannotCloneRequestError(CannotCloneRequestError),
EventSourceError(reqwest_eventsource::Error),
EventSourceClosedError,
}
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),
Error::Serde(e) => write!(f, "Serde error: {}", e),
Error::VertexError(e) => {
write!(f, "Vertex error: {}", e)
}
Error::NoCandidatesError => {
write!(f, "No candidates returned for the prompt")
}
Error::CannotCloneRequestError(e) => {
write!(f, "Cannot clone request: {}", e)
}
Error::EventSourceError(e) => {
write!(f, "EventSourrce Error: {}", e)
}
Error::EventSourceClosedError => {
write!(f, "EventSource closed error")
}
}
}
}
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)
}
}
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
}
}
impl From<types::VertexApiError> for Error {
fn from(e: types::VertexApiError) -> Self {
Error::VertexError(e)
}
}
impl From<CannotCloneRequestError> for Error {
fn from(e: CannotCloneRequestError) -> Self {
Error::CannotCloneRequestError(e)
}
}
impl From<reqwest_eventsource::Error> for Error {
fn from(e: reqwest_eventsource::Error) -> Self {
Error::EventSourceError(e)
}
}
use std::fmt::Display;
use tokio_util::codec::LinesCodecError;
use crate::types;
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),
Serde(serde_json::Error),
VertexError(types::VertexApiError),
NoCandidatesError,
/// An error occurred while decoding the SSE event stream.
EventSourceError(LinesCodecError),
}
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}"),
Error::Serde(e) => write!(f, "Serde error: {e}"),
Error::VertexError(e) => write!(f, "Vertex error: {e}"),
Error::NoCandidatesError => write!(f, "No candidates returned for the prompt"),
Error::EventSourceError(e) => write!(f, "EventSource 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<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::Serde(e)
}
}
impl From<gcp_auth::Error> for Error {
fn from(e: gcp_auth::Error) -> Self {
Error::Token(e)
}
}
impl From<types::VertexApiError> for Error {
fn from(e: types::VertexApiError) -> Self {
Error::VertexError(e)
}
}
impl From<LinesCodecError> for Error {
fn from(e: LinesCodecError) -> Self {
Error::EventSourceError(e)
}
}