lib.rs 19.5 KB
Newer Older
1
mod health;
2
/// Text Generation Inference Webserver
3
mod infer;
4
mod queue;
Olivier Dehaene's avatar
Olivier Dehaene committed
5
pub mod server;
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
6
mod validation;
Olivier Dehaene's avatar
Olivier Dehaene committed
7

8
use infer::{Infer, InferError, InferStreamResponse};
9
use queue::{Entry, Queue};
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
10
use serde::{Deserialize, Serialize};
11
12
use tokio::sync::OwnedSemaphorePermit;
use tokio_stream::wrappers::UnboundedReceiverStream;
13
use utoipa::ToSchema;
Olivier Dehaene's avatar
Olivier Dehaene committed
14
use validation::Validation;
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
15

16
17
18
19
20
21
22
/// Type alias for generation responses
pub(crate) type GenerateStreamResponse = (
    OwnedSemaphorePermit,
    u32, // input_length
    UnboundedReceiverStream<Result<InferStreamResponse, InferError>>,
);

23
24
/// Hub type
#[derive(Clone, Debug, Deserialize)]
25
pub struct HubModelInfo {
26
27
28
29
30
31
    #[serde(rename(deserialize = "id"))]
    pub model_id: String,
    pub sha: Option<String>,
    pub pipeline_tag: Option<String>,
}

32
33
34
#[derive(Clone, Deserialize, Default)]
pub struct HubTokenizerConfig {
    pub chat_template: Option<String>,
35
36
    pub bos_token: Option<String>,
    pub eos_token: Option<String>,
37
38
39
}

impl HubTokenizerConfig {
40
    pub fn from_file(filename: &std::path::Path) -> Self {
41
42
43
44
45
        let content = std::fs::read_to_string(filename).unwrap();
        serde_json::from_str(&content).unwrap_or_default()
    }
}

46
47
#[derive(Clone, Debug, Serialize, ToSchema)]
pub struct Info {
48
    /// Model info
49
50
51
52
    #[schema(example = "bigscience/blomm-560m")]
    pub model_id: String,
    #[schema(nullable = true, example = "e985a63cdc139290c5f700ff1929f0b5942cced2")]
    pub model_sha: Option<String>,
53
54
55
56
    #[schema(example = "torch.float16")]
    pub model_dtype: String,
    #[schema(example = "cuda")]
    pub model_device_type: String,
57
58
    #[schema(nullable = true, example = "text-generation")]
    pub model_pipeline_tag: Option<String>,
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    /// Router Parameters
    #[schema(example = "128")]
    pub max_concurrent_requests: usize,
    #[schema(example = "2")]
    pub max_best_of: usize,
    #[schema(example = "4")]
    pub max_stop_sequences: usize,
    #[schema(example = "1024")]
    pub max_input_length: usize,
    #[schema(example = "2048")]
    pub max_total_tokens: usize,
    #[schema(example = "1.2")]
    pub waiting_served_ratio: f32,
    #[schema(example = "32000")]
    pub max_batch_total_tokens: u32,
    #[schema(example = "20")]
    pub max_waiting_tokens: usize,
76
77
    #[schema(nullable = true, example = "null")]
    pub max_batch_size: Option<usize>,
78
79
80
    #[schema(example = "2")]
    pub validation_workers: usize,
    /// Router Info
81
82
83
84
    #[schema(example = "0.5.0")]
    pub version: &'static str,
    #[schema(nullable = true, example = "null")]
    pub sha: Option<&'static str>,
85
86
    #[schema(nullable = true, example = "null")]
    pub docker_label: Option<&'static str>,
87
88
}

