livrare lot 2
This commit is contained in:
commit
8ecc78e729
763 changed files with 164593 additions and 0 deletions
|
|
@ -0,0 +1,224 @@
|
|||
/**
|
||||
* TECHNIQUES V3 PILOT - Test Script
|
||||
*
|
||||
* Usage: npx ts-node scripts/test-techniques-v3.ts
|
||||
*/
|
||||
|
||||
import { createRedisConnection } from '../src/shared/redis/connection';
|
||||
import { TechniquesV3Executor, LLMClient, ModelConfig } from '../src/components/techniques/executor';
|
||||
|
||||
// ============================================================================
|
||||
// MOCK LLM CLIENT (for testing without real API calls)
|
||||
// ============================================================================
|
||||
|
||||
class MockLLMClient implements LLMClient {
|
||||
async call(prompt: string, systemPrompt: string, config: ModelConfig): Promise<string> {
|
||||
console.log(`\n📡 LLM Call to: ${config.model_key}`);
|
||||
console.log(` Prompt length: ${prompt.length} chars`);
|
||||
|
||||
// Simulate screening response
|
||||
if (prompt.includes('AVAILABLE DIMENSIONS')) {
|
||||
return JSON.stringify({
|
||||
detected_dimensions: ['D1', 'D4'],
|
||||
confidence_per_dimension: {
|
||||
D1: 85,
|
||||
D4: 72
|
||||
},
|
||||
quick_reasoning: 'Text contains fear appeal language and out-of-context claims'
|
||||
});
|
||||
}
|
||||
|
||||
// Simulate deep analysis response
|
||||
if (prompt.includes('TECHNIQUES TO DETECT')) {
|
||||
const dimension = prompt.match(/\(D\d\)/)?.[0]?.replace(/[()]/g, '') || 'D1';
|
||||
|
||||
if (dimension === 'D1') {
|
||||
return JSON.stringify({
|
||||
dimension: 'D1',
|
||||
detected_techniques: [
|
||||
{
|
||||
technique_id: 5,
|
||||
confidence: 92,
|
||||
intensity: 3,
|
||||
evidence: 'This is a THREAT to our survival!'
|
||||
},
|
||||
{
|
||||
technique_id: 6,
|
||||
confidence: 78,
|
||||
intensity: 2,
|
||||
evidence: 'We must ACT NOW before it is too late!'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
if (dimension === 'D4') {
|
||||
return JSON.stringify({
|
||||
dimension: 'D4',
|
||||
detected_techniques: [
|
||||
{
|
||||
technique_id: 77,
|
||||
confidence: 65,
|
||||
intensity: 2,
|
||||
evidence: 'The image shows clear manipulation artifacts'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// TEST DATA
|
||||
// ============================================================================
|
||||
|
||||
const TEST_TEXT = `
|
||||
URGENT: This is a THREAT to our survival! The government is hiding the truth from you.
|
||||
|
||||
We must ACT NOW before it is too late! They don't want you to know about this conspiracy.
|
||||
|
||||
The image shows clear manipulation artifacts around the edges. Expert sources (who wish to remain anonymous)
|
||||
confirm that this vaccine is dangerous.
|
||||
|
||||
Share this with everyone you know before they delete it! This is being censored on all platforms.
|
||||
`;
|
||||
|
||||
// ============================================================================
|
||||
// MAIN TEST
|
||||
// ============================================================================
|
||||
|
||||
async function runTest() {
|
||||
console.log('='.repeat(70));
|
||||
console.log('TECHNIQUES V3 PILOT - TEST');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
const redis = createRedisConnection({ label: 'test-techniques-v3' });
|
||||
|
||||
try {
|
||||
// Check if pilot data is loaded
|
||||
const manifest = await redis.get('didi:config:techniques:v3:stage_assignments');
|
||||
if (!manifest) {
|
||||
console.log('\n⚠️ Config data not found in Redis!');
|
||||
console.log(' Run: curl -X POST http://localhost:3005/api/sync-redis');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('\n✅ Config data found in Redis');
|
||||
console.log(` Manifest: ${manifest}`);
|
||||
|
||||
// Check for framework techniques (needed for deep analysis)
|
||||
const frameworkTechniques = await redis.get('didi:framework:techniques');
|
||||
if (!frameworkTechniques) {
|
||||
console.log('\n⚠️ Framework techniques not found!');
|
||||
console.log(' Using mock technique hierarchy for test...');
|
||||
|
||||
// Create mock hierarchy
|
||||
const mockHierarchy = {
|
||||
dimensions: [
|
||||
{
|
||||
dimension_id: 1,
|
||||
dimension_code: 'D1',
|
||||
dimension_name: 'Emotional Manipulation',
|
||||
subdimensions: [
|
||||
{
|
||||
subdimension_id: 1,
|
||||
subdimension_name: 'Fear Appeals',
|
||||
techniques: [
|
||||
{ technique_id: 5, technique_name: 'Fear Appeal', severity: 8, confidence: 5, indicators: [] },
|
||||
{ technique_id: 6, technique_name: 'Urgency Appeal', severity: 7, confidence: 5, indicators: [] }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
dimension_id: 4,
|
||||
dimension_code: 'D4',
|
||||
dimension_name: 'Content Manipulation',
|
||||
subdimensions: [
|
||||
{
|
||||
subdimension_id: 10,
|
||||
subdimension_name: 'Media Manipulation',
|
||||
techniques: [
|
||||
{ technique_id: 77, technique_name: 'Deepfake', severity: 9, confidence: 5, indicators: [] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
await redis.set('didi:framework:techniques', JSON.stringify(mockHierarchy));
|
||||
console.log(' Mock hierarchy created');
|
||||
}
|
||||
|
||||
// Create executor with mock LLM
|
||||
const mockLLM = new MockLLMClient();
|
||||
const executor = new TechniquesV3Executor(redis, mockLLM);
|
||||
|
||||
// Run test
|
||||
console.log('\n' + '-'.repeat(70));
|
||||
console.log('RUNNING ANALYSIS...');
|
||||
console.log('-'.repeat(70));
|
||||
console.log(`\nInput text (${TEST_TEXT.length} chars):`);
|
||||
console.log(TEST_TEXT.substring(0, 200) + '...');
|
||||
|
||||
const sessionId = `test-${Date.now()}`;
|
||||
const result = await executor.execute(TEST_TEXT, sessionId);
|
||||
|
||||
// Display results
|
||||
console.log('\n' + '='.repeat(70));
|
||||
console.log('RESULTS');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
console.log('\n📊 MANIPULATION SCORE:', (result.manipulation_score * 100).toFixed(1) + '%');
|
||||
console.log('📈 DIMENSIONS AFFECTED:', result.dimensions_affected.join(', '));
|
||||
console.log('📝 TECHNIQUES DETECTED:', result.techniques.length);
|
||||
|
||||
console.log('\n🔍 DETECTED TECHNIQUES:');
|
||||
for (const t of result.techniques) {
|
||||
console.log(` [${t.id}] ${t.name} (${t.dimension})`);
|
||||
console.log(` Confidence: ${t.confidence}%, Intensity: ${t.intensity}, Severity: ${t.severity}`);
|
||||
console.log(` Evidence: "${t.evidence.substring(0, 50)}..."`);
|
||||
}
|
||||
|
||||
console.log('\n🔗 COUPLING CONTEXT:');
|
||||
console.log(' For Claims:');
|
||||
console.log(` - Emotional manipulation: ${result.coupling_context.for_claims.has_emotional_manipulation}`);
|
||||
console.log(` - Logical fallacies: ${result.coupling_context.for_claims.has_logical_fallacies}`);
|
||||
console.log(` - Manipulation level: ${result.coupling_context.for_claims.manipulation_level}`);
|
||||
console.log(` - Warning flags: ${result.coupling_context.for_claims.warning_flags.join(', ') || 'none'}`);
|
||||
|
||||
console.log(' For Verdict:');
|
||||
console.log(` - Risk score: ${result.coupling_context.for_verdict.risk_score.toFixed(3)}`);
|
||||
console.log(` - Dimension count: ${result.coupling_context.for_verdict.dimension_count}`);
|
||||
console.log(` - Severe techniques: ${result.coupling_context.for_verdict.severe_technique_count}`);
|
||||
console.log(` - Needs override check: ${result.coupling_context.for_verdict.needs_override_check}`);
|
||||
|
||||
console.log('\n⏱️ TIMING:');
|
||||
console.log(` Screening: ${result.metadata.screening_duration_ms}ms (${result.metadata.llm_screening})`);
|
||||
console.log(` Deep analysis: ${result.metadata.deep_analysis_duration_ms}ms (${result.metadata.llm_deep})`);
|
||||
console.log(` Total: ${result.metadata.total_duration_ms}ms`);
|
||||
|
||||
// Verify Redis storage
|
||||
console.log('\n📦 REDIS STORAGE:');
|
||||
const keys = await redis.keys(`agent:result:${sessionId}:*`);
|
||||
for (const key of keys.sort()) {
|
||||
console.log(` - ${key}`);
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(70));
|
||||
console.log('TEST COMPLETE ✅');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Test failed:', error);
|
||||
} finally {
|
||||
await redis.quit();
|
||||
}
|
||||
}
|
||||
|
||||
// Run test
|
||||
runTest().catch(console.error);
|
||||
Loading…
Add table
Add a link
Reference in a new issue