gbserver/src/services/keywords/llm_keyword.rs
Rodrigo Rodriguez (Pragmatismo) 50bfad7642
Some checks are pending
GBCI / build (push) Waiting to run
- First run to generate e-mail.
2025-08-02 00:07:54 -03:00

28 lines
950 B
Rust

use rhai::{Dynamic, Engine};
use crate::services::{state::AppState, utils::call_llm};
pub fn llm_keyword(state: &AppState, engine: &mut Engine) {
let ai_config = state.config.clone().unwrap().ai.clone();
engine.register_custom_syntax(
&["LLM", "$expr$"], // Syntax: LLM "text to process"
false, // Expression, not statement
move |context, inputs| {
let text = context.eval_expression_tree(&inputs[0])?;
let text_str = text.to_string();
println!("LLM processing text: {}", text_str);
// Use the same pattern as GET
let fut = call_llm(
&text_str, &ai_config);
let result = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(fut)
}).map_err(|e| format!("LLM call failed: {}", e))?;
Ok(Dynamic::from(result))
}
).unwrap();
}