lib.rs 879 Bytes
Newer Older
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
1
//! Text Generation gRPC client library
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
2
3

mod client;
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
4
#[allow(clippy::derive_partial_eq_without_eq)]
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
5
6
7
8
mod pb;
mod sharded_client;

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

#[derive(Error, Debug, Clone)]
Olivier Dehaene's avatar
Olivier Dehaene committed
16
17
18
19
20
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
21
22
23
24
}

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

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
32
33
34
35
    }
}

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