1use serde::{Deserialize, Serialize};
10use utoipa::ToSchema;
11use chrono::{DateTime, Utc};
12use std::collections::HashMap;
13
14#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
16pub struct HealthResponse {
17 pub status: String,
19 pub version: String,
21 pub timestamp: DateTime<Utc>,
23 pub uptime_seconds: u64,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
29pub struct CompletionRequest {
30 pub provider: String,
32 pub model: String,
34 pub prompt: String,
36 #[serde(skip_serializing_if = "Option::is_none")]
38 pub max_tokens: Option<usize>,
39 #[serde(skip_serializing_if = "Option::is_none")]
41 pub temperature: Option<f32>,
42 #[serde(default)]
44 pub stream: bool,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
49pub struct CompletionResponse {
50 pub text: String,
52 pub model: String,
54 #[serde(skip_serializing_if = "Option::is_none")]
56 pub usage: Option<TokenUsage>,
57 pub request_id: String,
59 pub created_at: DateTime<Utc>,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
65pub struct TokenUsage {
66 pub prompt_tokens: u64,
67 pub completion_tokens: u64,
68 pub total_tokens: u64,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
73pub struct EvaluationRequest {
74 pub provider: String,
76 pub model: String,
78 pub input: String,
80 pub output: String,
82 #[serde(skip_serializing_if = "Option::is_none")]
84 pub expected: Option<String>,
85 pub metrics: Vec<String>,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
91pub struct EvaluationResponse {
92 pub score: f64,
94 pub metrics: HashMap<String, f64>,
96 pub evaluation_id: String,
98 pub created_at: DateTime<Utc>,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
104pub struct BenchmarkRequest {
105 pub name: String,
107 pub providers: Vec<String>,
109 pub models: Vec<String>,
111 pub dataset: String,
113 #[serde(skip_serializing_if = "Option::is_none")]
115 pub num_examples: Option<usize>,
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
120pub struct BenchmarkResponse {
121 pub benchmark_id: String,
123 pub status: BenchmarkStatus,
125 pub progress: f64,
127 #[serde(skip_serializing_if = "Option::is_none")]
129 pub results: Option<BenchmarkResults>,
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
134#[serde(rename_all = "snake_case")]
135pub enum BenchmarkStatus {
136 Pending,
137 Running,
138 Completed,
139 Failed,
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
144pub struct BenchmarkResults {
145 pub by_provider: HashMap<String, ProviderResults>,
147 pub duration_seconds: f64,
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
153pub struct ProviderResults {
154 pub provider: String,
156 pub model: String,
158 pub avg_score: f64,
160 pub avg_latency: f64,
162 pub total_cost: f64,
164 pub error_rate: f64,
166}
167
168#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
170pub struct PluginInfo {
171 pub id: String,
173 pub name: String,
175 pub version: String,
177 pub plugin_type: String,
179 pub status: String,
181 pub execution_count: u64,
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
187pub struct PluginExecuteRequest {
188 pub plugin_id: String,
190 pub input: serde_json::Value,
192}
193
194#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
196pub struct PluginExecuteResponse {
197 pub output: serde_json::Value,
199 pub execution_time_ms: u64,
201 pub request_id: String,
203}
204
205#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
207pub struct PaginatedResponse<T> {
208 pub items: Vec<T>,
210 pub total: usize,
212 pub page: usize,
214 pub page_size: usize,
216 pub total_pages: usize,
218}
219
220impl<T> PaginatedResponse<T> {
221 pub fn new(items: Vec<T>, total: usize, page: usize, page_size: usize) -> Self {
222 let total_pages = (total + page_size - 1) / page_size;
223 Self {
224 items,
225 total,
226 page,
227 page_size,
228 total_pages,
229 }
230 }
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
235pub struct ErrorResponse {
236 pub error: String,
238 pub code: String,
240 #[serde(skip_serializing_if = "Option::is_none")]
242 pub detail: Option<String>,
243 #[serde(skip_serializing_if = "Option::is_none")]
245 pub request_id: Option<String>,
246 pub timestamp: DateTime<Utc>,
248}
249
250impl ErrorResponse {
251 pub fn new(error: impl Into<String>, code: impl Into<String>) -> Self {
252 Self {
253 error: error.into(),
254 code: code.into(),
255 detail: None,
256 request_id: None,
257 timestamp: Utc::now(),
258 }
259 }
260
261 pub fn with_detail(mut self, detail: impl Into<String>) -> Self {
262 self.detail = Some(detail.into());
263 self
264 }
265
266 pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
267 self.request_id = Some(request_id.into());
268 self
269 }
270}
271
272#[cfg(test)]
273mod tests {
274 use super::*;
275
276 #[test]
277 fn test_paginated_response() {
278 let items = vec![1, 2, 3, 4, 5];
279 let response = PaginatedResponse::new(items.clone(), 15, 1, 5);
280
281 assert_eq!(response.items, items);
282 assert_eq!(response.total, 15);
283 assert_eq!(response.page, 1);
284 assert_eq!(response.total_pages, 3);
285 }
286
287 #[test]
288 fn test_error_response() {
289 let error = ErrorResponse::new("Test error", "TEST_ERROR")
290 .with_detail("Detailed message")
291 .with_request_id("req_123");
292
293 assert_eq!(error.error, "Test error");
294 assert_eq!(error.code, "TEST_ERROR");
295 assert_eq!(error.detail, Some("Detailed message".to_string()));
296 assert_eq!(error.request_id, Some("req_123".to_string()));
297 }
298}