89
#[derive(Clone, Debug, Deserialize, ToSchema)]
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
90
pub(crate) struct GenerateParameters {
91
92
93
    #[serde(default)]
    #[schema(exclusive_minimum = 0, nullable = true, default = "null", example = 1)]
    pub best_of: Option<usize>,
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    #[serde(default)]
    #[schema(
        exclusive_minimum = 0.0,
        nullable = true,
        default = "null",
        example = 0.5
    )]
    pub temperature: Option<f32>,
    #[serde(default)]
    #[schema(
        exclusive_minimum = 0.0,
        nullable = true,
        default = "null",
        example = 1.03
    )]
    pub repetition_penalty: Option<f32>,
    #[serde(default)]
111
112
113
114
115
116
117
118
    #[schema(
        exclusive_minimum = -2.0,
        nullable = true,
        default = "null",
        example = 0.1
    )]
    pub frequency_penalty: Option<f32>,
    #[serde(default)]
119
120
121
122
123
124
125
126
127
128
129
    #[schema(exclusive_minimum = 0, nullable = true, default = "null", example = 10)]
    pub top_k: Option<i32>,
    #[serde(default)]
    #[schema(
        exclusive_minimum = 0.0,
        maximum = 1.0,
        nullable = true,
        default = "null",
        example = 0.95
    )]
    pub top_p: Option<f32>,
130
    #[serde(default)]
131
132
133
134
135
136
137
138
139
    #[schema(
        exclusive_minimum = 0.0,
        maximum = 1.0,
        nullable = true,
        default = "null",
        example = 0.95
    )]
    pub typical_p: Option<f32>,
    #[serde(default)]
140
    #[schema(default = "false", example = true)]
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
141
142
    pub do_sample: bool,
    #[serde(default = "default_max_new_tokens")]
143
    #[schema(nullable = true, default = "100", example = "20")]
144
    pub max_new_tokens: Option<u32>,
OlivierDehaene's avatar
OlivierDehaene committed
145
    #[serde(default)]
146
    #[schema(nullable = true, default = "null", example = false)]
147
148
    pub return_full_text: Option<bool>,
    #[serde(default)]
149
    #[schema(inline, max_items = 4, example = json ! (["photographer"]))]
150
    pub stop: Vec<String>,
OlivierDehaene's avatar
OlivierDehaene committed
151
    #[serde(default)]
152
    #[schema(nullable = true, default = "null", example = "null")]
153
154
    pub truncate: Option<usize>,
    #[serde(default)]
155
156
157
    #[schema(default = "false", example = true)]
    pub watermark: bool,
    #[serde(default)]
158
    #[schema(default = "true")]
OlivierDehaene's avatar
OlivierDehaene committed
159
    pub details: bool,
160
    #[serde(default)]
161
162
163
    #[schema(default = "true")]
    pub decoder_input_details: bool,
    #[serde(default)]
164
165
166
167
168
169
    #[schema(
        exclusive_minimum = 0,
        nullable = true,
        default = "null",
        example = "null"
    )]
170
    pub seed: Option<u64>,
Nicolas Patry's avatar
Nicolas Patry committed
171
172
173
    #[serde(default)]
    #[schema(exclusive_minimum = 0, nullable = true, default = "null", example = 5)]
    pub top_n_tokens: Option<u32>,
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
174
175
}

176
fn default_max_new_tokens() -> Option<u32> {
177
    Some(100)
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
178
179
180
181
}

fn default_parameters() -> GenerateParameters {
    GenerateParameters {
182
        best_of: None,
183
184
        temperature: None,
        repetition_penalty: None,
185
        frequency_penalty: None,
186
187
        top_k: None,
        top_p: None,
188
        typical_p: None,
189
        do_sample: true,
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
190
        max_new_tokens: default_max_new_tokens(),
191
        return_full_text: None,
192
        stop: Vec::new(),
193
        truncate: None,
194
        watermark: false,
OlivierDehaene's avatar
OlivierDehaene committed
195
        details: false,
196
        decoder_input_details: false,
197
        seed: None,
Nicolas Patry's avatar
Nicolas Patry committed
198
        top_n_tokens: None,
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
199
200
201
    }
}

