langchain_rust/prompt/
mod.rs1mod chat;
2mod error;
3mod prompt;
4
5use std::collections::HashMap;
6
7pub use chat::*;
8pub use error::*;
9pub use prompt::*;
10use serde_json::Value;
11
12use crate::schemas::{messages::Message, prompt::PromptValue};
13
14pub type PromptArgs = HashMap<String, Value>;
16pub trait PromptFromatter: Send + Sync {
17 fn template(&self) -> String;
18 fn variables(&self) -> Vec<String>;
19 fn format(&self, input_variables: PromptArgs) -> Result<String, PromptError>;
20}
21impl<PA> From<PA> for Box<dyn PromptFromatter>
22where
23 PA: PromptFromatter + 'static,
24{
25 fn from(prompt: PA) -> Self {
26 Box::new(prompt)
27 }
28}
29
30pub trait MessageFormatter: Send + Sync {
32 fn format_messages(&self, input_variables: PromptArgs) -> Result<Vec<Message>, PromptError>;
33
34 fn input_variables(&self) -> Vec<String>;
36}
37impl<MF> From<MF> for Box<dyn MessageFormatter>
38where
39 MF: MessageFormatter + 'static,
40{
41 fn from(prompt: MF) -> Self {
42 Box::new(prompt)
43 }
44}
45
46pub trait FormatPrompter: Send + Sync {
47 fn format_prompt(&self, input_variables: PromptArgs) -> Result<PromptValue, PromptError>;
48 fn get_input_variables(&self) -> Vec<String>;
49}
50impl<FP> From<FP> for Box<dyn FormatPrompter>
51where
52 FP: FormatPrompter + 'static,
53{
54 fn from(prompt: FP) -> Self {
55 Box::new(prompt)
56 }
57}