use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ingredient {
pub kind: IngredientKind,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub provider: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub config: Option<serde_json::Value>,
}
#[derive(Debug)]
pub struct IngredientBuilder {
kind: IngredientKind,
name: String,
provider: Option<String>,
role: Option<String>,
config: Option<serde_json::Value>,
}
impl IngredientBuilder {
pub fn provider(mut self, provider: impl Into<String>) -> Self {
self.provider = Some(provider.into());
self
}
pub fn role(mut self, role: impl Into<String>) -> Self {
self.role = Some(role.into());
self
}
pub fn config(mut self, config: serde_json::Value) -> Self {
self.config = Some(config);
self
}
pub fn build(self) -> Ingredient {
Ingredient {
kind: self.kind,
name: self.name,
provider: self.provider,
role: self.role,
config: self.config,
}
}
}
impl Ingredient {
pub fn model(name: impl Into<String>) -> IngredientBuilder {
IngredientBuilder {
kind: IngredientKind::Model,
name: name.into(),
provider: None,
role: None,
config: None,
}
}
pub fn tool(name: impl Into<String>) -> IngredientBuilder {
IngredientBuilder {
kind: IngredientKind::Tool,
name: name.into(),
provider: None,
role: None,
config: None,
}
}
pub fn prompt(name: impl Into<String>) -> IngredientBuilder {
IngredientBuilder {
kind: IngredientKind::Prompt,
name: name.into(),
provider: None,
role: None,
config: None,
}
}
pub fn data(name: impl Into<String>) -> IngredientBuilder {
IngredientBuilder {
kind: IngredientKind::Data,
name: name.into(),
provider: None,
role: None,
config: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum IngredientKind {
Model,
Tool,
Prompt,
Data,
}