2022-10-18 07:19:03 -06:00
|
|
|
//! Text Generation gRPC client library
|
2022-10-08 04:30:12 -06:00
|
|
|
|
|
|
|
mod client;
|
2022-10-18 07:19:03 -06:00
|
|
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
2022-10-08 04:30:12 -06:00
|
|
|
mod pb;
|
|
|
|
mod sharded_client;
|
|
|
|
|
|
|
|
pub use client::Client;
|
2023-12-11 04:46:30 -07:00
|
|
|
pub use pb::generate::v2::HealthResponse;
|
|
|
|
pub use pb::generate::v2::InfoResponse as ShardInfo;
|
|
|
|
pub use pb::generate::v2::{
|
2024-02-15 02:28:10 -07:00
|
|
|
Batch, CachedBatch, FinishReason, GeneratedText, Generation, GrammarType,
|
|
|
|
NextTokenChooserParameters, Request, StoppingCriteriaParameters, Tokens,
|
2022-12-12 10:25:22 -07:00
|
|
|
};
|
2022-10-08 04:30:12 -06:00
|
|
|
pub use sharded_client::ShardedClient;
|
|
|
|
use thiserror::Error;
|
2022-10-18 07:19:03 -06:00
|
|
|
use tonic::transport;
|
2022-10-08 04:30:12 -06:00
|
|
|
use tonic::Status;
|
|
|
|
|
|
|
|
#[derive(Error, Debug, Clone)]
|
2022-10-17 06:59:00 -06:00
|
|
|
pub enum ClientError {
|
2023-02-13 05:02:45 -07:00
|
|
|
#[error("Could not connect to Text Generation server: {0}")]
|
2022-10-17 06:59:00 -06:00
|
|
|
Connection(String),
|
2023-02-13 05:02:45 -07:00
|
|
|
#[error("Server error: {0}")]
|
2022-10-17 06:59:00 -06:00
|
|
|
Generation(String),
|
2023-05-10 07:48:21 -06:00
|
|
|
#[error("Sharded results are empty")]
|
|
|
|
EmptyResults,
|
2022-10-08 04:30:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Status> for ClientError {
|
|
|
|
fn from(err: Status) -> Self {
|
2023-02-13 05:02:45 -07:00
|
|
|
let err = Self::Generation(err.message().to_string());
|
|
|
|
tracing::error!("{err}");
|
|
|
|
err
|
2022-10-17 06:59:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<transport::Error> for ClientError {
|
|
|
|
fn from(err: transport::Error) -> Self {
|
2023-02-13 05:02:45 -07:00
|
|
|
let err = Self::Connection(err.to_string());
|
|
|
|
tracing::error!("{err}");
|
|
|
|
err
|
2022-10-08 04:30:12 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, ClientError>;
|