pub mod adapter;
pub mod core;
pub mod data;
pub mod evaluate;
pub mod optimizer;
pub mod predictors;
pub mod utils;
pub use adapter::chat::*;
pub use core::*;
pub use data::*;
pub use evaluate::*;
pub use optimizer::*;
pub use predictors::*;
pub use utils::*;
pub use dsrs_macros::*;
#[macro_export]
macro_rules! example {
{ $($key:literal : $field_type:literal => $value:expr),* $(,)? } => {{
use std::collections::HashMap;
use dspy_rs::data::example::Example;
let mut input_keys = vec![];
let mut output_keys = vec![];
let mut fields = HashMap::new();
$(
if $field_type == "input" {
input_keys.push($key.to_string());
} else {
output_keys.push($key.to_string());
}
fields.insert($key.to_string(), serde_json::to_value($value).unwrap());
)*
Example::new(
fields,
input_keys,
output_keys,
)
}};
}
#[macro_export]
macro_rules! prediction {
{ $($key:literal => $value:expr),* $(,)? } => {{
use std::collections::HashMap;
use dspy_rs::{Prediction, LmUsage};
let mut fields = HashMap::new();
$(
fields.insert($key.to_string(), serde_json::to_value($value).unwrap());
)*
Prediction::new(fields, LmUsage::default())
}};
}
#[macro_export]
macro_rules! field {
{ $($field_type:ident[$desc:literal] => $field_name:ident : $field_ty:ty),* $(,)? } => {{
use serde_json::json;
let mut result = serde_json::Map::new();
$(
let type_str = stringify!($field_ty);
let schema = {
let schema = schemars::schema_for!($field_ty);
let schema_json = serde_json::to_value(schema).unwrap();
if let Some(obj) = schema_json.as_object() {
if obj.contains_key("properties") {
schema_json["properties"].clone()
} else {
"".to_string().into()
}
} else {
"".to_string().into()
}
};
result.insert(
stringify!($field_name).to_string(),
json!({
"type": type_str,
"desc": $desc,
"schema": schema,
"__dsrs_field_type": stringify!($field_type)
})
);
)*
serde_json::Value::Object(result)
}};
{ $($field_type:ident => $field_name:ident : $field_ty:ty),* $(,)? } => {{
use serde_json::json;
let mut result = serde_json::Map::new();
$(
let type_str = stringify!($field_ty);
let schema = {
let schema = schemars::schema_for!($field_ty);
let schema_json = serde_json::to_value(schema).unwrap();
if let Some(obj) = schema_json.as_object() {
if obj.contains_key("properties") {
schema_json["properties"].clone()
} else {
"".to_string().into()
}
} else {
"".to_string().into()
}
};
result.insert(
stringify!($field_name).to_string(),
json!({
"type": type_str,
"desc": "",
"schema": schema,
"__dsrs_field_type": stringify!($field_type)
})
);
)*
serde_json::Value::Object(result)
}};
}
#[macro_export]
macro_rules! sign {
{ ($($input_name:ident : $input_type:ty),* $(,)?) -> $($output_name:ident : $output_type:ty),* $(,)? } => {{
use dspy_rs::Signature;
let mut input_fields = serde_json::Map::new();
let mut output_fields = serde_json::Map::new();
#[Signature]
struct InlineSignature {
$(
#[input]
$input_name: $input_type,
)*
$(
#[output]
$output_name: $output_type,
)*
}
InlineSignature::new()
}};
}
#[macro_export]
macro_rules! hashmap {
() => {
::std::collections::HashMap::new()
};
($($key:expr => $value:expr),+ $(,)?) => {
::std::collections::HashMap::from([ $(($key, $value)),* ])
};
}