Files
test1/app/api/pua-score/route.ts

72 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: 话太废了反而debuffscore 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',
})
}
}