use crate::thinktool::{
DeepSeekValidationConfig, DeepSeekValidationEngine, DeepSeekValidationResult,
ValidationVerdict,
};
use crate::vibe::{
cross_cultural::{CulturalConfig, CulturalValidationEngine, CulturalValidationResult},
multi_model_validator::{MultiModelConfig, MultiModelValidationResult, MultiModelValidator},
statistical_testing::{StatisticalConfig, StatisticalEngine, StatisticalResult},
ValidationConfig, ValidationResult, VIBEEngine, VIBEError,
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeepSeekVIBEConfig {
pub vibe_config: ValidationConfig,
pub deepseek_config: DeepSeekValidationConfig,
pub multi_model_config: MultiModelConfig,
pub statistical_config: StatisticalConfig,
pub cultural_config: CulturalConfig,
pub enable_deepseek: bool,
pub enable_triangulation: bool,
pub enable_statistical: bool,
pub enable_cultural: bool,
}
impl Default for DeepSeekVIBEConfig {
fn default() -> Self {
Self {
vibe_config: ValidationConfig::default(),
deepseek_config: DeepSeekValidationConfig::default(),
multi_model_config: MultiModelConfig::default(),
statistical_config: StatisticalConfig::default(),
cultural_config: CulturalConfig::default(),
enable_deepseek: true,
enable_triangulation: true,
enable_statistical: true,
enable_cultural: true,
}
}
}
impl DeepSeekVIBEConfig {
pub fn enterprise() -> Self {
Self {
vibe_config: ValidationConfig::enterprise(),
deepseek_config: DeepSeekValidationConfig::enterprise(),
multi_model_config: MultiModelConfig::enterprise(),
statistical_config: StatisticalConfig::default(),
cultural_config: CulturalConfig::default(),
enable_deepseek: true,
enable_triangulation: true,
enable_statistical: true,
enable_cultural: true,
}
}
pub fn research() -> Self {
Self {
vibe_config: ValidationConfig::research(),
deepseek_config: DeepSeekValidationConfig::rigorous(),
multi_model_config: MultiModelConfig::research(),
statistical_config: StatisticalConfig::default(),
cultural_config: CulturalConfig::default(),
enable_deepseek: true,
enable_triangulation: true,
enable_statistical: true,
enable_cultural: true,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeepSeekVIBEResult {
pub vibe_result: ValidationResult,
pub deepseek_result: Option<DeepSeekValidationResult>,
pub multi_model_result: Option<MultiModelValidationResult>,
pub statistical_result: Option<StatisticalResult>,
pub cultural_result: Option<CulturalValidationResult>,
pub final_score: f32,
pub overall_confidence: f32,
pub verdict: ValidationVerdict,
}
pub struct DeepSeekVIBEEngine {
vibe_engine: VIBEEngine,
deepseek_engine: DeepSeekValidationEngine,
multi_model_validator: MultiModelValidator,
statistical_engine: StatisticalEngine,
cultural_engine: CulturalValidationEngine,
config: DeepSeekVIBEConfig,
}
impl DeepSeekVIBEEngine {
pub fn new(config: DeepSeekVIBEConfig) -> Result<Self, VIBEError> {
Ok(Self {
vibe_engine: VIBEEngine::new(),
deepseek_engine: DeepSeekValidationEngine::new()?,
multi_model_validator: MultiModelValidator::new()?,
statistical_engine: StatisticalEngine::default(),
cultural_engine: CulturalValidationEngine::new(config.cultural_config.clone())?,
config,
})
}
pub fn default() -> Result<Self, VIBEError> {
Self::new(DeepSeekVIBEConfig::default())
}
pub fn enterprise() -> Result<Self, VIBEError> {
Self::new(DeepSeekVIBEConfig::enterprise())
}
pub fn research() -> Result<Self, VIBEError> {
Self::new(DeepSeekVIBEConfig::research())
}
pub async fn validate_with_deepseek(
&self,
protocol: &str,
) -> Result<DeepSeekVIBEResult, VIBEError> {
let start_time = std::time::Instant::now();
let vibe_result = self
.vibe_engine
.validate_protocol(protocol, self.config.vibe_config.clone())
.await?;
let deepseek_result = if self.config.enable_deepseek {
Some(
self.deepseek_engine
.validate_reasoning_chain(protocol)
.await?,
)
} else {
None
};
let multi_model_result = if self.config.enable_triangulation {
Some(
self.multi_model_validator
.validate_triangulation(protocol)
.await?,
)
} else {
None
};
let statistical_result = if self.config.enable_statistical {
Some(self.perform_statistical_analysis(&vibe_result, &deepseek_result)?)
} else {
None
};
let cultural_result = if self.config.enable_cultural {
Some(
self.cultural_engine
.validate_cultural(protocol, vibe_result.clone())
.await?,
)
} else {
None
};
let (final_score, overall_confidence, verdict) =
self.aggregate_results(
&vibe_result,
&deepseek_result,
&multi_model_result,
&statistical_result,
&cultural_result,
);
let validation_time = start_time.elapsed().as_millis() as u64;
Ok(DeepSeekVIBEResult {
vibe_result: ValidationResult {
validation_time_ms: validation_time,
..vibe_result
},
deepseek_result,
multi_model_result,
statistical_result,
cultural_result,
final_score,
overall_confidence,
verdict,
})
}
pub async fn validate_with_specific_deepseek(
&self,
protocol: &str,
model_name: &str,
) -> Result<DeepSeekVIBEResult, VIBEError> {
let mut custom_config = self.config.deepseek_config.clone();
custom_config.model = model_name.to_string();
let custom_engine = DeepSeekValidationEngine::with_config(custom_config)?;
let vibe_result = self
.vibe_engine
.validate_protocol(protocol, self.config.vibe_config.clone())
.await?;
let deepseek_result = custom_engine.validate_reasoning_chain(protocol).await?;
let (final_score, overall_confidence, verdict) = self.aggregate_basic_results(
&vibe_result,
&deepseek_result,
None,
None,
None,
);
Ok(DeepSeekVIBEResult {
vibe_result,
deepseek_result: Some(deepseek_result),
multi_model_result: None,
statistical_result: None,
cultural_result: None,
final_score,
overall_confidence,
verdict,
})
}
pub async fn validate_quick(
&self,
protocol: &str,
) -> Result<DeepSeekVIBEResult, VIBEError> {
let start_time = std::time::Instant::now();
let deepseek_result = self
.deepseek_engine
.validate_reasoning_chain(protocol)
.await?;
let vibe_result = ValidationResult {
overall_score: deepseek_result.confidence * 100.0,
platform_scores: HashMap::new(),
confidence_interval: None,
status: crate::vibe::validation::ValidationStatus::Validated,
detailed_results: HashMap::new(),
validation_time_ms: start_time.elapsed().as_millis() as u64,
issues: Vec::new(),
recommendations: Vec::new(),
timestamp: chrono::Utc::now(),
protocol_id: uuid::Uuid::new_v4(),
};
let verdict = if deepseek_result.confidence > 0.8 {
ValidationVerdict::Validated
} else {
ValidationVerdict::PartiallyValidated
};
Ok(DeepSeekVIBEResult {
vibe_result,
deepseek_result: Some(deepseek_result),
multi_model_result: None,
statistical_result: None,
cultural_result: None,
final_score: deepseek_result.confidence * 100.0,
overall_confidence: deepseek_result.confidence,
verdict,
})
}
fn perform_statistical_analysis(
&self,
vibe_result: &ValidationResult,
deepseek_result: &Option<DeepSeekValidationResult>,
) -> Result<StatisticalResult, VIBEError> {
let mut validation_results = vec![vibe_result.clone()];
if let Some(ds_result) = deepseek_result {
let ds_vibe_result = ValidationResult {
overall_score: ds_result.confidence * 100.0,
platform_scores: HashMap::new(),
confidence_interval: None,
status: crate::vibe::validation::ValidationStatus::Validated,
detailed_results: HashMap::new(),
validation_time_ms: 0,
issues: Vec::new(),
recommendations: Vec::new(),
timestamp: chrono::Utc::now(),
protocol_id: uuid::Uuid::new_v4(),
};
validation_results.push(ds_vibe_result);
}
let mut statistical_engine = StatisticalEngine::new(self.config.statistical_config.clone());
statistical_engine.bootstrap_significance_test(&validation_results, 0.7)
}
fn aggregate_results(
&self,
vibe_result: &ValidationResult,
deepseek_result: &Option<DeepSeekValidationResult>,
multi_model_result: &Option<MultiModelValidationResult>,
statistical_result: &Option<StatisticalResult>,
cultural_result: &Option<CulturalValidationResult>,
) -> (f32, f32, ValidationVerdict) {
let mut total_score = vibe_result.overall_score;
let mut total_weight = 1.0;
if let Some(ds_result) = deepseek_result {
total_score += ds_result.confidence * 100.0 * 0.6; total_weight += 0.6;
}
if let Some(mm_result) = multi_model_result {
total_score += mm_result.overall_score * 0.4; total_weight += 0.4;
}
if let Some(cultural_result) = cultural_result {
total_score += cultural_result.cultural_score * 0.3; total_weight += 0.3;
}
let final_score = total_score / total_weight;
let mut confidence = vibe_result.overall_score / 100.0;
if let Some(ds_result) = deepseek_result {
confidence = (confidence + ds_result.confidence) / 2.0;
}
if let Some(mm_result) = multi_model_result {
confidence = (confidence + mm_result.triangulation_score) / 2.0;
}
let verdict = if final_score > 90.0 {
ValidationVerdict::StronglyValidated
} else if final_score > 75.0 {
ValidationVerdict::Validated
} else if final_score > 60.0 {
ValidationVerdict::PartiallyValidated
} else {
ValidationVerdict::Rejected
};
(final_score, confidence, verdict)
}
fn aggregate_basic_results(
&self,
vibe_result: &ValidationResult,
deepseek_result: &DeepSeekValidationResult,
multi_model_result: &Option<MultiModelValidationResult>,
statistical_result: &Option<StatisticalResult>,
cultural_result: &Option<CulturalValidationResult>,
) -> (f32, f32, ValidationVerdict) {
self.aggregate_results(
vibe_result,
&Some(deepseek_result.clone()),
multi_model_result,
statistical_result,
cultural_result,
)
}
pub fn config(&self) -> &DeepSeekVIBEConfig {
&self.config
}
pub fn update_config(&mut self, config: DeepSeekVIBEConfig) {
self.config = config;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_deepseek_vibe_engine_creation() {
let engine = DeepSeekVIBEEngine::default().unwrap();
assert!(engine.config.enable_deepseek);
assert!(engine.config.enable_triangulation);
}
#[tokio::test]
async fn test_quick_validation() {
let engine = DeepSeekVIBEEngine::default().unwrap();
let result = engine
.validate_quick("Sample protocol for quick validation")
.await
.unwrap();
assert!(result.final_score > 0.0);
assert!(result.overall_confidence > 0.0);
}
#[tokio::test]
async fn test_full_validation() {
let engine = DeepSeekVIBEEngine::enterprise().unwrap();
let result = engine
.validate_with_deepseek("Comprehensive protocol validation test")
.await
.unwrap();
assert!(result.final_score > 0.0);
assert!(result.deepseek_result.is_some());
}
}