Skip to content

Commit aaeb895

Browse files
committed
add ai_func message extender
1 parent eaf750d commit aaeb895

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/helpers/general.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::models::general::llm::Message;
2+
3+
4+
// Extend AI function for specific output
5+
pub fn extend_ai_function(ai_func: fn(&str) -> &'static str, func_input: &str) -> Message {
6+
let ai_function_string = ai_func(func_input);
7+
8+
// Extend the string to encourage only printing the output
9+
10+
let msg: String = format!("FUNCTION {} INSTRUCTION: You are a function printer. \
11+
You ONLY prints the result of a function. \
12+
NOTHING else. \
13+
NO commentary. \
14+
Here is the input to the function: {}", ai_function_string, func_input);
15+
16+
// return Message
17+
Message {
18+
role: "system".to_string(),
19+
content: msg,
20+
}
21+
}
22+
23+
24+
#[cfg(test)]
25+
mod tests {
26+
use crate::ai_functions::ai_func_manager::convert_user_input_to_goal;
27+
use crate::helpers::general::extend_ai_function;
28+
29+
#[test]
30+
fn test_extending_ai_function() {
31+
let extended_string = extend_ai_function(convert_user_input_to_goal, "dummy string");
32+
assert_eq!(extended_string.role, "system".to_string());
33+
dbg!(extended_string);
34+
}
35+
}

src/helpers/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pub mod command_lines;
1+
pub mod command_lines;
2+
pub mod general;

0 commit comments

Comments
 (0)