2023-02-02 06:59:27 -07:00
|
|
|
/// Text Generation Inference Webserver
|
2023-02-02 07:02:04 -07:00
|
|
|
|
|
|
|
mod infer;
|
2023-02-02 06:59:27 -07:00
|
|
|
mod queue;
|
2022-10-17 10:27:33 -06:00
|
|
|
pub mod server;
|
2022-10-18 07:19:03 -06:00
|
|
|
mod validation;
|
2022-10-17 06:59:00 -06:00
|
|
|
|
2023-01-31 09:04:00 -07:00
|
|
|
use infer::Infer;
|
2023-02-02 06:59:27 -07:00
|
|
|
use queue::{Entry, Queue};
|
2022-10-18 07:19:03 -06:00
|
|
|
use serde::{Deserialize, Serialize};
|
2022-10-17 06:59:00 -06:00
|
|
|
use validation::Validation;
|
2022-10-18 07:19:03 -06:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
|
pub(crate) struct GenerateParameters {
|
|
|
|
#[serde(default = "default_temperature")]
|
|
|
|
pub temperature: f32,
|
2023-02-01 07:58:42 -07:00
|
|
|
#[serde(default = "default_repetition_penalty")]
|
|
|
|
pub repetition_penalty: f32,
|
2022-10-18 07:19:03 -06:00
|
|
|
#[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,
|
2022-12-15 09:03:56 -07:00
|
|
|
#[serde(default)]
|
2022-12-12 10:25:22 -07:00
|
|
|
pub stop: Vec<String>,
|
2022-12-15 09:03:56 -07:00
|
|
|
#[serde(default)]
|
|
|
|
pub details: bool,
|
2023-01-30 07:36:16 -07:00
|
|
|
#[serde(default)]
|
|
|
|
pub seed: Option<u64>,
|
2022-10-18 07:19:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn default_temperature() -> f32 {
|
|
|
|
1.0
|
|
|
|
}
|
2023-02-01 07:58:42 -07:00
|
|
|
fn default_repetition_penalty() -> f32 {
|
|
|
|
1.0
|
|
|
|
}
|
2022-10-18 07:19:03 -06:00
|
|
|
|
|
|
|
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(),
|
2023-02-01 07:58:42 -07:00
|
|
|
repetition_penalty: default_repetition_penalty(),
|
2022-10-18 07:19:03 -06:00
|
|
|
top_k: default_top_k(),
|
|
|
|
top_p: default_top_p(),
|
|
|
|
do_sample: default_do_sample(),
|
|
|
|
max_new_tokens: default_max_new_tokens(),
|
2022-12-12 10:25:22 -07:00
|
|
|
stop: vec![],
|
2022-12-15 09:03:56 -07:00
|
|
|
details: false,
|
2023-01-30 07:36:16 -07:00
|
|
|
seed: None,
|
2022-10-18 07:19:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
|
|
pub(crate) struct GenerateRequest {
|
|
|
|
pub inputs: String,
|
|
|
|
#[serde(default = "default_parameters")]
|
|
|
|
pub parameters: GenerateParameters,
|
|
|
|
}
|
|
|
|
|
2023-01-31 09:04:00 -07:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct Token(u32, String, f32);
|
|
|
|
|
2022-12-15 09:03:56 -07:00
|
|
|
#[derive(Serialize)]
|
|
|
|
pub(crate) struct Details {
|
|
|
|
pub finish_reason: String,
|
|
|
|
pub generated_tokens: u32,
|
2023-01-30 07:36:16 -07:00
|
|
|
pub seed: Option<u64>,
|
2023-01-31 09:04:00 -07:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub prefill: Option<Vec<Token>>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub tokens: Option<Vec<Token>>,
|
2022-12-15 09:03:56 -07:00
|
|
|
}
|
|
|
|
|
2022-10-18 07:19:03 -06:00
|
|
|
#[derive(Serialize)]
|
2023-01-31 09:04:00 -07:00
|
|
|
pub(crate) struct GenerateResponse {
|
2022-10-18 07:19:03 -06:00
|
|
|
pub generated_text: String,
|
2022-12-15 09:03:56 -07:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub details: Option<Details>,
|
2022-10-18 07:19:03 -06:00
|
|
|
}
|
2022-10-27 06:25:29 -06:00
|
|
|
|
2023-01-31 09:04:00 -07:00
|
|
|
#[derive(Serialize)]
|
|
|
|
pub(crate) struct StreamResponse {
|
|
|
|
pub token: Token,
|
|
|
|
pub generated_text: Option<String>,
|
|
|
|
pub details: Option<Details>,
|
|
|
|
}
|
|
|
|
|
2022-10-27 06:25:29 -06:00
|
|
|
#[derive(Serialize)]
|
|
|
|
pub(crate) struct ErrorResponse {
|
|
|
|
pub error: String,
|
|
|
|
}
|