rune-chain-core 0.1.0

Core traits and types for the rune-chain LLM orchestration framework
Documentation
use std::collections::HashMap;

use serde_json::Value;

/// Key-value map of variables substituted into prompt templates.
///
/// Values are [`serde_json::Value`] so that booleans, numbers, lists, and
/// nested objects can be passed alongside plain strings.
pub type PromptArgs = HashMap<String, Value>;

/// Build a [`PromptArgs`] map from key-value pairs.
///
/// Keys are anything that implements `ToString`; values are passed through
/// [`serde_json::json!`] so any JSON-serialisable literal works.
///
/// # Example
///
/// ```rust
/// use rune_chain_core::prompt_args;
///
/// let args = prompt_args! {
///     "name" => "Alice",
///     "age"  => 30,
/// };
///
/// assert_eq!(args["name"], "Alice");
/// assert_eq!(args["age"], 30);
/// ```
#[macro_export]
macro_rules! prompt_args {
    ( $( $key:expr => $val:expr ),* $(,)? ) => {{
        let mut map: ::std::collections::HashMap<String, ::serde_json::Value> =
            ::std::collections::HashMap::new();
        $(
            map.insert($key.to_string(), ::serde_json::json!($val));
        )*
        map
    }};
}