gproxy_protocol/openai/common/
formats.rs1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use super::{JsonSchema, Rest};
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(untagged)]
8pub enum ChatResponseFormat {
9 JsonSchema(ChatJsonSchemaFormat),
10 Text(TextResponseFormat),
11 JsonObject(JsonObjectResponseFormat),
12 Unknown(Value),
13}
14
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
16#[serde(untagged)]
17pub enum ResponseFormat {
18 JsonSchema(JsonSchemaResponseFormat),
19 Text(TextResponseFormat),
20 JsonObject(JsonObjectResponseFormat),
21 Unknown(Value),
22}
23
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
25#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
26pub struct TextResponseFormat {
27 #[serde(rename = "type")]
28 pub type_: TextResponseFormatType,
29 #[serde(default, flatten)]
30 pub rest: Rest,
31}
32
33strict_string_enum!(TextResponseFormatType { Text => "text" });
34
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
36#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
37pub struct ChatJsonSchemaFormat {
38 #[serde(rename = "type")]
39 pub type_: JsonSchemaResponseFormatType,
40 pub json_schema: JsonSchemaFormat,
41 #[serde(default, flatten)]
42 pub rest: Rest,
43}
44
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
46#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
47pub struct JsonSchemaResponseFormat {
48 #[serde(rename = "type")]
49 pub type_: JsonSchemaResponseFormatType,
50 pub name: String,
51 pub schema: JsonSchema,
52 #[serde(skip_serializing_if = "Option::is_none")]
53 pub description: Option<String>,
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub strict: Option<bool>,
56 #[serde(default, flatten)]
57 pub rest: Rest,
58}
59
60strict_string_enum!(JsonSchemaResponseFormatType { JsonSchema => "json_schema" });
61
62#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
63#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
64pub struct JsonObjectResponseFormat {
65 #[serde(rename = "type")]
66 pub type_: JsonObjectResponseFormatType,
67 #[serde(default, flatten)]
68 pub rest: Rest,
69}
70
71strict_string_enum!(JsonObjectResponseFormatType { JsonObject => "json_object" });
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
74#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
75pub struct JsonSchemaFormat {
76 pub name: String,
77 #[serde(skip_serializing_if = "Option::is_none")]
78 pub description: Option<String>,
79 #[serde(skip_serializing_if = "Option::is_none")]
80 pub schema: Option<JsonSchema>,
81 #[serde(skip_serializing_if = "Option::is_none")]
82 pub strict: Option<bool>,
83 #[serde(default, flatten)]
84 pub rest: Rest,
85}