Skip to main content

openai_types/graders/
_gen.rs

1// AUTO-GENERATED by py2rust — do not edit.
2// Re-generate: python3 scripts/py2rust.py sync <python_dir> <rust_dir>
3// Domain: graders
4
5use serde::{Deserialize, Serialize};
6
7/// A text output from the model.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
10pub struct GraderInputItemOutputText {
11    /// The text output from the model.
12    pub text: String,
13    /// The type of the output text. Always `output_text`.
14    #[serde(rename = "type")]
15    pub type_: String,
16}
17
18/// An image input block used within EvalItem content arrays.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
21pub struct GraderInputItemInputImage {
22    /// The URL of the image input.
23    pub image_url: String,
24    /// The type of the image input. Always `input_image`.
25    #[serde(rename = "type")]
26    pub type_: String,
27    /// The detail level of the image to be sent to the model.
28    #[serde(skip_serializing_if = "Option::is_none", default)]
29    pub detail: Option<String>,
30}
31
32pub type GraderInputItem = serde_json::Value;
33
34pub type GraderInputs = Vec<GraderInputItem>;
35
36/// A text output from the model.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
39pub struct InputContentOutputText {
40    /// The text output from the model.
41    pub text: String,
42    /// The type of the output text. Always `output_text`.
43    #[serde(rename = "type")]
44    pub type_: String,
45}
46
47/// An image input block used within EvalItem content arrays.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
50pub struct InputContentInputImage {
51    /// The URL of the image input.
52    pub image_url: String,
53    /// The type of the image input. Always `input_image`.
54    #[serde(rename = "type")]
55    pub type_: String,
56    /// The detail level of the image to be sent to the model.
57    #[serde(skip_serializing_if = "Option::is_none", default)]
58    pub detail: Option<String>,
59}
60
61pub type InputContent = serde_json::Value;
62
63#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
64#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
65#[non_exhaustive]
66pub enum InputRole {
67    #[serde(rename = "user")]
68    User,
69    #[serde(rename = "assistant")]
70    Assistant,
71    #[serde(rename = "system")]
72    System,
73    #[serde(rename = "developer")]
74    Developer,
75}
76
77/// A message input to the model with a role indicating instruction following
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
80pub struct Input {
81    /// Inputs to the model - can contain template strings.
82    pub content: InputContent,
83    /// The role of the message input.
84    pub role: InputRole,
85    /// The type of the message input. Always `message`.
86    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
87    pub type_: Option<String>,
88}
89
90/// A LabelModelGrader object which uses a model to assign labels to each item
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
93pub struct LabelModelGrader {
94    pub input: Vec<Input>,
95    /// The labels to assign to each item in the evaluation.
96    pub labels: Vec<String>,
97    /// The model to use for the evaluation. Must support structured outputs.
98    pub model: String,
99    /// The name of the grader.
100    pub name: String,
101    /// The labels that indicate a passing result. Must be a subset of labels.
102    pub passing_labels: Vec<String>,
103    /// The object type, which is always `label_model`.
104    #[serde(rename = "type")]
105    pub type_: String,
106}
107
108pub type Graders = serde_json::Value;
109
110/// A MultiGrader object combines the output of multiple graders to produce a single score.
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
113pub struct MultiGrader {
114    /// A formula to calculate the output based on grader results.
115    pub calculate_output: String,
116    /// A StringCheckGrader object that performs a string comparison between input and
117    pub graders: Graders,
118    /// The name of the grader.
119    pub name: String,
120    /// The object type, which is always `multi`.
121    #[serde(rename = "type")]
122    pub type_: String,
123}
124
125/// A PythonGrader object that runs a python script on the input.
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
128pub struct PythonGrader {
129    /// The name of the grader.
130    pub name: String,
131    /// The source code of the python script.
132    pub source: String,
133    /// The object type, which is always `python`.
134    #[serde(rename = "type")]
135    pub type_: String,
136    /// The image tag to use for the python script.
137    #[serde(skip_serializing_if = "Option::is_none", default)]
138    pub image_tag: Option<String>,
139}
140
141/// The sampling parameters for the model.
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
144pub struct SamplingParams {
145    /// The maximum number of tokens the grader model may generate in its response.
146    #[serde(skip_serializing_if = "Option::is_none", default)]
147    pub max_completions_tokens: Option<i64>,
148    /// Constrains effort on reasoning for
149    #[serde(skip_serializing_if = "Option::is_none", default)]
150    pub reasoning_effort: Option<serde_json::Value>,
151    /// A seed value to initialize the randomness, during sampling.
152    #[serde(skip_serializing_if = "Option::is_none", default)]
153    pub seed: Option<i64>,
154    /// A higher temperature increases randomness in the outputs.
155    #[serde(skip_serializing_if = "Option::is_none", default)]
156    pub temperature: Option<f64>,
157    /// An alternative to temperature for nucleus sampling; 1.0 includes all tokens.
158    #[serde(skip_serializing_if = "Option::is_none", default)]
159    pub top_p: Option<f64>,
160}
161
162/// A ScoreModelGrader object that uses a model to assign a score to the input.
163#[derive(Debug, Clone, Serialize, Deserialize)]
164#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
165pub struct ScoreModelGrader {
166    /// The input messages evaluated by the grader.
167    pub input: Vec<Input>,
168    /// The model to use for the evaluation.
169    pub model: String,
170    /// The name of the grader.
171    pub name: String,
172    /// The object type, which is always `score_model`.
173    #[serde(rename = "type")]
174    pub type_: String,
175    /// The range of the score. Defaults to `[0, 1]`.
176    #[serde(skip_serializing_if = "Option::is_none", default)]
177    pub range: Option<Vec<f64>>,
178    /// The sampling parameters for the model.
179    #[serde(skip_serializing_if = "Option::is_none", default)]
180    pub sampling_params: Option<SamplingParams>,
181}
182
183#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
184#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
185#[non_exhaustive]
186pub enum StringCheckGraderOperation {
187    #[serde(rename = "eq")]
188    Eq,
189    #[serde(rename = "ne")]
190    Ne,
191    #[serde(rename = "like")]
192    Like,
193    #[serde(rename = "ilike")]
194    Ilike,
195}
196
197/// A StringCheckGrader object that performs a string comparison between input and reference using a specified operation.
198#[derive(Debug, Clone, Serialize, Deserialize)]
199#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
200pub struct StringCheckGrader {
201    /// The input text. This may include template strings.
202    pub input: String,
203    /// The name of the grader.
204    pub name: String,
205    /// The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`.
206    pub operation: StringCheckGraderOperation,
207    /// The reference text. This may include template strings.
208    pub reference: String,
209    /// The object type, which is always `string_check`.
210    #[serde(rename = "type")]
211    pub type_: String,
212}
213
214#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
215#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
216#[non_exhaustive]
217pub enum TextSimilarityGraderEvaluationMetric {
218    #[serde(rename = "cosine")]
219    Cosine,
220    #[serde(rename = "fuzzy_match")]
221    FuzzyMatch,
222    #[serde(rename = "bleu")]
223    Bleu,
224    #[serde(rename = "gleu")]
225    Gleu,
226    #[serde(rename = "meteor")]
227    Meteor,
228    #[serde(rename = "rouge_1")]
229    Rouge1,
230    #[serde(rename = "rouge_2")]
231    Rouge2,
232    #[serde(rename = "rouge_3")]
233    Rouge3,
234    #[serde(rename = "rouge_4")]
235    Rouge4,
236    #[serde(rename = "rouge_5")]
237    Rouge5,
238    #[serde(rename = "rouge_l")]
239    RougeL,
240}
241
242/// A TextSimilarityGrader object which grades text based on similarity metrics.
243#[derive(Debug, Clone, Serialize, Deserialize)]
244#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
245pub struct TextSimilarityGrader {
246    /// The evaluation metric to use.
247    pub evaluation_metric: TextSimilarityGraderEvaluationMetric,
248    /// The text being graded.
249    pub input: String,
250    /// The name of the grader.
251    pub name: String,
252    /// The text being graded against.
253    pub reference: String,
254    /// The type of grader.
255    #[serde(rename = "type")]
256    pub type_: String,
257}