gproxy_protocol/openai/common/
types.rs1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use serde_json::{Map, Value};
5
6use crate::OperationKey;
7
8use super::{OpenAiModelId, PromptCacheBreakpointMode, PromptCacheMode, PromptCacheTtl};
9
10pub type Rest = Map<String, Value>;
11pub type JsonSchema = Map<String, Value>;
12pub type LogitBias = BTreeMap<String, f64>;
13pub type Metadata = BTreeMap<String, String>;
14
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
16#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
17pub struct PromptCacheOptions {
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub mode: Option<PromptCacheMode>,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub ttl: Option<PromptCacheTtl>,
22 #[serde(default, flatten)]
23 pub rest: Rest,
24}
25
26#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
27#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
28pub struct PromptCacheBreakpoint {
29 pub mode: PromptCacheBreakpointMode,
30 #[serde(default, flatten)]
31 pub rest: Rest,
32}
33
34#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
35#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
36pub struct ModerationConfig {
37 pub model: OpenAiModelId,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub policy: Option<ModerationPolicy>,
40 #[serde(default, flatten)]
41 pub rest: Rest,
42}
43
44#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
45#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
46pub struct ModerationPolicy {
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub input: Option<ModerationPolicyRule>,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub output: Option<ModerationPolicyRule>,
51 #[serde(default, flatten)]
52 pub rest: Rest,
53}
54
55#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
56#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
57pub struct ModerationPolicyRule {
58 pub mode: ModerationPolicyMode,
59 #[serde(default, flatten)]
60 pub rest: Rest,
61}
62
63strict_string_enum!(ModerationPolicyMode {
64 Score => "score",
65 Block => "block",
66});
67
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
69#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
70pub struct ModerationResult {
71 pub categories: BTreeMap<String, bool>,
72 pub category_applied_input_types: BTreeMap<String, Vec<ModerationInputType>>,
73 pub category_scores: BTreeMap<String, f64>,
74 pub flagged: bool,
75 pub model: OpenAiModelId,
76 #[serde(rename = "type")]
77 pub type_: ModerationResultType,
78 #[serde(default, flatten)]
79 pub rest: Rest,
80}
81
82#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
83#[serde(rename_all = "snake_case")]
84pub enum ModerationInputType {
85 Text,
86 Image,
87}
88
89#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
90pub enum ModerationResultType {
91 #[serde(rename = "moderation_result")]
92 ModerationResult,
93}
94
95#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
96#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
97pub struct ModerationError {
98 pub code: String,
99 pub message: String,
100 #[serde(rename = "type")]
101 pub type_: ModerationErrorType,
102 #[serde(default, flatten)]
103 pub rest: Rest,
104}
105
106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
107pub enum ModerationErrorType {
108 #[serde(rename = "error")]
109 Error,
110}
111
112#[derive(Debug, Clone, PartialEq, gproxy_protocol_macros::WireBuilder)]
113#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
114pub struct OpenAiWireModel<TRequest, TResponse> {
115 pub operation_key: OperationKey,
116 pub request: Option<TRequest>,
117 pub response: Option<TResponse>,
118 pub rest: Rest,
119}
120
121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum OneOrMany<T> {
124 One(T),
125 Many(Vec<T>),
126}
127
128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum StringOrList {
131 String(String),
132 List(Vec<String>),
133}