first pass of merging in warp (doesn't build)

This commit is contained in:
Ryan Ward
2026-07-01 16:08:58 -05:00
parent 2f64909469
commit 4770ac06b5
3662 changed files with 414574 additions and 89772 deletions
+30 -40
View File
@@ -2,9 +2,9 @@ use std::{fs, process};
use clap::{Parser, Subcommand};
use futures::executor::block_on;
use input_classifier::test_utils::CompletionContext;
use input_classifier::{
ClassificationResult, Context, HeuristicClassifier, InputClassifier, InputType,
test_utils::CompletionContext,
};
/// Convert HSL to RGB values (0-255 range)
@@ -66,13 +66,24 @@ fn get_binary_confidence_color(is_correct: bool, is_low_confidence: bool) -> Str
"\x1b[31m".to_string() // Red for incorrect
}
}
use galaxy_completer::{ParsedTokensSnapshot, util::parse_current_commands_and_tokens};
#[cfg(feature = "fasttext")]
use input_classifier::FasttextClassifier;
#[cfg(feature = "onnx")]
use input_classifier::{OnnxClassifier, OnnxModel};
use warp_completer::ParsedTokensSnapshot;
use warp_completer::util::parse_current_commands_and_tokens;
#[cfg(feature = "onnx")]
fn default_onnx_model() -> Option<OnnxModel> {
cfg_if::cfg_if! {
if #[cfg(feature = "nld_classifier_v1")] {
Some(OnnxModel::BertTinyV1)
} else if #[cfg(feature = "nld_classifier_v2")] {
Some(OnnxModel::BertTinyV2)
} else if #[cfg(feature = "nld_classifier_v3")] {
Some(OnnxModel::BertTinyV3)
} else {
None
}
}
}
#[derive(Parser)]
struct InputSource {
@@ -98,11 +109,6 @@ struct Args {
#[arg(long)]
heuristic: bool,
/// Use fasttext classifier
#[cfg(feature = "fasttext")]
#[arg(long)]
fasttext: bool,
/// Use ONNX classifier
#[cfg(feature = "onnx")]
#[arg(long)]
@@ -135,17 +141,6 @@ fn create_classifiers(args: &Args) -> Vec<(&'static str, Box<dyn InputClassifier
let mut classifiers: Vec<(&'static str, Box<dyn InputClassifier>)> = Vec::new();
// Default to all available classifiers if none specified
let fasttext_specified = {
#[cfg(feature = "fasttext")]
{
args.fasttext
}
#[cfg(not(feature = "fasttext"))]
{
false
}
};
let onnx_specified = {
#[cfg(feature = "onnx")]
{
@@ -157,27 +152,19 @@ fn create_classifiers(args: &Args) -> Vec<(&'static str, Box<dyn InputClassifier
}
};
let use_all = !args.heuristic && !fasttext_specified && !onnx_specified;
let use_all = !args.heuristic && !onnx_specified;
if args.heuristic || use_all {
classifiers.push(("heuristic", Box::new(HeuristicClassifier)));
}
#[cfg(feature = "fasttext")]
if args.fasttext || use_all {
match FasttextClassifier::new() {
Ok(classifier) => {
classifiers.push(("fasttext", Box::new(classifier)));
}
Err(e) => {
eprintln!("Warning: Failed to initialize FastText classifier: {e}");
}
}
}
#[cfg(feature = "onnx")]
if args.onnx || use_all {
match OnnxClassifier::new(OnnxModel::BertTiny) {
let Some(model) = default_onnx_model() else {
eprintln!("Warning: No ONNX model feature is enabled for the ONNX classifier");
return classifiers;
};
match OnnxClassifier::new(model) {
Ok(classifier) => {
classifiers.push(("onnx", Box::new(classifier)));
}
@@ -247,10 +234,13 @@ async fn handle_classify(
}
Err(_) => {
// Fallback to detect_input_type if classify_input fails
let result = classifier
let classification = classifier
.detect_input_type(parsed_input.clone(), &context)
.await;
println!(" {name}: {result} (probabilities unavailable)");
println!(
" {}: {} (probabilities unavailable)",
name, classification.input_type
);
}
}
}
@@ -302,10 +292,10 @@ async fn handle_verify(
}
Err(_) => {
// Fallback to detect_input_type if classify_input fails
let result = classifier
let classification = classifier
.detect_input_type(parsed_input.clone(), &context)
.await;
let is_correct = result == expected;
let is_correct = classification.input_type == expected;
if is_correct {
correct_count += 1;
}