#[path = "builder/backend.rs"]
mod backend;
#[path = "builder/llm_builder.rs"]
mod llm_builder;
#[path = "builder/validation.rs"]
mod validation;
#[path = "builder/tools.rs"]
mod tools;
#[path = "builder/state.rs"]
mod state;
#[path = "builder/build/mod.rs"]
mod build;
#[path = "builder/memory.rs"]
mod memory;
#[path = "builder/resilience.rs"]
mod resilience;
#[path = "builder/search.rs"]
mod search;
#[path = "builder/azure.rs"]
mod azure;
#[path = "builder/embedding.rs"]
mod embedding;
#[path = "builder/voice.rs"]
mod voice;
use serde::Serialize;
use serde_json::Value;
#[derive(Debug, Clone, Serialize)]
pub struct SystemContent {
pub text: String,
#[serde(rename = "type")]
pub content_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub cache_control: Option<Value>,
}
impl SystemContent {
pub fn text(text: String) -> Self {
Self {
text,
content_type: "text".to_string(),
cache_control: None,
}
}
pub fn text_with_cache(text: String, cache_control: Value) -> Self {
Self {
text,
content_type: "text".to_string(),
cache_control: Some(cache_control),
}
}
}
#[derive(Debug, Clone)]
pub enum SystemPrompt {
String(String),
Messages(Vec<SystemContent>),
}
impl SystemPrompt {
pub fn to_string_representation(self) -> String {
match self {
SystemPrompt::String(s) => s,
SystemPrompt::Messages(messages) => messages
.into_iter()
.map(|m| m.text)
.collect::<Vec<_>>()
.join("\n"),
}
}
}
impl From<SystemPrompt> for String {
fn from(prompt: SystemPrompt) -> String {
prompt.to_string_representation()
}
}
pub trait IntoSystemMessage {
fn into_system_message(self) -> SystemPrompt;
}
impl IntoSystemMessage for String {
fn into_system_message(self) -> SystemPrompt {
SystemPrompt::String(self)
}
}
impl IntoSystemMessage for &str {
fn into_system_message(self) -> SystemPrompt {
SystemPrompt::String(self.to_string())
}
}
impl IntoSystemMessage for Vec<String> {
fn into_system_message(self) -> SystemPrompt {
if self.len() == 1 {
SystemPrompt::String(self.into_iter().next().unwrap())
} else {
SystemPrompt::Messages(self.into_iter().map(SystemContent::text).collect())
}
}
}
impl IntoSystemMessage for Vec<&str> {
fn into_system_message(self) -> SystemPrompt {
if self.len() == 1 {
SystemPrompt::String(self[0].to_string())
} else {
SystemPrompt::Messages(
self.into_iter()
.map(|s| SystemContent::text(s.to_string()))
.collect(),
)
}
}
}
impl IntoSystemMessage for Vec<SystemContent> {
fn into_system_message(self) -> SystemPrompt {
SystemPrompt::Messages(self)
}
}
impl IntoSystemMessage for SystemPrompt {
fn into_system_message(self) -> SystemPrompt {
self
}
}
pub use backend::LLMBackend;
pub use llm_builder::LLMBuilder;
pub use tools::{FunctionBuilder, ParamBuilder};
pub use validation::ValidatorFn;