outfox-openai 0.7.0

Openai for outfox
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
use serde::{Deserialize, Serialize};

/// Sent when a batch API request has been cancelled.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchCancelled {
    /// The Unix timestamp (in seconds) of when the batch API request was cancelled.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookBatchData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a batch API request has been completed.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchCompleted {
    /// The Unix timestamp (in seconds) of when the batch API request was completed.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookBatchData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a batch API request has expired.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchExpired {
    /// The Unix timestamp (in seconds) of when the batch API request expired.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookBatchData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a batch API request has failed.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchFailed {
    /// The Unix timestamp (in seconds) of when the batch API request failed.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookBatchData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Data payload for batch webhook events.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchData {
    /// The unique ID of the batch API request.
    pub id: String,
}

/// Sent when an eval run has been canceled.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunCanceled {
    /// The Unix timestamp (in seconds) of when the eval run was canceled.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookEvalRunData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when an eval run has failed.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunFailed {
    /// The Unix timestamp (in seconds) of when the eval run failed.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookEvalRunData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when an eval run has succeeded.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunSucceeded {
    /// The Unix timestamp (in seconds) of when the eval run succeeded.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookEvalRunData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Data payload for eval run webhook events.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunData {
    /// The unique ID of the eval run.
    pub id: String,
}

/// Sent when a fine-tuning job has been cancelled.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobCancelled {
    /// The Unix timestamp (in seconds) of when the fine-tuning job was cancelled.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookFineTuningJobData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a fine-tuning job has failed.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobFailed {
    /// The Unix timestamp (in seconds) of when the fine-tuning job failed.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookFineTuningJobData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a fine-tuning job has succeeded.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobSucceeded {
    /// The Unix timestamp (in seconds) of when the fine-tuning job succeeded.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookFineTuningJobData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Data payload for fine-tuning job webhook events.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobData {
    /// The unique ID of the fine-tuning job.
    pub id: String,
}

// EventType and EventId implementations for fine-tuning job events

/// Sent when Realtime API receives an incoming SIP call.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookRealtimeCallIncoming {
    /// The Unix timestamp (in seconds) of when the model response was completed.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookRealtimeCallData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Data payload for realtime call webhook events.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookRealtimeCallData {
    /// The unique ID of this call.
    pub call_id: String,

    /// Headers from the SIP Invite.
    pub sip_headers: Vec<SipHeader>,
}

/// A header from the SIP Invite.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct SipHeader {
    /// Name of the SIP Header.
    pub name: String,

    /// Value of the SIP Header.
    pub value: String,
}

/// Sent when a background response has been cancelled.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseCancelled {
    /// The Unix timestamp (in seconds) of when the model response was cancelled.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookResponseData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a background response has been completed.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseCompleted {
    /// The Unix timestamp (in seconds) of when the model response was completed.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookResponseData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a background response has failed.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseFailed {
    /// The Unix timestamp (in seconds) of when the model response failed.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookResponseData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Sent when a background response has been interrupted.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseIncomplete {
    /// The Unix timestamp (in seconds) of when the model response was interrupted.
    pub created_at: u64,

    /// The unique ID of the event.
    pub id: String,

    /// Event data payload.
    pub data: WebhookResponseData,

    /// The object of the event. Always `event`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub object: Option<String>,
}

/// Data payload for response webhook events.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseData {
    /// The unique ID of the model response.
    pub id: String,
}

// EventType and EventId implementations for response events

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type")]
pub enum WebhookEvent {
    #[serde(rename = "batch.cancelled")]
    BatchCancelled(WebhookBatchCancelled),

    #[serde(rename = "batch.completed")]
    BatchCompleted(WebhookBatchCompleted),

    #[serde(rename = "batch.expired")]
    BatchExpired(WebhookBatchExpired),

    #[serde(rename = "batch.failed")]
    BatchFailed(WebhookBatchFailed),

    #[serde(rename = "eval.run.canceled")]
    EvalRunCanceled(WebhookEvalRunCanceled),

    #[serde(rename = "eval.run.failed")]
    EvalRunFailed(WebhookEvalRunFailed),

    #[serde(rename = "eval.run.succeeded")]
    EvalRunSucceeded(WebhookEvalRunSucceeded),

    #[serde(rename = "fine_tuning.job.cancelled")]
    FineTuningJobCancelled(WebhookFineTuningJobCancelled),

    #[serde(rename = "fine_tuning.job.failed")]
    FineTuningJobFailed(WebhookFineTuningJobFailed),

    #[serde(rename = "fine_tuning.job.succeeded")]
    FineTuningJobSucceeded(WebhookFineTuningJobSucceeded),

    #[serde(rename = "realtime.call.incoming")]
    RealtimeCallIncoming(WebhookRealtimeCallIncoming),

    #[serde(rename = "response.cancelled")]
    ResponseCancelled(WebhookResponseCancelled),

    #[serde(rename = "response.completed")]
    ResponseCompleted(WebhookResponseCompleted),

    #[serde(rename = "response.failed")]
    ResponseFailed(WebhookResponseFailed),

    #[serde(rename = "response.incomplete")]
    ResponseIncomplete(WebhookResponseIncomplete),
}

// Implement EventType trait for all event types in this file
#[cfg(feature = "_api")]
macro_rules! impl_event_type {
    ($($ty:ty => $event_type:expr),* $(,)?) => {
        $(
            impl crate::traits::EventType for $ty {
                fn event_type(&self) -> &'static str {
                    $event_type
                }
            }
        )*
    };
}

