lib.rs 918 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;
9
pub use pb::generate::v1::{
10
    Batch, GeneratedText, NextTokenChooserParameters, Request, StoppingCriteriaParameters,
11
};
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
12
13
pub use sharded_client::ShardedClient;
use thiserror::Error;
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
14
use tonic::transport;
Olivier Dehaene's avatar
Init  
Olivier Dehaene committed
15
16
17
use tonic::Status;

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

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

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
34
35
36
37
    }
}

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