Skip to main content

linger_openai_sdk/
fine_tuning.rs

1use crate::error::LingerError;
2use crate::RequestId;
3use serde::{Deserialize, Deserializer, Serialize};
4use serde_json::Value;
5use std::collections::BTreeMap;
6
7/// EN: Request body for `POST /v1/fine_tuning/jobs`.
8/// 中文:`POST /v1/fine_tuning/jobs` 的请求体。
9#[derive(Clone, Debug, Serialize, PartialEq)]
10#[non_exhaustive]
11pub struct CreateFineTuningJobRequest {
12    /// EN: Base model to fine-tune.
13    /// 中文:要微调的基础模型。
14    pub model: String,
15    /// EN: Uploaded training file id.
16    /// 中文:已上传的训练文件 ID。
17    pub training_file: String,
18    /// EN: Optional uploaded validation file id.
19    /// 中文:可选的已上传验证文件 ID。
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub validation_file: Option<String>,
22    /// EN: Optional suffix for the fine-tuned model name.
23    /// 中文:微调后模型名称的可选后缀。
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub suffix: Option<String>,
26    /// EN: Optional seed for reproducibility.
27    /// 中文:用于可复现性的可选 seed。
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub seed: Option<u64>,
30    /// EN: Optional metadata attached to the job.
31    /// 中文:附加到任务的可选元数据。
32    #[serde(skip_serializing_if = "BTreeMap::is_empty")]
33    pub metadata: BTreeMap<String, String>,
34    /// EN: Forward-compatible optional fields not yet covered by handwritten types.
35    /// 中文:手写类型尚未覆盖的前向兼容可选字段。
36    #[serde(flatten)]
37    pub extra: BTreeMap<String, Value>,
38}
39
40impl CreateFineTuningJobRequest {
41    /// EN: Starts building a fine-tuning job request.
42    /// 中文:开始构建 fine-tuning job 请求。
43    pub fn builder() -> CreateFineTuningJobRequestBuilder {
44        CreateFineTuningJobRequestBuilder::default()
45    }
46}
47
48/// EN: Builder for create-fine-tuning-job requests.
49/// 中文:创建 fine-tuning job 请求的构建器。
50#[derive(Clone, Debug, Default)]
51#[non_exhaustive]
52pub struct CreateFineTuningJobRequestBuilder {
53    model: Option<String>,
54    training_file: Option<String>,
55    validation_file: Option<String>,
56    suffix: Option<String>,
57    seed: Option<u64>,
58    metadata: BTreeMap<String, String>,
59    extra: BTreeMap<String, Value>,
60}
61
62impl CreateFineTuningJobRequestBuilder {
63    /// EN: Sets the base model id.
64    /// 中文:设置基础模型 ID。
65    pub fn model(mut self, model: impl Into<String>) -> Self {
66        self.model = Some(model.into());
67        self
68    }
69
70    /// EN: Sets the uploaded training file id.
71    /// 中文:设置已上传的训练文件 ID。
72    pub fn training_file(mut self, training_file: impl Into<String>) -> Self {
73        self.training_file = Some(training_file.into());
74        self
75    }
76
77    /// EN: Sets the optional validation file id.
78    /// 中文:设置可选的验证文件 ID。
79    pub fn validation_file(mut self, validation_file: impl Into<String>) -> Self {
80        self.validation_file = Some(validation_file.into());
81        self
82    }
83
84    /// EN: Sets the optional model suffix.
85    /// 中文:设置可选的模型后缀。
86    pub fn suffix(mut self, suffix: impl Into<String>) -> Self {
87        self.suffix = Some(suffix.into());
88        self
89    }
90
91    /// EN: Sets the optional reproducibility seed.
92    /// 中文:设置可选的可复现 seed。
93    pub fn seed(mut self, seed: u64) -> Self {
94        self.seed = Some(seed);
95        self
96    }
97
98    /// EN: Adds a metadata entry.
99    /// 中文:添加一项元数据。
100    pub fn metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
101        self.metadata.insert(key.into(), value.into());
102        self
103    }
104
105    /// EN: Adds a forward-compatible JSON field.
106    /// 中文:添加前向兼容的 JSON 字段。
107    pub fn extra(mut self, name: impl Into<String>, value: Value) -> Self {
108        self.extra.insert(name.into(), value);
109        self
110    }
111
112    /// EN: Builds and validates the request.
113    /// 中文:构建并校验请求。
114    pub fn build(self) -> Result<CreateFineTuningJobRequest, LingerError> {
115        let model = self
116            .model
117            .filter(|value| !value.trim().is_empty())
118            .ok_or_else(|| LingerError::invalid_config("model is required"))?;
119        let training_file = self
120            .training_file
121            .filter(|value| !value.trim().is_empty())
122            .ok_or_else(|| LingerError::invalid_config("training_file is required"))?;
123        if self
124            .validation_file
125            .as_ref()
126            .is_some_and(|value| value.trim().is_empty())
127        {
128            return Err(LingerError::invalid_config(
129                "validation_file must not be empty",
130            ));
131        }
132        if self
133            .suffix
134            .as_ref()
135            .is_some_and(|value| value.trim().is_empty())
136        {
137            return Err(LingerError::invalid_config("suffix must not be empty"));
138        }
139        if self
140            .metadata
141            .iter()
142            .any(|(key, value)| key.trim().is_empty() || value.is_empty())
143        {
144            return Err(LingerError::invalid_config(
145                "metadata keys and values must not be empty",
146            ));
147        }
148        Ok(CreateFineTuningJobRequest {
149            model,
150            training_file,
151            validation_file: self.validation_file,
152            suffix: self.suffix,
153            seed: self.seed,
154            metadata: self.metadata,
155            extra: self.extra,
156        })
157    }
158}
159
160/// EN: Request body for checkpoint permission creation.
161/// 中文:创建 checkpoint permission 的请求体。
162#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
163#[non_exhaustive]
164pub struct CreateFineTuningCheckpointPermissionRequest {
165    /// EN: Project ids to grant access to.
166    /// 中文:要授予访问权限的项目 ID。
167    pub project_ids: Vec<String>,
168}
169
170impl CreateFineTuningCheckpointPermissionRequest {
171    /// EN: Creates and validates a checkpoint-permission request.
172    /// 中文:创建并校验 checkpoint permission 请求。
173    pub fn new<I, T>(project_ids: I) -> Result<Self, LingerError>
174    where
175        I: IntoIterator<Item = T>,
176        T: Into<String>,
177    {
178        let project_ids = project_ids.into_iter().map(Into::into).collect::<Vec<_>>();
179        if project_ids.is_empty() || project_ids.iter().any(|value| value.trim().is_empty()) {
180            return Err(LingerError::invalid_config("project_ids is required"));
181        }
182        Ok(Self { project_ids })
183    }
184}
185
186/// EN: Request body for `POST /v1/fine_tuning/alpha/graders/validate`.
187/// 中文:`POST /v1/fine_tuning/alpha/graders/validate` 的请求体。
188#[derive(Clone, Debug, Serialize, PartialEq)]
189#[non_exhaustive]
190pub struct ValidateFineTuningGraderRequest {
191    /// EN: Grader definition to validate.
192    /// 中文:要校验的 grader 定义。
193    pub grader: Value,
194}
195
196impl ValidateFineTuningGraderRequest {
197    /// EN: Starts building a grader validation request.
198    /// 中文:开始构建 grader 校验请求。
199    pub fn builder() -> ValidateFineTuningGraderRequestBuilder {
200        ValidateFineTuningGraderRequestBuilder::default()
201    }
202}
203
204/// EN: Builder for grader validation requests.
205/// 中文:grader 校验请求的构建器。
206#[derive(Clone, Debug, Default)]
207#[non_exhaustive]
208pub struct ValidateFineTuningGraderRequestBuilder {
209    grader: Option<Value>,
210}
211
212impl ValidateFineTuningGraderRequestBuilder {
213    /// EN: Sets the grader definition to validate.
214    /// 中文:设置要校验的 grader 定义。
215    pub fn grader(mut self, grader: Value) -> Self {
216        self.grader = Some(grader);
217        self
218    }
219
220    /// EN: Builds and validates the request.
221    /// 中文:构建并校验请求。
222    pub fn build(self) -> Result<ValidateFineTuningGraderRequest, LingerError> {
223        let grader = self
224            .grader
225            .filter(|value| !value.is_null())
226            .ok_or_else(|| LingerError::invalid_config("grader is required"))?;
227        Ok(ValidateFineTuningGraderRequest { grader })
228    }
229}
230
231/// EN: Response returned after validating a fine-tuning grader.
232/// 中文:校验 fine-tuning grader 后返回的响应。
233#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
234#[non_exhaustive]
235pub struct FineTuningGraderValidation {
236    /// EN: Validated grader definition.
237    /// 中文:已校验的 grader 定义。
238    pub grader: Value,
239    /// EN: OpenAI request id from response headers.
240    /// 中文:响应头中的 OpenAI 请求 ID。
241    #[serde(skip)]
242    request_id: Option<RequestId>,
243}
244
245impl FineTuningGraderValidation {
246    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
247        self.request_id = request_id;
248        self
249    }
250
251    /// EN: Returns the OpenAI request id, when present.
252    /// 中文:返回 OpenAI 请求 ID,如存在。
253    pub fn request_id(&self) -> Option<&RequestId> {
254        self.request_id.as_ref()
255    }
256}
257
258/// EN: Request body for `POST /v1/fine_tuning/alpha/graders/run`.
259/// 中文:`POST /v1/fine_tuning/alpha/graders/run` 的请求体。
260#[derive(Clone, Debug, Serialize, PartialEq)]
261#[non_exhaustive]
262pub struct RunFineTuningGraderRequest {
263    /// EN: Grader definition to run.
264    /// 中文:要运行的 grader 定义。
265    pub grader: Value,
266    /// EN: Optional dataset item used to populate the `item` namespace.
267    /// 中文:可选的数据集条目,用于填充 `item` 命名空间。
268    #[serde(skip_serializing_if = "Option::is_none")]
269    pub item: Option<Value>,
270    /// EN: Model sample to evaluate.
271    /// 中文:要评估的模型样本。
272    pub model_sample: String,
273}
274
275impl RunFineTuningGraderRequest {
276    /// EN: Starts building a grader run request.
277    /// 中文:开始构建 grader run 请求。
278    pub fn builder() -> RunFineTuningGraderRequestBuilder {
279        RunFineTuningGraderRequestBuilder::default()
280    }
281}
282
283/// EN: Builder for grader run requests.
284/// 中文:grader run 请求的构建器。
285#[derive(Clone, Debug, Default)]
286#[non_exhaustive]
287pub struct RunFineTuningGraderRequestBuilder {
288    grader: Option<Value>,
289    item: Option<Value>,
290    model_sample: Option<String>,
291}
292
293impl RunFineTuningGraderRequestBuilder {
294    /// EN: Sets the grader definition to run.
295    /// 中文:设置要运行的 grader 定义。
296    pub fn grader(mut self, grader: Value) -> Self {
297        self.grader = Some(grader);
298        self
299    }
300
301    /// EN: Sets the optional dataset item.
302    /// 中文:设置可选的数据集条目。
303    pub fn item(mut self, item: Value) -> Self {
304        self.item = Some(item);
305        self
306    }
307
308    /// EN: Sets the model sample to evaluate.
309    /// 中文:设置要评估的模型样本。
310    pub fn model_sample(mut self, model_sample: impl Into<String>) -> Self {
311        self.model_sample = Some(model_sample.into());
312        self
313    }
314
315    /// EN: Builds and validates the request.
316    /// 中文:构建并校验请求。
317    pub fn build(self) -> Result<RunFineTuningGraderRequest, LingerError> {
318        let grader = self
319            .grader
320            .filter(|value| !value.is_null())
321            .ok_or_else(|| LingerError::invalid_config("grader is required"))?;
322        let model_sample = self
323            .model_sample
324            .filter(|value| !value.trim().is_empty())
325            .ok_or_else(|| LingerError::invalid_config("model_sample is required"))?;
326        Ok(RunFineTuningGraderRequest {
327            grader,
328            item: self.item,
329            model_sample,
330        })
331    }
332}
333
334/// EN: Response returned after running a fine-tuning grader.
335/// 中文:运行 fine-tuning grader 后返回的响应。
336#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
337#[non_exhaustive]
338pub struct FineTuningGraderRun {
339    /// EN: Numeric reward produced by the grader.
340    /// 中文:grader 产生的数值 reward。
341    pub reward: f64,
342    /// EN: Grader execution metadata.
343    /// 中文:grader 执行元数据。
344    pub metadata: Value,
345    /// EN: Sub-rewards returned by composite graders.
346    /// 中文:组合 grader 返回的子 reward。
347    pub sub_rewards: Value,
348    /// EN: Model grader token usage grouped by model.
349    /// 中文:按模型分组的 model grader token 用量。
350    pub model_grader_token_usage_per_model: Value,
351    /// EN: OpenAI request id from response headers.
352    /// 中文:响应头中的 OpenAI 请求 ID。
353    #[serde(skip)]
354    request_id: Option<RequestId>,
355}
356
357impl FineTuningGraderRun {
358    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
359        self.request_id = request_id;
360        self
361    }
362
363    /// EN: Returns the OpenAI request id, when present.
364    /// 中文:返回 OpenAI 请求 ID,如存在。
365    pub fn request_id(&self) -> Option<&RequestId> {
366        self.request_id.as_ref()
367    }
368}
369
370/// EN: Fine-tuning job object returned by the API.
371/// 中文:API 返回的 fine-tuning job 对象。
372#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
373#[non_exhaustive]
374pub struct FineTuningJob {
375    /// EN: Fine-tuning job id.
376    /// 中文:fine-tuning job ID。
377    pub id: String,
378    /// EN: API object type.
379    /// 中文:API 对象类型。
380    pub object: String,
381    /// EN: Base model.
382    /// 中文:基础模型。
383    pub model: String,
384    /// EN: Unix timestamp for creation.
385    /// 中文:创建时间的 Unix 时间戳。
386    pub created_at: u64,
387    /// EN: Fine-tuned model id, when available.
388    /// 中文:可用时的微调后模型 ID。
389    #[serde(default)]
390    pub fine_tuned_model: Option<String>,
391    /// EN: Organization id that owns the job.
392    /// 中文:拥有该任务的组织 ID。
393    #[serde(default)]
394    pub organization_id: Option<String>,
395    /// EN: Result file ids.
396    /// 中文:结果文件 ID。
397    #[serde(default)]
398    pub result_files: Vec<String>,
399    /// EN: Current job status.
400    /// 中文:当前任务状态。
401    pub status: String,
402    /// EN: Validation file id, when present.
403    /// 中文:验证文件 ID,如存在。
404    #[serde(default)]
405    pub validation_file: Option<String>,
406    /// EN: Training file id.
407    /// 中文:训练文件 ID。
408    pub training_file: String,
409    /// EN: Hyperparameter details returned by the API.
410    /// 中文:API 返回的超参数详情。
411    #[serde(default)]
412    pub hyperparameters: Value,
413    /// EN: Number of trained tokens, when returned.
414    /// 中文:训练 token 数,如响应中存在。
415    #[serde(default)]
416    pub trained_tokens: Option<u64>,
417    /// EN: Job error details, when returned.
418    /// 中文:任务错误详情,如响应中存在。
419    #[serde(default)]
420    pub error: Option<Value>,
421    /// EN: Estimated finish timestamp, when returned.
422    /// 中文:预计完成时间戳,如响应中存在。
423    #[serde(default)]
424    pub estimated_finish: Option<u64>,
425    /// EN: Integration descriptors returned by the API.
426    /// 中文:API 返回的集成描述。
427    #[serde(default)]
428    pub integrations: Vec<Value>,
429    /// EN: Seed used for the job, when returned.
430    /// 中文:任务使用的 seed,如响应中存在。
431    #[serde(default)]
432    pub seed: Option<u64>,
433    /// EN: Metadata returned with this job.
434    /// 中文:此任务返回的元数据。
435    #[serde(default, deserialize_with = "deserialize_null_default")]
436    pub metadata: BTreeMap<String, String>,
437    /// EN: Fine-tuning method details.
438    /// 中文:fine-tuning 方法详情。
439    #[serde(default)]
440    pub method: Value,
441    /// EN: Additional fields preserved for forward compatibility.
442    /// 中文:为前向兼容保留的额外字段。
443    #[serde(flatten)]
444    pub extra: BTreeMap<String, Value>,
445    /// EN: OpenAI request id from response headers.
446    /// 中文:响应头中的 OpenAI 请求 ID。
447    #[serde(skip)]
448    request_id: Option<RequestId>,
449}
450
451impl FineTuningJob {
452    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
453        self.request_id = request_id;
454        self
455    }
456
457    /// EN: Returns the OpenAI request id, when present.
458    /// 中文:返回 OpenAI 请求 ID,如存在。
459    pub fn request_id(&self) -> Option<&RequestId> {
460        self.request_id.as_ref()
461    }
462}
463
464/// EN: Paginated fine-tuning job list.
465/// 中文:分页 fine-tuning job 列表。
466#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
467#[non_exhaustive]
468pub struct FineTuningJobPage {
469    /// EN: API list object type.
470    /// 中文:API 列表对象类型。
471    pub object: String,
472    /// EN: Jobs on this page.
473    /// 中文:本页任务。
474    #[serde(default)]
475    pub data: Vec<FineTuningJob>,
476    /// EN: First job id on this page.
477    /// 中文:本页第一个任务 ID。
478    #[serde(default)]
479    pub first_id: Option<String>,
480    /// EN: Last job id on this page.
481    /// 中文:本页最后一个任务 ID。
482    #[serde(default)]
483    pub last_id: Option<String>,
484    /// EN: Whether more jobs are available.
485    /// 中文:是否还有更多任务。
486    pub has_more: bool,
487    /// EN: OpenAI request id from response headers.
488    /// 中文:响应头中的 OpenAI 请求 ID。
489    #[serde(skip)]
490    request_id: Option<RequestId>,
491}
492
493impl FineTuningJobPage {
494    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
495        self.request_id = request_id;
496        self
497    }
498
499    /// EN: Returns the OpenAI request id, when present.
500    /// 中文:返回 OpenAI 请求 ID,如存在。
501    pub fn request_id(&self) -> Option<&RequestId> {
502        self.request_id.as_ref()
503    }
504}
505
506/// EN: Fine-tuning job event.
507/// 中文:fine-tuning job 事件。
508#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
509#[non_exhaustive]
510pub struct FineTuningEvent {
511    /// EN: Event id.
512    /// 中文:事件 ID。
513    pub id: String,
514    /// EN: API object type.
515    /// 中文:API 对象类型。
516    pub object: String,
517    /// EN: Unix timestamp for event creation.
518    /// 中文:事件创建时间的 Unix 时间戳。
519    pub created_at: u64,
520    /// EN: Event level.
521    /// 中文:事件级别。
522    pub level: String,
523    /// EN: Human-readable event message.
524    /// 中文:可读事件消息。
525    pub message: String,
526    /// EN: Event type, when returned.
527    /// 中文:事件类型,如响应中存在。
528    #[serde(default)]
529    pub r#type: Option<String>,
530    /// EN: Additional fields preserved for forward compatibility.
531    /// 中文:为前向兼容保留的额外字段。
532    #[serde(flatten)]
533    pub extra: BTreeMap<String, Value>,
534}
535
536/// EN: Paginated fine-tuning event list.
537/// 中文:分页 fine-tuning 事件列表。
538#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
539#[non_exhaustive]
540pub struct FineTuningEventPage {
541    /// EN: API list object type.
542    /// 中文:API 列表对象类型。
543    pub object: String,
544    /// EN: Events on this page.
545    /// 中文:本页事件。
546    #[serde(default)]
547    pub data: Vec<FineTuningEvent>,
548    /// EN: First event id on this page.
549    /// 中文:本页第一个事件 ID。
550    #[serde(default)]
551    pub first_id: Option<String>,
552    /// EN: Last event id on this page.
553    /// 中文:本页最后一个事件 ID。
554    #[serde(default)]
555    pub last_id: Option<String>,
556    /// EN: Whether more events are available.
557    /// 中文:是否还有更多事件。
558    pub has_more: bool,
559    /// EN: OpenAI request id from response headers.
560    /// 中文:响应头中的 OpenAI 请求 ID。
561    #[serde(skip)]
562    request_id: Option<RequestId>,
563}
564
565impl FineTuningEventPage {
566    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
567        self.request_id = request_id;
568        self
569    }
570
571    /// EN: Returns the OpenAI request id, when present.
572    /// 中文:返回 OpenAI 请求 ID,如存在。
573    pub fn request_id(&self) -> Option<&RequestId> {
574        self.request_id.as_ref()
575    }
576}
577
578/// EN: Fine-tuning job checkpoint.
579/// 中文:fine-tuning job 检查点。
580#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
581#[non_exhaustive]
582pub struct FineTuningCheckpoint {
583    /// EN: Checkpoint id.
584    /// 中文:检查点 ID。
585    pub id: String,
586    /// EN: API object type.
587    /// 中文:API 对象类型。
588    pub object: String,
589    /// EN: Unix timestamp for checkpoint creation.
590    /// 中文:检查点创建时间的 Unix 时间戳。
591    pub created_at: u64,
592    /// EN: Fine-tuned checkpoint model id.
593    /// 中文:微调检查点模型 ID。
594    pub fine_tuned_model_checkpoint: String,
595    /// EN: Fine-tuning job id.
596    /// 中文:fine-tuning job ID。
597    pub fine_tuning_job_id: String,
598    /// EN: Step number for this checkpoint.
599    /// 中文:此检查点的步数。
600    pub step_number: u64,
601    /// EN: Metrics returned for this checkpoint.
602    /// 中文:此检查点返回的指标。
603    #[serde(default)]
604    pub metrics: BTreeMap<String, Value>,
605    /// EN: Additional fields preserved for forward compatibility.
606    /// 中文:为前向兼容保留的额外字段。
607    #[serde(flatten)]
608    pub extra: BTreeMap<String, Value>,
609}
610
611/// EN: Paginated fine-tuning checkpoint list.
612/// 中文:分页 fine-tuning 检查点列表。
613#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
614#[non_exhaustive]
615pub struct FineTuningCheckpointPage {
616    /// EN: API list object type.
617    /// 中文:API 列表对象类型。
618    pub object: String,
619    /// EN: Checkpoints on this page.
620    /// 中文:本页检查点。
621    #[serde(default)]
622    pub data: Vec<FineTuningCheckpoint>,
623    /// EN: First checkpoint id on this page.
624    /// 中文:本页第一个检查点 ID。
625    #[serde(default)]
626    pub first_id: Option<String>,
627    /// EN: Last checkpoint id on this page.
628    /// 中文:本页最后一个检查点 ID。
629    #[serde(default)]
630    pub last_id: Option<String>,
631    /// EN: Whether more checkpoints are available.
632    /// 中文:是否还有更多检查点。
633    pub has_more: bool,
634    /// EN: OpenAI request id from response headers.
635    /// 中文:响应头中的 OpenAI 请求 ID。
636    #[serde(skip)]
637    request_id: Option<RequestId>,
638}
639
640impl FineTuningCheckpointPage {
641    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
642        self.request_id = request_id;
643        self
644    }
645
646    /// EN: Returns the OpenAI request id, when present.
647    /// 中文:返回 OpenAI 请求 ID,如存在。
648    pub fn request_id(&self) -> Option<&RequestId> {
649        self.request_id.as_ref()
650    }
651}
652
653/// EN: A permission for a fine-tuned model checkpoint.
654/// 中文:微调模型 checkpoint 的权限对象。
655#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
656#[non_exhaustive]
657pub struct FineTuningCheckpointPermission {
658    /// EN: Permission id.
659    /// 中文:权限 ID。
660    pub id: String,
661    /// EN: API object type, normally `checkpoint.permission`.
662    /// 中文:API 对象类型,通常为 `checkpoint.permission`。
663    pub object: String,
664    /// EN: Unix timestamp for permission creation.
665    /// 中文:权限创建时间的 Unix 时间戳。
666    pub created_at: u64,
667    /// EN: Project id this permission grants access to.
668    /// 中文:此权限授予访问权限的项目 ID。
669    pub project_id: String,
670}
671
672/// EN: Paginated checkpoint permission list.
673/// 中文:分页 checkpoint permission 列表。
674#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
675#[non_exhaustive]
676pub struct FineTuningCheckpointPermissionPage {
677    /// EN: API list object type.
678    /// 中文:API 列表对象类型。
679    pub object: String,
680    /// EN: Permissions on this page.
681    /// 中文:本页权限。
682    #[serde(default)]
683    pub data: Vec<FineTuningCheckpointPermission>,
684    /// EN: First permission id on this page.
685    /// 中文:本页第一个权限 ID。
686    #[serde(default)]
687    pub first_id: Option<String>,
688    /// EN: Last permission id on this page.
689    /// 中文:本页最后一个权限 ID。
690    #[serde(default)]
691    pub last_id: Option<String>,
692    /// EN: Whether more permissions are available.
693    /// 中文:是否还有更多权限。
694    pub has_more: bool,
695    /// EN: OpenAI request id from response headers.
696    /// 中文:响应头中的 OpenAI 请求 ID。
697    #[serde(skip)]
698    request_id: Option<RequestId>,
699}
700
701impl FineTuningCheckpointPermissionPage {
702    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
703        self.request_id = request_id;
704        self
705    }
706
707    /// EN: Returns the OpenAI request id, when present.
708    /// 中文:返回 OpenAI 请求 ID,如存在。
709    pub fn request_id(&self) -> Option<&RequestId> {
710        self.request_id.as_ref()
711    }
712}
713
714/// EN: Deletion result returned for checkpoint permissions.
715/// 中文:checkpoint permission 的删除结果。
716#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
717#[non_exhaustive]
718pub struct FineTuningCheckpointPermissionDeletion {
719    /// EN: Deleted permission id.
720    /// 中文:已删除的权限 ID。
721    pub id: String,
722    /// EN: API object type, normally `checkpoint.permission`.
723    /// 中文:API 对象类型,通常为 `checkpoint.permission`。
724    pub object: String,
725    /// EN: Whether the permission was deleted.
726    /// 中文:权限是否已删除。
727    pub deleted: bool,
728    /// EN: OpenAI request id from response headers.
729    /// 中文:响应头中的 OpenAI 请求 ID。
730    #[serde(skip)]
731    request_id: Option<RequestId>,
732}
733
734impl FineTuningCheckpointPermissionDeletion {
735    pub(crate) fn with_request_id(mut self, request_id: Option<RequestId>) -> Self {
736        self.request_id = request_id;
737        self
738    }
739
740    /// EN: Returns the OpenAI request id, when present.
741    /// 中文:返回 OpenAI 请求 ID,如存在。
742    pub fn request_id(&self) -> Option<&RequestId> {
743        self.request_id.as_ref()
744    }
745}
746
747fn deserialize_null_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
748where
749    D: Deserializer<'de>,
750    T: Deserialize<'de> + Default,
751{
752    Ok(Option::<T>::deserialize(deserializer)?.unwrap_or_default())
753}