replicate_client/models/
common.rs

1//! Common types and structures used across the API.
2
3use serde::{Deserialize, Serialize};
4
5/// Generic API response wrapper.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ApiResponse<T> {
8    /// The response data
9    #[serde(flatten)]
10    pub data: T,
11}
12
13/// Paginated response structure.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct PaginatedResponse<T> {
16    /// The results for this page
17    pub results: Vec<T>,
18    /// URL for the next page (if available)
19    pub next: Option<String>,
20    /// URL for the previous page (if available)
21    pub previous: Option<String>,
22}
23
24impl<T> PaginatedResponse<T> {
25    /// Check if there are more pages
26    pub fn has_next(&self) -> bool {
27        self.next.is_some()
28    }
29
30    /// Check if there are previous pages
31    pub fn has_previous(&self) -> bool {
32        self.previous.is_some()
33    }
34
35    /// Get the number of results in this page
36    pub fn len(&self) -> usize {
37        self.results.len()
38    }
39
40    /// Check if this page is empty
41    pub fn is_empty(&self) -> bool {
42        self.results.is_empty()
43    }
44}
45
46/// Hardware configuration for running models.
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct Hardware {
49    /// Hardware identifier
50    pub sku: String,
51    /// Human-readable name
52    pub name: String,
53}
54
55/// Model version metadata.
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct ModelVersion {
58    /// Version ID
59    pub id: String,
60    /// When this version was created
61    pub created_at: String,
62    /// Cog version used
63    pub cog_version: Option<String>,
64    /// OpenAPI schema for the model
65    pub openapi_schema: Option<serde_json::Value>,
66}
67
68/// Basic model information.
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct Model {
71    /// Model owner
72    pub owner: String,
73    /// Model name
74    pub name: String,
75    /// Model description
76    pub description: Option<String>,
77    /// Model visibility
78    pub visibility: String,
79    /// GitHub URL
80    pub github_url: Option<String>,
81    /// Paper URL
82    pub paper_url: Option<String>,
83    /// License URL
84    pub license_url: Option<String>,
85    /// Cover image URL
86    pub cover_image_url: Option<String>,
87    /// Latest version
88    pub latest_version: Option<ModelVersion>,
89}
90
91impl Model {
92    /// Get the full model identifier (owner/name)
93    pub fn identifier(&self) -> String {
94        format!("{}/{}", self.owner, self.name)
95    }
96}