72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
import { NextResponse } from 'next/server'
|
||
import { llmClient } from '@/app/api/llm-client'
|
||
|
||
const SYSTEM_PROMPT = `你是一个专门分析互联网大厂老板PUA话术的AI裁判。
|
||
用户输入一段老板/领导对员工说的"打鸡血"或"PUA"的话,你需要分析这段话并给出评分和游戏效果。
|
||
|
||
评分标准(1-10分):
|
||
1-3分:废话/没营养("大家加油"之类)→ 轻微效果
|
||
4-6分:标准大厂黑话("对齐""闭环""狼性")→ 中等效果
|
||
7-8分:强力PUA("996是福报""不拼搏对不起父母")→ 强力效果
|
||
9-10分:终极毒鸡汤(极限施压/情感绑架)→ 全场爆发
|
||
|
||
只返回如下JSON,不要其他内容:
|
||
{
|
||
"score": 数字(1-10),
|
||
"title": "效果名称(2-6个汉字,有创意)",
|
||
"desc": "对话语的一句话点评(15字以内,带点讽刺)",
|
||
"effect": "attack_boost" | "speed_boost" | "money_rain" | "rage_mode" | "backfire"
|
||
}
|
||
|
||
effect说明:
|
||
- attack_boost: 攻击力提升(score 4-6)
|
||
- speed_boost: 攻击速度提升(score 7-8)
|
||
- money_rain: HC暴增(score 5-7,话语中强调利益)
|
||
- rage_mode: 全场狂暴(score 9-10)
|
||
- backfire: 话太废了反而debuff(score 1-2)`
|
||
|
||
export async function POST(req: Request) {
|
||
try {
|
||
const { text } = await req.json()
|
||
if (!text || typeof text !== 'string' || text.trim().length < 2) {
|
||
return NextResponse.json({ error: '输入内容太短了' }, { status: 400 })
|
||
}
|
||
|
||
const resp = await llmClient.chat({
|
||
model: 'gpt-4o-mini',
|
||
messages: [
|
||
{ role: 'system', content: SYSTEM_PROMPT },
|
||
{ role: 'user', content: text.slice(0, 200) },
|
||
],
|
||
maxTokens: 150,
|
||
temperature: 0.7,
|
||
})
|
||
|
||
const raw = resp.choices?.[0]?.message?.content ?? ''
|
||
|
||
// 提取 JSON(防止 LLM 多输出文字)
|
||
const match = raw.match(/\{[\s\S]*\}/)
|
||
if (!match) throw new Error('LLM 返回格式异常')
|
||
|
||
const result = JSON.parse(match[0])
|
||
const score = Math.max(1, Math.min(10, Number(result.score) || 5))
|
||
|
||
return NextResponse.json({
|
||
score,
|
||
title: result.title || '打鸡血',
|
||
desc: result.desc || '还行吧',
|
||
effect: result.effect || 'attack_boost',
|
||
})
|
||
} catch (e) {
|
||
console.error('[pua-score]', e)
|
||
// 降级:随机给个分数
|
||
const score = Math.floor(Math.random() * 7) + 3
|
||
return NextResponse.json({
|
||
score,
|
||
title: '随机鸡血',
|
||
desc: 'AI开小差了,随机发力',
|
||
effect: 'attack_boost',
|
||
})
|
||
}
|
||
}
|