#![allow(
missing_docs,
reason = "fields mirror pi's TypeScript types; contracts are noted where they differ from the name"
)]
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use crate::message::{ImageContent, TextContent, Usage};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BoolCriteria {
#[serde(rename = "true")]
pub yes: String,
#[serde(rename = "false")]
pub no: String,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ClassifierQuestion {
Choice {
instructions: String,
criteria: IndexMap<String, String>,
},
Score {
instructions: String,
criteria: Vec<String>,
},
Bool {
instructions: String,
criteria: BoolCriteria,
},
}
impl ClassifierQuestion {
pub fn instructions(&self) -> &str {
match self {
ClassifierQuestion::Choice { instructions, .. }
| ClassifierQuestion::Score { instructions, .. }
| ClassifierQuestion::Bool { instructions, .. } => instructions,
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ClassifierContext {
pub state: Map<String, Value>,
pub questions: IndexMap<String, ClassifierQuestion>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ClassifierAnswer {
Choice {
choice: String,
probabilities: IndexMap<String, f64>,
confidence: f64,
},
Score {
score: f64,
confidence: f64,
},
Bool {
probability: f64,
},
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum OutcomeReason {
Stop,
Error,
Aborted,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClassifierResult {
pub api: String,
pub provider: String,
pub model: String,
pub answers: IndexMap<String, ClassifierAnswer>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub usage: Option<Usage>,
pub stop_reason: OutcomeReason,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub error_message: Option<String>,
pub timestamp: u64,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum ImagesContent {
Text(TextContent),
Image(ImageContent),
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ImagesContext {
pub input: Vec<ImagesContent>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AssistantImages {
pub api: String,
pub provider: String,
pub model: String,
pub output: Vec<ImagesContent>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub response_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub usage: Option<Usage>,
pub stop_reason: OutcomeReason,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub error_message: Option<String>,
pub timestamp: u64,
}