openai_interface/batches/
list.rs1use url::Url;
7
8use crate::{
9 batches::Batch,
10 errors::OapiError,
11 pagination::PaginationQuery,
12 rest::get::{Get, GetNoStream},
13};
14
15#[derive(Debug, Clone, Default)]
17pub struct ListBatchesRequest<'a> {
18 pub pagination: PaginationQuery<'a>,
20 pub before: Option<&'a str>,
23 pub extra_query: Option<std::collections::HashMap<String, String>>,
25}
26
27impl Get for ListBatchesRequest<'_> {
28 fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
32 let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
33 url.path_segments_mut()
34 .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
35 .push("batches");
36
37 let mut touched = false;
38 {
39 let mut pairs = url.query_pairs_mut();
40 if self.pagination.any_set() {
41 self.pagination.append_to(&mut pairs);
42 touched = true;
43 }
44 if let Some(before) = self.before {
45 pairs.append_pair("before", before);
46 touched = true;
47 }
48 if let Some(extra_query) = &self.extra_query {
49 for (key, value) in extra_query {
50 pairs.append_pair(key, value);
51 }
52 touched = true;
53 }
54 }
55 if !touched {
56 url.set_query(None);
57 }
58
59 Ok(url.to_string())
60 }
61}
62
63impl GetNoStream for ListBatchesRequest<'_> {
64 type Response = ListBatchesResponse;
65}
66
67#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
69pub struct ListBatchesResponse {
70 #[serde(default)]
72 pub data: Vec<Batch>,
73 #[serde(default)]
75 pub has_more: Option<bool>,
76 #[serde(default)]
78 pub first_id: Option<String>,
79 #[serde(default)]
81 pub last_id: Option<String>,
82 #[serde(default)]
84 pub object: Option<String>,
85}
86
87crate::impl_from_str!(ListBatchesResponse);