use alloc::string::String;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PromptDefinition {
pub name: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub description: String,
#[serde(default, skip_serializing_if = "alloc::vec::Vec::is_empty")]
pub arguments: alloc::vec::Vec<PromptArgumentDefinition>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PromptArgumentDefinition {
pub name: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub description: String,
#[serde(default)]
pub required: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PromptRole {
User,
Assistant,
System,
}
impl PromptRole {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::User => "user",
Self::Assistant => "assistant",
Self::System => "system",
}
}
}
impl core::fmt::Display for PromptRole {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PromptOutputMessage {
pub role: PromptRole,
pub content: String,
}
impl PromptOutputMessage {
pub fn user(content: impl Into<String>) -> Self {
Self {
role: PromptRole::User,
content: content.into(),
}
}
pub fn assistant(content: impl Into<String>) -> Self {
Self {
role: PromptRole::Assistant,
content: content.into(),
}
}
pub fn system(content: impl Into<String>) -> Self {
Self {
role: PromptRole::System,
content: content.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PromptOutput {
pub messages: alloc::vec::Vec<PromptOutputMessage>,
}
impl PromptOutput {
pub fn user(content: impl Into<String>) -> Self {
Self {
messages: alloc::vec![PromptOutputMessage::user(content)],
}
}
pub fn assistant(content: impl Into<String>) -> Self {
Self {
messages: alloc::vec![PromptOutputMessage::assistant(content)],
}
}
pub fn system(content: impl Into<String>) -> Self {
Self {
messages: alloc::vec![PromptOutputMessage::system(content)],
}
}
}
impl From<String> for PromptOutput {
fn from(content: String) -> Self {
Self::user(content)
}
}
impl From<&str> for PromptOutput {
fn from(content: &str) -> Self {
Self::user(content)
}
}