hugging_face_client/api/
get_collections.rs

1use serde::Serialize;
2
3use crate::collection::Collection;
4
5/// Request of [`crate::client::Client::get_collections`]
6#[derive(Debug, Serialize)]
7pub struct GetCollectionsReq<'a> {
8  #[serde(skip_serializing_if = "Option::is_none")]
9  owner: Option<&'a str>,
10
11  #[serde(skip_serializing_if = "Option::is_none")]
12  item: Option<&'a str>,
13
14  #[serde(skip_serializing_if = "Option::is_none")]
15  sort: Option<&'a str>,
16
17  #[serde(skip_serializing_if = "Option::is_none")]
18  limit: Option<usize>,
19
20  #[serde(skip_serializing_if = "Option::is_none", rename = "q")]
21  query: Option<&'a str>,
22}
23
24impl<'a> GetCollectionsReq<'a> {
25  pub fn new() -> Self {
26    GetCollectionsReq {
27      owner: None,
28      item: None,
29      sort: None,
30      limit: None,
31      query: None,
32    }
33  }
34
35  /// Filter collections created by a specific user or organization
36  pub fn owner(mut self, owner: &'a str) -> Self {
37    self.owner = Some(owner);
38    self
39  }
40
41  /// Filter collections containing a specific item. Value must be the item_type and item_id
42  /// concatenated. Example: "models/teknium/OpenHermes-2.5-Mistral-7B", "datasets/rajpurkar/squad"
43  /// or "papers/2311.12983"
44  pub fn item(mut self, item: &'a str) -> Self {
45    self.item = Some(item);
46    self
47  }
48
49  /// Sort the returned collections. Supported values are "lastModified", "trending" (default) and
50  /// "upvotes"
51  pub fn sort(mut self, sort: &'a str) -> Self {
52    self.sort = Some(sort);
53    self
54  }
55
56  /// Maximum number (100) of collections per page
57  pub fn limit(mut self, limit: usize) -> Self {
58    self.limit = Some(limit);
59    self
60  }
61
62  ///  Filter based on substrings for titles & descriptions
63  pub fn query(mut self, query: &'a str) -> Self {
64    self.query = Some(query);
65    self
66  }
67}
68
69/// Response of [`crate::client::Client::get_collections`]
70pub type GetCollectionsRes = Vec<Collection>;