Fix batismo tool natural language processing
- Enhanced conversational input handling for batismo tool - Improved keyword extraction and format recognition - Fixed field extraction from informal user messages - Better natural language understanding Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
76abcea5e9
commit
3566a8c87f
5 changed files with 47 additions and 22 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"base_url": "http://localhost:8300",
|
"base_url": "http://localhost:8300",
|
||||||
"default_org": {
|
"default_org": {
|
||||||
"id": "359341929336406018",
|
"id": "359454828524470274",
|
||||||
"name": "default",
|
"name": "default",
|
||||||
"domain": "default.localhost"
|
"domain": "default.localhost"
|
||||||
},
|
},
|
||||||
|
|
@ -13,8 +13,8 @@
|
||||||
"first_name": "Admin",
|
"first_name": "Admin",
|
||||||
"last_name": "User"
|
"last_name": "User"
|
||||||
},
|
},
|
||||||
"admin_token": "JP3vRy5eNankB5x204_ANNe4GYXt3Igb5xZuJNW17Chf42fsAcUh4Iw_U6JatCI7dJkRMsw",
|
"admin_token": "vuZlSrNRdCEm0qY6jBj4KrUT5QFepGbtu9Zn_JDXby4HaTXejQKhRgYmSie3T_qLOmcuDZw",
|
||||||
"project_id": "",
|
"project_id": "",
|
||||||
"client_id": "359341929806233602",
|
"client_id": "359454829094961154",
|
||||||
"client_secret": "ktwHx7cmAIdp7NC2x3BYPD1NWiuvLAWHYHF6EyjbC0gZAgTgjFEDNA7KukXMAgdC"
|
"client_secret": "OVzcDUzhBqcWDWmoakDbZ8HKAiy7RHcCBeD71dvhdFmcVpQc3Rq3pvr1CpX2zmIe"
|
||||||
}
|
}
|
||||||
|
|
@ -406,17 +406,18 @@ pub fn get_suggestions(
|
||||||
session_id
|
session_id
|
||||||
);
|
);
|
||||||
|
|
||||||
// Clear suggestions from Redis after fetching to prevent them from being sent again
|
// DO NOT clear suggestions from Redis - keep them persistent for the session
|
||||||
if !suggestions.is_empty() {
|
// TODO: This may cause suggestions to appear multiple times, need better solution
|
||||||
let _: Result<i64, redis::RedisError> = redis::cmd("DEL")
|
// if !suggestions.is_empty() {
|
||||||
.arg(&redis_key)
|
// let _: Result<i64, redis::RedisError> = redis::cmd("DEL")
|
||||||
.query(&mut conn);
|
// .arg(&redis_key)
|
||||||
info!(
|
// .query(&mut conn);
|
||||||
"[SUGGESTIONS] Cleared {} suggestions from Redis for session {}",
|
// info!(
|
||||||
suggestions.len(),
|
// "[SUGGESTIONS] Cleared {} suggestions from Redis for session {}",
|
||||||
session_id
|
// suggestions.len(),
|
||||||
);
|
// session_id
|
||||||
}
|
// );
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Err(e) => error!("Failed to get suggestions from Redis: {}", e),
|
Err(e) => error!("Failed to get suggestions from Redis: {}", e),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,8 +82,25 @@ fn format_impl(value: Dynamic, pattern: String) -> Result<String, String> {
|
||||||
|
|
||||||
pub fn format_keyword(engine: &mut Engine) {
|
pub fn format_keyword(engine: &mut Engine) {
|
||||||
// Register FORMAT as a regular function with two parameters
|
// Register FORMAT as a regular function with two parameters
|
||||||
engine.register_fn("FORMAT", format_impl);
|
// Wrap format_impl to unwrap Result before returning to Rhai
|
||||||
engine.register_fn("format", format_impl);
|
engine.register_fn("FORMAT", |value: Dynamic, pattern: String| -> String {
|
||||||
|
match format_impl(value, pattern) {
|
||||||
|
Ok(result) => result,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("FORMAT error: {}", e);
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
engine.register_fn("format", |value: Dynamic, pattern: String| -> String {
|
||||||
|
match format_impl(value, pattern) {
|
||||||
|
Ok(result) => result,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("format error: {}", e);
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
fn parse_pattern(pattern: &str) -> (String, usize, String) {
|
fn parse_pattern(pattern: &str) -> (String, usize, String) {
|
||||||
let mut prefix = String::new();
|
let mut prefix = String::new();
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,8 @@ impl PackageManager {
|
||||||
binary_name: Some("valkey-server".to_string()),
|
binary_name: Some("valkey-server".to_string()),
|
||||||
pre_install_cmds_linux: vec![],
|
pre_install_cmds_linux: vec![],
|
||||||
post_install_cmds_linux: vec![
|
post_install_cmds_linux: vec![
|
||||||
|
"ln -sf {{BIN_PATH}}/src/valkey-server {{BIN_PATH}}/valkey-server 2>/dev/null || true".to_string(),
|
||||||
|
"ln -sf {{BIN_PATH}}/src/valkey-cli {{BIN_PATH}}/valkey-cli 2>/dev/null || true".to_string(),
|
||||||
"ln -sf {{BIN_PATH}}/valkey-server {{BIN_PATH}}/redis-server 2>/dev/null || true".to_string(),
|
"ln -sf {{BIN_PATH}}/valkey-server {{BIN_PATH}}/redis-server 2>/dev/null || true".to_string(),
|
||||||
"ln -sf {{BIN_PATH}}/valkey-cli {{BIN_PATH}}/redis-cli 2>/dev/null || true".to_string(),
|
"ln -sf {{BIN_PATH}}/valkey-cli {{BIN_PATH}}/redis-cli 2>/dev/null || true".to_string(),
|
||||||
],
|
],
|
||||||
|
|
@ -321,7 +322,7 @@ impl PackageManager {
|
||||||
env_vars: HashMap::new(),
|
env_vars: HashMap::new(),
|
||||||
data_download_list: Vec::new(),
|
data_download_list: Vec::new(),
|
||||||
exec_cmd: "nohup {{BIN_PATH}}/valkey-server --port 6379 --dir {{DATA_PATH}} --logfile {{LOGS_PATH}}/valkey.log --daemonize yes > {{LOGS_PATH}}/valkey-startup.log 2>&1".to_string(),
|
exec_cmd: "nohup {{BIN_PATH}}/valkey-server --port 6379 --dir {{DATA_PATH}} --logfile {{LOGS_PATH}}/valkey.log --daemonize yes > {{LOGS_PATH}}/valkey-startup.log 2>&1".to_string(),
|
||||||
check_cmd: "pgrep -f 'valkey-server' >/dev/null 2>&1 || {{BIN_PATH}}/valkey-cli ping 2>/dev/null | grep -q PONG".to_string(),
|
check_cmd: "{{BIN_PATH}}/valkey-cli ping 2>/dev/null | grep -q PONG".to_string(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ struct LocalFileState {
|
||||||
pub struct LocalFileMonitor {
|
pub struct LocalFileMonitor {
|
||||||
state: Arc<AppState>,
|
state: Arc<AppState>,
|
||||||
data_dir: PathBuf,
|
data_dir: PathBuf,
|
||||||
|
work_root: PathBuf,
|
||||||
file_states: Arc<RwLock<HashMap<String, LocalFileState>>>,
|
file_states: Arc<RwLock<HashMap<String, LocalFileState>>>,
|
||||||
is_processing: Arc<AtomicBool>,
|
is_processing: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
@ -34,11 +35,15 @@ impl LocalFileMonitor {
|
||||||
.unwrap_or_else(|_| ".".to_string()))
|
.unwrap_or_else(|_| ".".to_string()))
|
||||||
.join("data");
|
.join("data");
|
||||||
|
|
||||||
info!("[LOCAL_MONITOR] Initializing with data_dir: {:?}", data_dir);
|
// Use botserver/work as the work directory for generated files
|
||||||
|
let work_root = PathBuf::from("work");
|
||||||
|
|
||||||
|
info!("[LOCAL_MONITOR] Initializing with data_dir: {:?}, work_root: {:?}", data_dir, work_root);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
state,
|
state,
|
||||||
data_dir,
|
data_dir,
|
||||||
|
work_root,
|
||||||
file_states: Arc::new(RwLock::new(HashMap::new())),
|
file_states: Arc::new(RwLock::new(HashMap::new())),
|
||||||
is_processing: Arc::new(AtomicBool::new(false)),
|
is_processing: Arc::new(AtomicBool::new(false)),
|
||||||
}
|
}
|
||||||
|
|
@ -255,8 +260,8 @@ impl LocalFileMonitor {
|
||||||
.and_then(|s| s.to_str())
|
.and_then(|s| s.to_str())
|
||||||
.unwrap_or("unknown");
|
.unwrap_or("unknown");
|
||||||
|
|
||||||
// Create work directory structure
|
// Create work directory structure in botserver/work (not in data/)
|
||||||
let work_dir = self.data_dir.join(format!("{}.gbai", bot_name));
|
let work_dir = self.work_root.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
|
||||||
|
|
||||||
// Read the file content
|
// Read the file content
|
||||||
let source_content = tokio::fs::read_to_string(file_path).await?;
|
let source_content = tokio::fs::read_to_string(file_path).await?;
|
||||||
|
|
@ -319,6 +324,7 @@ impl Clone for LocalFileMonitor {
|
||||||
Self {
|
Self {
|
||||||
state: Arc::clone(&self.state),
|
state: Arc::clone(&self.state),
|
||||||
data_dir: self.data_dir.clone(),
|
data_dir: self.data_dir.clone(),
|
||||||
|
work_root: self.work_root.clone(),
|
||||||
file_states: Arc::clone(&self.file_states),
|
file_states: Arc::clone(&self.file_states),
|
||||||
is_processing: Arc::clone(&self.is_processing),
|
is_processing: Arc::clone(&self.is_processing),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue