|
1 | | -use crate::{ |
2 | | - ComputeUnits, Error, ErrorResponse, GenericResponse, InitRequest, InitResponse, ServerStatus, |
3 | | -}; |
| 1 | +use crate::{Error, ErrorResponse, GenericResponse, InitRequest, InitResponse, ServerStatus}; |
4 | 2 | use reqwest::{Response, StatusCode}; |
5 | 3 |
|
6 | 4 | #[derive(Clone)] |
@@ -35,33 +33,6 @@ impl Client { |
35 | 33 | } |
36 | 34 | } |
37 | 35 |
|
38 | | - pub async fn wait_for_ready( |
39 | | - &self, |
40 | | - max_wait_time: Option<u32>, |
41 | | - poll_interval: Option<f32>, |
42 | | - ) -> Result<ServerStatus, Error> { |
43 | | - let url = format!("{}/v1/waitForReady", self.base_url); |
44 | | - let mut request = self.client.get(&url); |
45 | | - |
46 | | - if let Some(max_wait) = max_wait_time { |
47 | | - request = request.query(&[("maxWaitTime", max_wait)]); |
48 | | - } |
49 | | - |
50 | | - if let Some(interval) = poll_interval { |
51 | | - request = request.query(&[("pollInterval", interval)]); |
52 | | - } |
53 | | - |
54 | | - let response = request.send().await?; |
55 | | - |
56 | | - match response.status() { |
57 | | - StatusCode::OK => Ok(response.json().await?), |
58 | | - StatusCode::BAD_REQUEST | StatusCode::REQUEST_TIMEOUT => { |
59 | | - Err(self.handle_error_response(response).await) |
60 | | - } |
61 | | - _ => Err(Error::UnexpectedResponse), |
62 | | - } |
63 | | - } |
64 | | - |
65 | 36 | pub async fn init(&self, request: InitRequest) -> Result<InitResponse, Error> { |
66 | 37 | if !request.api_key.starts_with("ax_") { |
67 | 38 | return Err(Error::InvalidApiKey); |
@@ -129,77 +100,15 @@ impl InitRequest { |
129 | 100 | Self { |
130 | 101 | api_key: api_key.into(), |
131 | 102 | model: None, |
132 | | - model_token: None, |
133 | 103 | download_base: None, |
134 | 104 | model_repo: None, |
135 | 105 | model_folder: None, |
136 | | - tokenizer_folder: None, |
137 | | - fast_load: None, |
138 | | - fast_load_encoder_compute_units: None, |
139 | | - fast_load_decoder_compute_units: None, |
140 | | - model_vad: None, |
141 | | - verbose: None, |
142 | 106 | } |
143 | 107 | } |
144 | 108 |
|
145 | | - pub fn with_model(mut self, model: impl Into<String>) -> Self { |
146 | | - self.model = Some(model.into()); |
147 | | - self |
148 | | - } |
149 | | - |
150 | | - pub fn with_model_token(mut self, token: impl Into<String>) -> Self { |
151 | | - self.model_token = Some(token.into()); |
152 | | - self |
153 | | - } |
154 | | - |
155 | | - pub fn with_download_base(mut self, download_base: impl Into<String>) -> Self { |
156 | | - self.download_base = Some(download_base.into()); |
157 | | - self |
158 | | - } |
159 | | - |
160 | | - pub fn with_model_repo(mut self, repo: impl Into<String>) -> Self { |
161 | | - self.model_repo = Some(repo.into()); |
| 109 | + pub fn with_model(mut self, model: crate::AmModel) -> Self { |
| 110 | + self.model = Some(model.model_key().to_string()); |
| 111 | + self.model_repo = Some(model.repo_name().to_string()); |
162 | 112 | self |
163 | 113 | } |
164 | | - |
165 | | - pub fn with_model_folder(mut self, folder: impl Into<String>) -> Self { |
166 | | - self.model_folder = Some(folder.into()); |
167 | | - self |
168 | | - } |
169 | | - |
170 | | - pub fn with_tokenizer_folder(mut self, folder: impl Into<String>) -> Self { |
171 | | - self.tokenizer_folder = Some(folder.into()); |
172 | | - self |
173 | | - } |
174 | | - |
175 | | - pub fn with_fast_load(mut self, fast_load: bool) -> Self { |
176 | | - self.fast_load = Some(fast_load); |
177 | | - self |
178 | | - } |
179 | | - |
180 | | - pub fn with_encoder_compute_units(mut self, units: ComputeUnits) -> Self { |
181 | | - self.fast_load_encoder_compute_units = Some(units); |
182 | | - self |
183 | | - } |
184 | | - |
185 | | - pub fn with_decoder_compute_units(mut self, units: ComputeUnits) -> Self { |
186 | | - self.fast_load_decoder_compute_units = Some(units); |
187 | | - self |
188 | | - } |
189 | | - |
190 | | - pub fn with_model_vad(mut self, vad: bool) -> Self { |
191 | | - self.model_vad = Some(vad); |
192 | | - self |
193 | | - } |
194 | | - |
195 | | - pub fn with_verbose(mut self, verbose: bool) -> Self { |
196 | | - self.verbose = Some(verbose); |
197 | | - self |
198 | | - } |
199 | | -} |
200 | | - |
201 | | -impl Default for Client { |
202 | | - fn default() -> Self { |
203 | | - Self::new("http://localhost:50060") |
204 | | - } |
205 | 114 | } |
0 commit comments