#[cfg(feature = "_api")]
macro_rules! impl_event_id {
    ($($ty:ty),* $(,)?) => {
        $(
            impl crate::traits::EventId for $ty {
                fn event_id(&self) -> &str {
                    &self.id
                }
            }
        )*
    };
}
// Use the macro to implement EventType for all webhook event structs
#[cfg(feature = "_api")]
impl_event_type! {
    WebhookBatchCancelled => "batch.cancelled",
    WebhookBatchCompleted => "batch.completed",
    WebhookBatchExpired => "batch.expired",
    WebhookBatchFailed => "batch.failed",
    WebhookEvalRunCanceled => "eval.run.canceled",
    WebhookEvalRunFailed => "eval.run.failed",
    WebhookEvalRunSucceeded => "eval.run.succeeded",
    WebhookFineTuningJobCancelled => "fine_tuning.job.cancelled",
    WebhookFineTuningJobFailed => "fine_tuning.job.failed",
    WebhookFineTuningJobSucceeded => "fine_tuning.job.succeeded",
    WebhookRealtimeCallIncoming => "realtime.call.incoming",
    WebhookResponseCancelled => "response.cancelled",
    WebhookResponseCompleted => "response.completed",
    WebhookResponseFailed => "response.failed",
    WebhookResponseIncomplete => "response.incomplete",
}

// Use the macro to implement EventId for all webhook event structs
#[cfg(feature = "_api")]
impl_event_id! {
    WebhookBatchCancelled,
    WebhookBatchCompleted,
    WebhookBatchExpired,
    WebhookBatchFailed,
    WebhookEvalRunCanceled,
    WebhookEvalRunFailed,
    WebhookEvalRunSucceeded,
    WebhookFineTuningJobCancelled,
    WebhookFineTuningJobFailed,
    WebhookFineTuningJobSucceeded,
    WebhookRealtimeCallIncoming,
    WebhookResponseCancelled,
    WebhookResponseCompleted,
    WebhookResponseFailed,
    WebhookResponseIncomplete,
}

// Trait implementations for WebhookEvent enum
#[cfg(feature = "_api")]
impl crate::traits::EventType for WebhookEvent {
    fn event_type(&self) -> &'static str {
        match self {
            WebhookEvent::BatchCancelled(e) => e.event_type(),
            WebhookEvent::BatchCompleted(e) => e.event_type(),
            WebhookEvent::BatchExpired(e) => e.event_type(),
            WebhookEvent::BatchFailed(e) => e.event_type(),
            WebhookEvent::EvalRunCanceled(e) => e.event_type(),
            WebhookEvent::EvalRunFailed(e) => e.event_type(),
            WebhookEvent::EvalRunSucceeded(e) => e.event_type(),
            WebhookEvent::FineTuningJobCancelled(e) => e.event_type(),
            WebhookEvent::FineTuningJobFailed(e) => e.event_type(),
            WebhookEvent::FineTuningJobSucceeded(e) => e.event_type(),
            WebhookEvent::RealtimeCallIncoming(e) => e.event_type(),
            WebhookEvent::ResponseCancelled(e) => e.event_type(),
            WebhookEvent::ResponseCompleted(e) => e.event_type(),
            WebhookEvent::ResponseFailed(e) => e.event_type(),
            WebhookEvent::ResponseIncomplete(e) => e.event_type(),
        }
    }
}

#[cfg(feature = "_api")]
impl crate::traits::EventId for WebhookEvent {
    fn event_id(&self) -> &str {
        match self {
            WebhookEvent::BatchCancelled(e) => e.event_id(),
            WebhookEvent::BatchCompleted(e) => e.event_id(),
            WebhookEvent::BatchExpired(e) => e.event_id(),
            WebhookEvent::BatchFailed(e) => e.event_id(),
            WebhookEvent::EvalRunCanceled(e) => e.event_id(),
            WebhookEvent::EvalRunFailed(e) => e.event_id(),
            WebhookEvent::EvalRunSucceeded(e) => e.event_id(),
            WebhookEvent::FineTuningJobCancelled(e) => e.event_id(),
            WebhookEvent::FineTuningJobFailed(e) => e.event_id(),
            WebhookEvent::FineTuningJobSucceeded(e) => e.event_id(),
            WebhookEvent::RealtimeCallIncoming(e) => e.event_id(),
            WebhookEvent::ResponseCancelled(e) => e.event_id(),
            WebhookEvent::ResponseCompleted(e) => e.event_id(),
            WebhookEvent::ResponseFailed(e) => e.event_id(),
            WebhookEvent::ResponseIncomplete(e) => e.event_id(),
        }
    }
}

impl WebhookEvent {
    /// Get the timestamp when the event was created
    pub fn created_at(&self) -> u64 {
        match self {
            WebhookEvent::BatchCancelled(w) => w.created_at,
            WebhookEvent::BatchCompleted(w) => w.created_at,
            WebhookEvent::BatchExpired(w) => w.created_at,
            WebhookEvent::BatchFailed(w) => w.created_at,
            WebhookEvent::EvalRunCanceled(w) => w.created_at,
            WebhookEvent::EvalRunFailed(w) => w.created_at,
            WebhookEvent::EvalRunSucceeded(w) => w.created_at,
            WebhookEvent::FineTuningJobCancelled(w) => w.created_at,
            WebhookEvent::FineTuningJobFailed(w) => w.created_at,
            WebhookEvent::FineTuningJobSucceeded(w) => w.created_at,
            WebhookEvent::RealtimeCallIncoming(w) => w.created_at,
            WebhookEvent::ResponseCancelled(w) => w.created_at,
            WebhookEvent::ResponseCompleted(w) => w.created_at,
            WebhookEvent::ResponseFailed(w) => w.created_at,
            WebhookEvent::ResponseIncomplete(w) => w.created_at,
        }
    }
}