71 行
2.8 KiB
TypeScript
71 行
2.8 KiB
TypeScript
import {
|
|
AiSentimentIntentAnalyzer,
|
|
analyzeConversationIntent,
|
|
analyzeConversationSentiment,
|
|
ConversationAnalysisResult,
|
|
} from '../../../src/modules/ai/service/sentiment-intent';
|
|
|
|
describe('Point 61 (P1): AI 对话客商意图与情绪极性分析引擎', () => {
|
|
let analyzer: AiSentimentIntentAnalyzer;
|
|
|
|
beforeEach(() => {
|
|
analyzer = new AiSentimentIntentAnalyzer();
|
|
});
|
|
|
|
describe('1. analyzeConversationIntent (商务意图识别)', () => {
|
|
it('包含价格、报价、起订量或购买关键词应识别为 PURCHASE_INTENT', () => {
|
|
const msgs = [
|
|
'Hello, what is the MOQ for 500 NFC metal cards?',
|
|
'Can you provide a wholesale quotation and delivery time to Dubai?',
|
|
];
|
|
const intent = analyzeConversationIntent(msgs);
|
|
expect(intent.primaryIntent).toBe('PURCHASE_INTENT');
|
|
expect(intent.confidence).toBeGreaterThanOrEqual(0.8);
|
|
});
|
|
|
|
it('包含代理、渠道分销或合作伙伴意向应识别为 PARTNER_INQUIRY', () => {
|
|
const msgs = [
|
|
'We are a leading distributor in Saudi Arabia.',
|
|
'Interested in becoming your regional partner and reseller.',
|
|
];
|
|
const intent = analyzeConversationIntent(msgs);
|
|
expect(intent.primaryIntent).toBe('PARTNER_INQUIRY');
|
|
});
|
|
|
|
it('普通闲聊应识别为 GENERAL_CHAT', () => {
|
|
const msgs = ['Hi there', 'Just browsing your digital card showcase'];
|
|
const intent = analyzeConversationIntent(msgs);
|
|
expect(intent.primaryIntent).toBe('GENERAL_CHAT');
|
|
});
|
|
});
|
|
|
|
describe('2. analyzeConversationSentiment (客商商业情绪极性分析)', () => {
|
|
it('热情积极、赞美或明确赞同应识别为 positive', () => {
|
|
const msgs = ['Great product! Exactly what our international sales team needs.'];
|
|
const sentiment = analyzeConversationSentiment(msgs);
|
|
expect(sentiment.polarity).toBe('positive');
|
|
expect(sentiment.score).toBeGreaterThan(0.5);
|
|
});
|
|
|
|
it('抱怨、价格过贵或批评应识别为 negative', () => {
|
|
const msgs = ['Too expensive, not happy with the slow response.', 'Bad experience.'];
|
|
const sentiment = analyzeConversationSentiment(msgs);
|
|
expect(sentiment.polarity).toBe('negative');
|
|
expect(sentiment.score).toBeLessThan(0);
|
|
});
|
|
});
|
|
|
|
describe('3. AiSentimentIntentAnalyzer 综合画像报告与 CRM 加分', () => {
|
|
it('高价值积极意向对话应输出线索加权建议 (+25~35分)', async () => {
|
|
const result = await analyzer.evaluateConversationSession([
|
|
'We want to purchase 1,000 smart cards for our Dubai exhibition.',
|
|
'Looking forward to signing the contract next week.',
|
|
]);
|
|
|
|
expect(result.intent.primaryIntent).toBe('PURCHASE_INTENT');
|
|
expect(result.sentiment.polarity).toBe('positive');
|
|
expect(result.recommendedLeadScoreBoost).toBeGreaterThanOrEqual(25);
|
|
});
|
|
});
|
|
});
|