openai-types 0.1.2

Typed OpenAI API models — zero dependencies beyond serde
Documentation
// AUTO-GENERATED by py2rust — do not edit.
// Re-generate: python3 scripts/py2rust.py sync <python_dir> <rust_dir>
// Domain: graders

use serde::{Deserialize, Serialize};

/// A text output from the model.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct GraderInputItemOutputText {
    /// The text output from the model.
    pub text: String,
    /// The type of the output text. Always `output_text`.
    #[serde(rename = "type")]
    pub type_: String,
}

/// An image input block used within EvalItem content arrays.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct GraderInputItemInputImage {
    /// The URL of the image input.
    pub image_url: String,
    /// The type of the image input. Always `input_image`.
    #[serde(rename = "type")]
    pub type_: String,
    /// The detail level of the image to be sent to the model.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub detail: Option<String>,
}

pub type GraderInputItem = serde_json::Value;

pub type GraderInputs = Vec<GraderInputItem>;

/// A text output from the model.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct InputContentOutputText {
    /// The text output from the model.
    pub text: String,
    /// The type of the output text. Always `output_text`.
    #[serde(rename = "type")]
    pub type_: String,
}

/// An image input block used within EvalItem content arrays.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct InputContentInputImage {
    /// The URL of the image input.
    pub image_url: String,
    /// The type of the image input. Always `input_image`.
    #[serde(rename = "type")]
    pub type_: String,
    /// The detail level of the image to be sent to the model.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub detail: Option<String>,
}

pub type InputContent = serde_json::Value;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum InputRole {
    #[serde(rename = "user")]
    User,
    #[serde(rename = "assistant")]
    Assistant,
    #[serde(rename = "system")]
    System,
    #[serde(rename = "developer")]
    Developer,
}

/// A message input to the model with a role indicating instruction following
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct Input {
    /// Inputs to the model - can contain template strings.
    pub content: InputContent,
    /// The role of the message input.
    pub role: InputRole,
    /// The type of the message input. Always `message`.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
    pub type_: Option<String>,
}

/// A LabelModelGrader object which uses a model to assign labels to each item
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct LabelModelGrader {
    pub input: Vec<Input>,
    /// The labels to assign to each item in the evaluation.
    pub labels: Vec<String>,
    /// The model to use for the evaluation. Must support structured outputs.
    pub model: String,
    /// The name of the grader.
    pub name: String,
    /// The labels that indicate a passing result. Must be a subset of labels.
    pub passing_labels: Vec<String>,
    /// The object type, which is always `label_model`.
    #[serde(rename = "type")]
    pub type_: String,
}

pub type Graders = serde_json::Value;

/// A MultiGrader object combines the output of multiple graders to produce a single score.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct MultiGrader {
    /// A formula to calculate the output based on grader results.
    pub calculate_output: String,
    /// A StringCheckGrader object that performs a string comparison between input and
    pub graders: Graders,
    /// The name of the grader.
    pub name: String,
    /// The object type, which is always `multi`.
    #[serde(rename = "type")]
    pub type_: String,
}

/// A PythonGrader object that runs a python script on the input.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct PythonGrader {
    /// The name of the grader.
    pub name: String,
    /// The source code of the python script.
    pub source: String,
    /// The object type, which is always `python`.
    #[serde(rename = "type")]
    pub type_: String,
    /// The image tag to use for the python script.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub image_tag: Option<String>,
}

/// The sampling parameters for the model.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct SamplingParams {
    /// The maximum number of tokens the grader model may generate in its response.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub max_completions_tokens: Option<i64>,
    /// Constrains effort on reasoning for
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub reasoning_effort: Option<serde_json::Value>,
    /// A seed value to initialize the randomness, during sampling.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub seed: Option<i64>,
    /// A higher temperature increases randomness in the outputs.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub temperature: Option<f64>,
    /// An alternative to temperature for nucleus sampling; 1.0 includes all tokens.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub top_p: Option<f64>,
}

/// A ScoreModelGrader object that uses a model to assign a score to the input.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct ScoreModelGrader {
    /// The input messages evaluated by the grader.
    pub input: Vec<Input>,
    /// The model to use for the evaluation.
    pub model: String,
    /// The name of the grader.
    pub name: String,
    /// The object type, which is always `score_model`.
    #[serde(rename = "type")]
    pub type_: String,
    /// The range of the score. Defaults to `[0, 1]`.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub range: Option<Vec<f64>>,
    /// The sampling parameters for the model.
    #[serde(skip_serializing_if = "Option::is_none", default)]
    pub sampling_params: Option<SamplingParams>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum StringCheckGraderOperation {
    #[serde(rename = "eq")]
    Eq,
    #[serde(rename = "ne")]
    Ne,
    #[serde(rename = "like")]
    Like,
    #[serde(rename = "ilike")]
    Ilike,
}

/// A StringCheckGrader object that performs a string comparison between input and reference using a specified operation.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct StringCheckGrader {
    /// The input text. This may include template strings.
    pub input: String,
    /// The name of the grader.
    pub name: String,
    /// The string check operation to perform. One of `eq`, `ne`, `like`, or `ilike`.
    pub operation: StringCheckGraderOperation,
    /// The reference text. This may include template strings.
    pub reference: String,
    /// The object type, which is always `string_check`.
    #[serde(rename = "type")]
    pub type_: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum TextSimilarityGraderEvaluationMetric {
    #[serde(rename = "cosine")]
    Cosine,
    #[serde(rename = "fuzzy_match")]
    FuzzyMatch,
    #[serde(rename = "bleu")]
    Bleu,
    #[serde(rename = "gleu")]
    Gleu,
    #[serde(rename = "meteor")]
    Meteor,
    #[serde(rename = "rouge_1")]
    Rouge1,
    #[serde(rename = "rouge_2")]
    Rouge2,
    #[serde(rename = "rouge_3")]
    Rouge3,
    #[serde(rename = "rouge_4")]
    Rouge4,
    #[serde(rename = "rouge_5")]
    Rouge5,
    #[serde(rename = "rouge_l")]
    RougeL,
}

/// A TextSimilarityGrader object which grades text based on similarity metrics.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct TextSimilarityGrader {
    /// The evaluation metric to use.
    pub evaluation_metric: TextSimilarityGraderEvaluationMetric,
    /// The text being graded.
    pub input: String,
    /// The name of the grader.
    pub name: String,
    /// The text being graded against.
    pub reference: String,
    /// The type of grader.
    #[serde(rename = "type")]
    pub type_: String,
}