202
#[derive(Clone, Deserialize, Serialize, ToSchema)]
203
204
205
pub(crate) struct ChatCompletion {
    pub id: String,
    pub object: String,
206
    #[schema(example = "1706270835")]
207
    pub created: u64,
208
    #[schema(example = "mistralai/Mistral-7B-Instruct-v0.2")]
209
210
211
212
213
214
    pub model: String,
    pub system_fingerprint: String,
    pub choices: Vec<ChatCompletionComplete>,
    pub usage: Usage,
}

215
#[derive(Clone, Deserialize, Serialize, ToSchema)]
216
217
218
pub(crate) struct ChatCompletionComplete {
    pub index: u32,
    pub message: Message,
219
    pub logprobs: Option<ChatCompletionLogprobs>,
220
221
222
    pub finish_reason: String,
}

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#[derive(Clone, Deserialize, Serialize, ToSchema)]
pub(crate) struct ChatCompletionLogprobs {
    content: Vec<ChatCompletionLogprob>,
}

impl From<(Token, Vec<Token>)> for ChatCompletionLogprobs {
    fn from(value: (Token, Vec<Token>)) -> Self {
        let (token, top_tokens) = value;

        Self {
            content: vec![ChatCompletionLogprob {
                token: token.text,
                logprob: token.logprob,
                top_logprobs: top_tokens
                    .into_iter()
                    .map(|t| ChatCompletionTopLogprob {
                        token: t.text,
                        logprob: t.logprob,
                    })
                    .collect(),
            }],
        }
    }
}

impl From<(Vec<Token>, Vec<Vec<Token>>)> for ChatCompletionLogprobs {
    fn from(value: (Vec<Token>, Vec<Vec<Token>>)) -> Self {
        let (tokens, top_tokens) = value;
        Self {
            content: tokens
                .into_iter()
                .zip(top_tokens)
                .map(|(t, top_t)| ChatCompletionLogprob {
                    token: t.text,
                    logprob: t.logprob,
                    top_logprobs: top_t
                        .into_iter()
                        .map(|t| ChatCompletionTopLogprob {
                            token: t.text,
                            logprob: t.logprob,
                        })
                        .collect(),
                })
                .collect(),
        }
    }
}

#[derive(Clone, Deserialize, Serialize, ToSchema)]
pub(crate) struct ChatCompletionLogprob {
    token: String,
    logprob: f32,
    top_logprobs: Vec<ChatCompletionTopLogprob>,
}

#[derive(Clone, Deserialize, Serialize, ToSchema)]
pub(crate) struct ChatCompletionTopLogprob {
    token: String,
    logprob: f32,
}

284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#[derive(Clone, Deserialize, Serialize)]
pub(crate) struct Usage {
    pub prompt_tokens: u32,
    pub completion_tokens: u32,
    pub total_tokens: u32,
}

impl ChatCompletion {
    pub(crate) fn new(
        model: String,
        system_fingerprint: String,
        output: String,
        created: u64,
        details: Details,
        return_logprobs: bool,
    ) -> Self {
        Self {
            id: String::new(),
            object: "text_completion".into(),
            created,
            model,
            system_fingerprint,
            choices: vec![ChatCompletionComplete {
                index: 0,
                message: Message {
                    role: "assistant".into(),
                    content: output,
                },
                logprobs: return_logprobs
313
                    .then(|| ChatCompletionLogprobs::from((details.tokens, details.top_tokens))),
314
315
316
317
318
319
320
321
322
323
324
                finish_reason: details.finish_reason.to_string(),
            }],
            usage: Usage {
                prompt_tokens: details.prefill.len() as u32,
                completion_tokens: details.generated_tokens,
                total_tokens: details.prefill.len() as u32 + details.generated_tokens,
            },
        }
    }
}

325
#[derive(Clone, Deserialize, Serialize, ToSchema)]
326
327
328
pub(crate) struct ChatCompletionChunk {
    pub id: String,
    pub object: String,
329
    #[schema(example = "1706270978")]
330
    pub created: u64,
331
    #[schema(example = "mistralai/Mistral-7B-Instruct-v0.2")]
332
333
334
335
336
    pub model: String,
    pub system_fingerprint: String,
    pub choices: Vec<ChatCompletionChoice>,
}

337
#[derive(Clone, Deserialize, Serialize, ToSchema)]
338
339
340
pub(crate) struct ChatCompletionChoice {
    pub index: u32,
    pub delta: ChatCompletionDelta,
341
    pub logprobs: Option<ChatCompletionLogprobs>,
342
343
344
    pub finish_reason: Option<String>,
}

345
#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
346
pub(crate) struct ChatCompletionDelta {
347
    #[schema(example = "user")]
348
    pub role: String,
349
    #[schema(example = "What is Deep Learning?")]
350
351
352
353
354
355
356
357
358
359
    pub content: String,
}

impl ChatCompletionChunk {
    pub(crate) fn new(
        model: String,
        system_fingerprint: String,
        delta: String,
        created: u64,
        index: u32,
360
        logprobs: Option<ChatCompletionLogprobs>,
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
        finish_reason: Option<String>,
    ) -> Self {
        Self {
            id: String::new(),
            object: "text_completion".to_string(),
            created,
            model,
            system_fingerprint,
            choices: vec![ChatCompletionChoice {
                index,
                delta: ChatCompletionDelta {
                    role: "assistant".to_string(),
                    content: delta,
                },
                logprobs,
                finish_reason,
            }],
        }
    }
}

fn default_request_messages() -> Vec<Message> {
    vec![Message {
        role: "user".to_string(),
        content: "My name is David and I".to_string(),
    }]
}

#[derive(Clone, Deserialize, ToSchema, Serialize)]
pub(crate) struct ChatRequest {
    /// UNUSED
392
    #[schema(example = "mistralai/Mistral-7B-Instruct-v0.2")]
393
    /// ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API.
394
395
    pub model: String,
    /* NOTE: UNUSED */
396
397
398
399
400
401
402
    /// A list of messages comprising the conversation so far.
    #[serde(default = "default_request_messages")]
    pub messages: Vec<Message>,

    /// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far,
    /// decreasing the model's likelihood to repeat the same line verbatim.
    #[serde(default)]
403
    #[schema(example = "1.0")]
404
405
406
407
408
409
410
411
412
413
414
415
416
417
    pub frequency_penalty: Option<f32>,

    /// UNUSED
    /// Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens
    /// (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically,
    /// the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model,
    /// but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should
    /// result in a ban or exclusive selection of the relevant token.
    #[serde(default)]
    pub logit_bias: Option<Vec<f32>>,

    /// Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each
    /// output token returned in the content of message.
    #[serde(default)]
418
    #[schema(example = "false")]
419
420
421
422
423
    pub logprobs: Option<bool>,

    /// An integer between 0 and 5 specifying the number of most likely tokens to return at each token position, each with
    /// an associated log probability. logprobs must be set to true if this parameter is used.
    #[serde(default)]
424
    #[schema(example = "5")]
425
426
427
428
    pub top_logprobs: Option<u32>,

    /// The maximum number of tokens that can be generated in the chat completion.
    #[serde(default)]
429
    #[schema(example = "32")]
430
431
432
433
434
435
    pub max_tokens: Option<u32>,

    /// UNUSED
    /// How many chat completion choices to generate for each input message. Note that you will be charged based on the
    /// number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
    #[serde(default)]
436
    #[schema(nullable = true, example = "2")]
437
438
439
440
441
    pub n: Option<u32>,

    /// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far,
    /// increasing the model's likelihood to talk about new topics
    #[serde(default)]
442
    #[schema(nullable = true, example = 0.1)]
443
444
445
446
447
448
449
    pub presence_penalty: Option<f32>,

    #[serde(default = "bool::default")]
    pub stream: bool,

    #[schema(nullable = true, example = 42)]
    pub seed: Option<u64>,
450
451
452
453
454
455

    /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while
    /// lower values like 0.2 will make it more focused and deterministic.
    ///
    /// We generally recommend altering this or `top_p` but not both.
    #[serde(default)]
456
    #[schema(nullable = true, example = 1.0)]
457
458
459
460
461
    pub temperature: Option<f32>,

    /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the
    /// tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
    #[serde(default)]
462
    #[schema(nullable = true, example = 0.95)]
463
    pub top_p: Option<f32>,
464
465
}

466
467
468
469
470
#[derive(Clone, Serialize, Deserialize)]
pub(crate) struct ChatTemplateInputs<'a> {
    messages: Vec<Message>,
    bos_token: Option<&'a str>,
    eos_token: Option<&'a str>,
471
    add_generation_prompt: bool,
472
473
}

474
475
476
477
478
479
480
481
#[derive(Clone, Deserialize, ToSchema, Serialize)]
pub(crate) struct Message {
    #[schema(example = "user")]
    pub role: String,
    #[schema(example = "My name is David and I")]
    pub content: String,
}

482
#[derive(Clone, Debug, Deserialize, ToSchema)]
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
483
pub(crate) struct GenerateRequest {
484
    #[schema(example = "My name is Olivier and I")]
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
485
486
487
488
489
    pub inputs: String,
    #[serde(default = "default_parameters")]
    pub parameters: GenerateParameters,
}

490
491
492
493
494
495
496
#[derive(Clone, Debug, Deserialize, ToSchema)]
pub(crate) struct CompatGenerateRequest {
    #[schema(example = "My name is Olivier and I")]
    pub inputs: String,
    #[serde(default = "default_parameters")]
    pub parameters: GenerateParameters,
    #[serde(default)]
OlivierDehaene's avatar
OlivierDehaene committed
497
    #[schema(default = "false")]
498
499
500
501
502
503
504
505
506
507
508
509
    pub stream: bool,
}

impl From<CompatGenerateRequest> for GenerateRequest {
    fn from(req: CompatGenerateRequest) -> Self {
        Self {
            inputs: req.inputs,
            parameters: req.parameters,
        }
    }
}

510
511
512
513
514
515
#[derive(Debug, Serialize, ToSchema)]
pub struct PrefillToken {
    #[schema(example = 0)]
    id: u32,
    #[schema(example = "test")]
    text: String,
516
    #[schema(nullable = true, example = - 0.34)]
517
518
519
    logprob: f32,
}

520
#[derive(Debug, Serialize, ToSchema, Clone)]
521
522
523
524
525
pub struct Token {
    #[schema(example = 0)]
    id: u32,
    #[schema(example = "test")]
    text: String,
526
    #[schema(nullable = true, example = - 0.34)]
527
    logprob: f32,
528
529
    #[schema(example = "false")]
    special: bool,
530
531
}

532
533
534
535
536
537
538
539
540
541
542
543
#[derive(Debug, Serialize, ToSchema)]
pub struct SimpleToken {
    #[schema(example = 0)]
    id: u32,
    #[schema(example = "test")]
    text: String,
    #[schema(example = 0)]
    start: usize,
    #[schema(example = 2)]
    stop: usize,
}

544
545
#[derive(Serialize, ToSchema)]
#[serde(rename_all(serialize = "snake_case"))]
546
#[schema(example = "Length")]
547
548
549
550
551
552
553
554
555
pub(crate) enum FinishReason {
    #[schema(rename = "length")]
    Length,
    #[serde(rename = "eos_token")]
    #[schema(rename = "eos_token")]
    EndOfSequenceToken,
    #[schema(rename = "stop_sequence")]
    StopSequence,
}
556

