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

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

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

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

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