-
Notifications
You must be signed in to change notification settings - Fork 238
/
Copy pathlib.rs
129 lines (115 loc) · 3.26 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/// Text Embedding Inference Webserver
pub mod server;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(Clone, Debug, Serialize, ToSchema)]
pub struct Info {
/// Model info
#[schema(example = "thenlper/gte-base")]
pub model_id: String,
#[schema(nullable = true, example = "fca14538aa9956a46526bd1d0d11d69e19b5a101")]
pub model_sha: Option<String>,
#[schema(example = "float16")]
pub model_dtype: String,
#[schema(example = "cls")]
pub model_pooling: String,
/// Router Parameters
#[schema(example = "128")]
pub max_concurrent_requests: usize,
#[schema(example = "512")]
pub max_input_length: usize,
#[schema(example = "2048")]
pub max_batch_tokens: usize,
#[schema(nullable = true, example = "null", default = "null")]
pub max_batch_requests: Option<usize>,
#[schema(example = "32")]
pub max_client_batch_size: usize,
#[schema(example = "4")]
pub tokenization_workers: usize,
/// Router Info
#[schema(example = "0.5.0")]
pub version: &'static str,
#[schema(nullable = true, example = "null")]
pub sha: Option<&'static str>,
#[schema(nullable = true, example = "null")]
pub docker_label: Option<&'static str>,
}
#[derive(Deserialize, ToSchema)]
#[serde(untagged)]
pub(crate) enum Input {
Single(String),
Batch(Vec<String>),
}
#[derive(Deserialize, ToSchema)]
pub(crate) struct OpenAICompatRequest {
pub input: Input,
#[allow(dead_code)]
#[schema(nullable = true, example = "null")]
model: Option<String>,
#[allow(dead_code)]
#[schema(nullable = true, example = "null")]
user: Option<String>,
}
#[derive(Serialize, ToSchema)]
pub(crate) struct OpenAICompatEmbedding {
#[schema(example = "embedding")]
object: &'static str,
#[schema(example = json ! (["0.0", "1.0", "2.0"]))]
embedding: Vec<f32>,
#[schema(example = "0")]
index: usize,
}
#[derive(Serialize, ToSchema)]
pub(crate) struct OpenAICompatUsage {
#[schema(example = "512")]
prompt_tokens: usize,
#[schema(example = "512")]
total_tokens: usize,
}
#[derive(Serialize, ToSchema)]
pub(crate) struct OpenAICompatResponse {
#[schema(example = "list")]
object: &'static str,
data: Vec<OpenAICompatEmbedding>,
#[schema(example = "thenlper/gte-base")]
model: String,
usage: OpenAICompatUsage,
}
#[derive(Deserialize, ToSchema)]
pub(crate) struct EmbedRequest {
pub inputs: Input,
#[serde(default)]
#[schema(default = "false", example = "false")]
pub truncate: bool,
}
#[derive(Serialize, ToSchema)]
#[schema(example = json ! ([["0.0", "1.0", "2.0"]]))]
pub(crate) struct EmbedResponse(Vec<Vec<f32>>);
#[derive(Deserialize)]
pub(crate) struct HFECompatRequest {
pub inputs: String,
}
#[derive(Serialize)]
pub(crate) struct HFECompatResponse {
embeddings: Vec<f32>,
}
#[derive(Serialize, ToSchema)]
pub(crate) enum ErrorType {
Unhealthy,
Backend,
Overloaded,
Validation,
Tokenizer,
}
#[derive(Serialize, ToSchema)]
pub(crate) struct ErrorResponse {
pub error: String,
pub error_type: ErrorType,
}
#[derive(Serialize, ToSchema)]
pub(crate) struct OpenAICompatErrorResponse {
pub message: String,
pub code: u16,
#[serde(rename(serialize = "type"))]
pub error_type: ErrorType,
}