Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ async fn on_started(device: AviDevice, peer_id: String, _listening: Vec<String>)

device
.subscribe(
&format!("speak/{}/text", device.get_id().await.to_string()),
&format!("speak/{}/text", device.get_id().await),
move |_from, _topic, data| {
let msg = String::from_utf8_lossy(&data);
println!("Speaker: {}", msg);
Expand Down
4 changes: 1 addition & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use avi_nlu_client::models::{
use log::trace;

fn box_err<E: std::fmt::Display>(e: E) -> Box<dyn std::error::Error> {
Box::new(std::io::Error::other(
e.to_string(),
))
Box::new(std::io::Error::other(e.to_string()))
}
/// A client for interacting with the Avi server API.
pub struct Api {
Expand Down
8 changes: 4 additions & 4 deletions src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@ pub enum Commands {
pub enum AviDeviceType {
/// Main controller node with full orchestration capabilities
#[value(name = "core")]
CORE,
Core,

/// Peripheral node for distributed processing
#[value(name = "node")]
NODE,
Node,
}

impl std::fmt::Display for AviDeviceType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AviDeviceType::CORE => write!(f, "CORE"),
AviDeviceType::NODE => write!(f, "NODE"),
AviDeviceType::Core => write!(f, "CORE"),
AviDeviceType::Node => write!(f, "NODE"),
}
}
}
3 changes: 2 additions & 1 deletion src/dialogue/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ impl LanguageSystem {
.map(|i| match &i.value {
serde_yaml::Value::Sequence(seq) if !seq.is_empty() => {
let mut rng = rand::rng();
seq.choose(&mut rng).cloned()
seq.choose(&mut rng)
.cloned()
.unwrap_or_else(|| i.value.clone())
}
_ => i.value.clone(),
Expand Down
27 changes: 12 additions & 15 deletions src/dialogue/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,39 +332,36 @@ mod tests {
fn test_bool_validator_basic() {
let validator = BoolValidator::new(false);

assert_eq!(validator.validate_and_parse("yes").unwrap(), true);
assert_eq!(validator.validate_and_parse("no").unwrap(), false);
assert_eq!(validator.validate_and_parse("always").unwrap(), true);
assert_eq!(validator.validate_and_parse("never").unwrap(), false);
assert!(validator.validate_and_parse("yes").unwrap());
assert!(!validator.validate_and_parse("no").unwrap());
assert!(validator.validate_and_parse("always").unwrap());
assert!(!validator.validate_and_parse("never").unwrap());
}

#[test]
fn test_bool_validator_case_insensitive() {
let validator = BoolValidator::new(false);

assert_eq!(validator.validate_and_parse("YES").unwrap(), true);
assert_eq!(validator.validate_and_parse("No").unwrap(), false);
assert_eq!(validator.validate_and_parse("ALWAYS").unwrap(), true);
assert_eq!(validator.validate_and_parse("NeVeR").unwrap(), false);
assert!(validator.validate_and_parse("YES").unwrap());
assert!(!validator.validate_and_parse("No").unwrap());
assert!(validator.validate_and_parse("ALWAYS").unwrap());
assert!(!validator.validate_and_parse("NeVeR").unwrap());
}

#[test]
fn test_bool_validator_partial_match() {
let validator = BoolValidator::new(false);

assert_eq!(validator.validate_and_parse("oh yes please").unwrap(), true);
assert_eq!(validator.validate_and_parse("no way").unwrap(), false);
assert_eq!(
validator.validate_and_parse("I will always do it").unwrap(),
true
);
assert!(validator.validate_and_parse("oh yes please").unwrap());
assert!(!validator.validate_and_parse("no way").unwrap());
assert!(validator.validate_and_parse("I will always do it").unwrap());
}

#[test]
fn test_bool_validator_hard_search() {
let validator = BoolValidator::new(true);

assert_eq!(validator.validate_and_parse("yes").unwrap(), true);
assert!(validator.validate_and_parse("yes").unwrap());
assert!(validator.validate_and_parse("oh yes please").is_err());
assert!(validator.validate_and_parse("maybe").is_err());
}
Expand Down
1 change: 1 addition & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ macro_rules! subscribe {
}};
}

#[allow(clippy::await_holding_lock)]
#[macro_export]
macro_rules! set_ctx {
($key:expr, $value:expr) => {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
AviCoreLogger::set_level(&level);
}

let is_core = matches!(dev_type, AviDeviceType::CORE);
let is_core = matches!(dev_type, AviDeviceType::Core);
let mode_str = if is_core {
"CORE CONTROLLER"
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/skills/skill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Skill {
for subscription in subscriptions {
let event = Event::get_event(subscription.to_string())?;

if matches!(event.event_type, EventType::TOPIC) {
if matches!(event.event_type, EventType::Topic) {
// Clone Arc and create new engine instance for closure
let ast_clone = Arc::clone(&ast);
let scope_clone = Arc::clone(&scope);
Expand Down
7 changes: 6 additions & 1 deletion src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ impl UserManager {

pub async fn save_to_device(&self) {
trace!("Saving user data to device context");
let _ = set_ctx!(device, "avi.user", &*self.user.read());
let user = {
let guard = self.user.read();
guard.clone()
};

let _ = set_ctx!(device, "avi.user", user);
}

fn save_to_persistent(&self) {
Expand Down
12 changes: 6 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ use std::path::PathBuf;

#[derive(Eq, PartialEq)]
pub enum EventType {
TOPIC,
EVENT,
Topic,
Event,
}

impl EventType {
pub fn from(string: &str) -> Option<EventType> {
if string.eq_ignore_ascii_case("topic") {
return Some(EventType::TOPIC);
return Some(EventType::Topic);
} else if string.eq_ignore_ascii_case("event") {
return Some(EventType::EVENT);
return Some(EventType::Event);
}
None
}
pub fn name(&self) -> String {
match self {
EventType::TOPIC => "topic".to_string(),
EventType::EVENT => "event".to_string(),
EventType::Topic => "topic".to_string(),
EventType::Event => "event".to_string(),
}
}
}
Expand Down