gproxy_protocol/transform/claude/model_list/openai/
response.rs1use crate::claude::model_list::response::{
2 ClaudeModelListResponse, ResponseBody as ClaudeModelListResponseBody,
3};
4use crate::claude::types::ClaudeResponseHeaders;
5use crate::openai::model_list::response::OpenAiModelListResponse;
6use crate::transform::claude::model_list::openai::utils::{
7 beta_error_response_from_openai, beta_model_info_from_openai_model,
8};
9use crate::transform::utils::TransformError;
10
11impl TryFrom<OpenAiModelListResponse> for ClaudeModelListResponse {
12 type Error = TransformError;
13
14 fn try_from(value: OpenAiModelListResponse) -> Result<Self, TransformError> {
15 Ok(match value {
16 OpenAiModelListResponse::Success {
17 stats_code,
18 headers,
19 body,
20 } => {
21 let data = body
22 .data
23 .into_iter()
24 .map(beta_model_info_from_openai_model)
25 .collect::<Vec<_>>();
26 let first_id = data
27 .first()
28 .map(|model| model.id.clone())
29 .unwrap_or_default();
30 let last_id = data
31 .last()
32 .map(|model| model.id.clone())
33 .unwrap_or_default();
34
35 ClaudeModelListResponse::Success {
36 stats_code,
37 headers: ClaudeResponseHeaders {
38 extra: headers.extra,
39 },
40 body: ClaudeModelListResponseBody {
41 data,
42 first_id,
43 has_more: false,
44 last_id,
45 },
46 }
47 }
48 OpenAiModelListResponse::Error {
49 stats_code,
50 headers,
51 body,
52 } => ClaudeModelListResponse::Error {
53 stats_code,
54 headers: ClaudeResponseHeaders {
55 extra: headers.extra,
56 },
57 body: beta_error_response_from_openai(stats_code, body),
58 },
59 })
60 }
61}