557
558
559
560
561
562
563
564
565
566
impl std::fmt::Display for FinishReason {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            FinishReason::Length => write!(f, "length"),
            FinishReason::EndOfSequenceToken => write!(f, "eos_token"),
            FinishReason::StopSequence => write!(f, "stop_sequence"),
        }
    }
}

567
568
569
570
571
572
573
574
575
576
577
578
#[derive(Serialize, ToSchema)]
pub(crate) struct BestOfSequence {
    #[schema(example = "test")]
    pub generated_text: String,
    #[schema(example = "length")]
    pub finish_reason: FinishReason,
    #[schema(example = 1)]
    pub generated_tokens: u32,
    #[schema(nullable = true, example = 42)]
    pub seed: Option<u64>,
    pub prefill: Vec<PrefillToken>,
    pub tokens: Vec<Token>,
Nicolas Patry's avatar
Nicolas Patry committed
579
580
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub top_tokens: Vec<Vec<Token>>,
581
582
}

583
#[derive(Serialize, ToSchema)]
OlivierDehaene's avatar
OlivierDehaene committed
584
pub(crate) struct Details {
585
586
587
    #[schema(example = "length")]
    pub finish_reason: FinishReason,
    #[schema(example = 1)]
OlivierDehaene's avatar
OlivierDehaene committed
588
    pub generated_tokens: u32,
589
    #[schema(nullable = true, example = 42)]
590
    pub seed: Option<u64>,
591
592
    pub prefill: Vec<PrefillToken>,
    pub tokens: Vec<Token>,
593
594
    #[serde(skip_serializing_if = "Option::is_none")]
    pub best_of_sequences: Option<Vec<BestOfSequence>>,
Nicolas Patry's avatar
Nicolas Patry committed
595
596
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub top_tokens: Vec<Vec<Token>>,
OlivierDehaene's avatar
OlivierDehaene committed
597
598
}

599
#[derive(Serialize, ToSchema)]
600
pub(crate) struct GenerateResponse {
601
    #[schema(example = "test")]
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
602
    pub generated_text: String,
OlivierDehaene's avatar
OlivierDehaene committed
603
604
    #[serde(skip_serializing_if = "Option::is_none")]
    pub details: Option<Details>,
Olivier Dehaene's avatar
v0.1.0  
Olivier Dehaene committed
605
}
606

607
608
609
610
#[derive(Serialize, ToSchema)]
#[serde(transparent)]
pub(crate) struct TokenizeResponse(Vec<SimpleToken>);

611
612
613
614
615
616
#[derive(Serialize, ToSchema)]
pub(crate) struct StreamDetails {
    #[schema(example = "length")]
    pub finish_reason: FinishReason,
    #[schema(example = 1)]
    pub generated_tokens: u32,
617
    #[schema(nullable = true, example = 42)]
618
619
620
621
    pub seed: Option<u64>,
}

#[derive(Serialize, ToSchema)]
622
pub(crate) struct StreamResponse {
623
    pub index: u32,
624
    pub token: Token,
Nicolas Patry's avatar
Nicolas Patry committed
625
626
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub top_tokens: Vec<Token>,
627
    #[schema(nullable = true, default = "null", example = "test")]
628
    pub generated_text: Option<String>,
629
630
    #[schema(nullable = true, default = "null")]
    pub details: Option<StreamDetails>,
631
632
}

633
#[derive(Serialize, ToSchema)]
634
635
pub(crate) struct ErrorResponse {
    pub error: String,
636
    pub error_type: String,
637
}
638
639

#[cfg(test)]
640
mod tests {
641
642
    use tokenizers::Tokenizer;

643
    pub(crate) async fn get_tokenizer() -> Tokenizer {
644
645
646
647
        let api = hf_hub::api::sync::Api::new().unwrap();
        let repo = api.model("gpt2".to_string());
        let filename = repo.get("tokenizer.json").unwrap();
        Tokenizer::from_file(filename).unwrap()
648
649
    }
}