lib.rs 1.83 KB
Newer Older
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
1
/// Text Generation Inference Webserver
Olivier Dehaene's avatar
Olivier Dehaene committed
2
3
mod batcher;
mod db;
Olivier Dehaene's avatar
Olivier Dehaene committed
4
pub mod server;
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
5
mod validation;
Olivier Dehaene's avatar
Olivier Dehaene committed
6

7
use batcher::{Batcher, InferResponse};
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
8
9
use db::{Db, Entry};
use serde::{Deserialize, Serialize};
Olivier Dehaene's avatar
Olivier Dehaene committed
10
use validation::Validation;
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
11
12
13
14
15
16
17
18
19
20
21
22
23

#[derive(Clone, Debug, Deserialize)]
pub(crate) struct GenerateParameters {
    #[serde(default = "default_temperature")]
    pub temperature: f32,
    #[serde(default = "default_top_k")]
    pub top_k: i32,
    #[serde(default = "default_top_p")]
    pub top_p: f32,
    #[serde(default = "default_do_sample")]
    pub do_sample: bool,
    #[serde(default = "default_max_new_tokens")]
    pub max_new_tokens: u32,
OlivierDehaene's avatar
OlivierDehaene committed
24
    #[serde(default)]
25
    pub stop: Vec<String>,
OlivierDehaene's avatar
OlivierDehaene committed
26
27
    #[serde(default)]
    pub details: bool,
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
}

fn default_temperature() -> f32 {
    1.0
}

fn default_top_k() -> i32 {
    0
}

fn default_top_p() -> f32 {
    1.0
}

fn default_do_sample() -> bool {
    false
}

fn default_max_new_tokens() -> u32 {
    20
}

fn default_parameters() -> GenerateParameters {
    GenerateParameters {
        temperature: default_temperature(),
        top_k: default_top_k(),
        top_p: default_top_p(),
        do_sample: default_do_sample(),
        max_new_tokens: default_max_new_tokens(),
57
        stop: vec![],
OlivierDehaene's avatar
OlivierDehaene committed
58
        details: false,
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
59
60
61
62
63
64
65
66
67
68
    }
}

#[derive(Clone, Debug, Deserialize)]
pub(crate) struct GenerateRequest {
    pub inputs: String,
    #[serde(default = "default_parameters")]
    pub parameters: GenerateParameters,
}

OlivierDehaene's avatar
OlivierDehaene committed
69
70
71
72
73
74
75
#[derive(Serialize)]
pub(crate) struct Details {
    pub finish_reason: String,
    pub generated_tokens: u32,
    pub tokens: Vec<(u32, String, f32)>,
}

Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
76
77
78
#[derive(Serialize)]
pub(crate) struct GeneratedText {
    pub generated_text: String,
OlivierDehaene's avatar
OlivierDehaene committed
79
80
    #[serde(skip_serializing_if = "Option::is_none")]
    pub details: Option<Details>,
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
81
}
82
83
84
85
86

#[derive(Serialize)]
pub(crate) struct ErrorResponse {
    pub error: String,
}