feat(ai): make reply suggestions natural and context-aware
This commit is contained in:
@@ -2,6 +2,12 @@ import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { countBy, dateKey, percent, telegramAttachment } from '../src/business.js'
|
||||
import { decryptEmailPassword, encryptEmailPassword } from '../src/email.js'
|
||||
import {
|
||||
HUMAN_REPLY_SYSTEM_PROMPT,
|
||||
buildHumanReplyUserPrompt,
|
||||
replySuggestionIssues,
|
||||
replyToneInstruction,
|
||||
} from '../src/reply-suggestions.js'
|
||||
|
||||
test('Telegram 图片、文档、语音和贴纸映射为可下载文件', () => {
|
||||
assert.deepEqual(
|
||||
@@ -54,3 +60,41 @@ test('Email 渠道凭据使用认证加密且可正确解密', () => {
|
||||
tampered[2] = `${tampered[2][0] === 'A' ? 'B' : 'A'}${tampered[2].slice(1)}`
|
||||
assert.throws(() => decryptEmailPassword(tampered.join(':')))
|
||||
})
|
||||
|
||||
test('回复建议提示词突出最新消息、避免重复并遵循企业语气', () => {
|
||||
const prompt = buildHumanReplyUserPrompt({
|
||||
targetInstruction: '使用西班牙语',
|
||||
tone: 'friendly',
|
||||
latestCustomerMessage: '¿Cuándo pueden enviarlo?',
|
||||
latestAgentMessage: 'I will check it.',
|
||||
conversation: '客户: ¿Cuándo pueden enviarlo?',
|
||||
conversationMemory: '客户关注交期',
|
||||
knowledgeContext: [],
|
||||
})
|
||||
assert.match(HUMAN_REPLY_SYSTEM_PROMPT, /不是写客服范文/)
|
||||
assert.match(HUMAN_REPLY_SYSTEM_PROMPT, /不要重新问候/)
|
||||
assert.match(prompt, /¿Cuándo pueden enviarlo\?/)
|
||||
assert.match(prompt, /坐席上一条回复(避免重复)/)
|
||||
assert.match(prompt, /长期合作伙伴/)
|
||||
assert.match(replyToneInstruction('concise'), /简洁直接/)
|
||||
})
|
||||
|
||||
test('回复建议质量检查拦截模板话术和同质草稿', () => {
|
||||
const valid = [
|
||||
{ style: 'stable', content: 'I can confirm the dispatch date with our warehouse and update you once I have it.' },
|
||||
{ style: 'active', content: "Let me check the warehouse schedule and come back to you with the exact date." },
|
||||
{ style: 'brief', content: "I'll verify the dispatch date and get back to you." },
|
||||
]
|
||||
assert.deepEqual(replySuggestionIssues(valid), [])
|
||||
const invalid = valid.map((item) => ({ ...item }))
|
||||
invalid[0].content = 'Dear customer, please rest assured that we value your feedback.'
|
||||
invalid[2] = { style: 'active', content: invalid[1].content }
|
||||
const issues = replySuggestionIssues(invalid)
|
||||
assert.ok(issues.some((item) => item.includes('模板化')))
|
||||
assert.ok(issues.some((item) => item.includes('缺少 brief')))
|
||||
assert.ok(issues.some((item) => item.includes('过于相似')))
|
||||
assert.ok(replySuggestionIssues([
|
||||
...valid.slice(0, 2),
|
||||
{ style: 'brief', content: "I'll confirm it today." },
|
||||
]).some((item) => item.includes('时间承诺')))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user