lib.rs 826 Bytes
Newer Older
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
1
2
3
4
5
6
7
//! BLOOM Inference gRPC client library

mod client;
mod pb;
mod sharded_client;

pub use client::Client;
Olivier Dehaene's avatar
Olivier Dehaene committed
8
pub use pb::generate::v1::{Batch, GeneratedText, LogitsWarperParameters, Request};
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
9
10
pub use sharded_client::ShardedClient;
use thiserror::Error;
Olivier Dehaene's avatar
Olivier Dehaene committed
11
pub use tonic::transport;
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
12
13
14
use tonic::Status;

#[derive(Error, Debug, Clone)]
Olivier Dehaene's avatar
Olivier Dehaene committed
15
16
17
18
19
pub enum ClientError {
    #[error("Could not connect to Text Generation server: {0:?}")]
    Connection(String),
    #[error("Server error: {0:?}")]
    Generation(String),
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
20
21
22
23
}

impl From<Status> for ClientError {
    fn from(err: Status) -> Self {
Olivier Dehaene's avatar
Olivier Dehaene committed
24
25
26
27
28
29
30
        Self::Generation(err.to_string())
    }
}

impl From<transport::Error> for ClientError {
    fn from(err: transport::Error) -> Self {
        Self::Connection(err.to_string())
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
31
32
33
34
    }
}

pub type Result<T> = std::result::Result<T, ClientError>;