Macro llm_chain::prompt

source ·
macro_rules! prompt {
    (user: $user_arg:expr $(,)?) => { ... };
    (assistant: $assistant_arg:expr $(,)?) => { ... };
    (system: $system_arg:expr $(,)?) => { ... };
    ($single_arg:expr) => { ... };
    ($system_arg:expr, $user_arg:expr $(,)?) => { ... };
    ($($extra_tokens:expr),+ $(,)?) => { ... };
}
Expand description

Creates a TextPrompt or a ChatPrompt based on the number of arguments provided.

If there is only one argument, it creates a TextPrompt with the provided template. However, if you prefix it with system:, assistant: or user: it will create a ChatPrompt with the provided template as the system, assistant or user message respectively. If there are two arguments, it creates a ChatPrompt with the first message as the system message and the second message as the user message. You may add a “conversation: your_conversation” to include a conversation. If there are more than two arguments, a compile-time error is produced.

Example

use llm_chain::prompt;
let text_prompt = prompt!("Hello {{name}}!");
assert_eq!(format!("{}", text_prompt), "Hello {{name}}!");

let chat_prompt = prompt!("You are a helpful assistant.", "What is the meaning of life?");
assert_eq!(format!("{}", chat_prompt), "System: You are a helpful assistant.\nUser: What is the meaning of life?\n");

let role_prompt = prompt!(system: "You are a helpful assistant.");
assert_eq!(format!("{}", role_prompt), "System: You are a helpful assistant.\n");