SOURCE

console 命令行工具 X clear

                    
>
console
const chatBox = document.getElementById('chatBox')
const input = document.getElementById('input')
const sendBtn = document.getElementById('send')

// 这里填入你的 DeepSeek API Key
const API_KEY = "sk-0133a2c4e4e248a0b6d7883bb65b7e45"
const API_URL = "https://api.deepseek.com/v1/chat/completions"

// 固定系统提示词:就是我们厨师离职评估智能体的规则
const systemPrompt = `
你是厨师离职风险评估顾问。
你会根据用户输入的厨师个人信息,从下面维度评估:年龄、籍贯、家庭情况、薪资水平、夜班频次、补贴发放是否准时、排班稳定性、岗位技能、入职时长、是否有带徒职责、休息保障。
输出内容固定分为三块:
1. 离职风险等级:高/中/低,一句话说明原因
2. 核心风险点
3. 针对性培训&留人建议
回答简洁清晰,适合HR查看,不要多余废话。
`

function addMsg(text, isUser){
  const div = document.createElement('div')
  div.className = "msg " + (isUser ? "user" : "bot")
  div.innerText = text
  chatBox.appendChild(div)
  chatBox.scrollTop = chatBox.scrollHeight
}

sendBtn.onclick = async ()=>{
  const text = input.value.trim()
  if(!text) return
  addMsg(text, true)
  input.value = ""
  addMsg("正在分析厨师信息,评估离职风险……", false)

  try {
    const res = await fetch(API_URL, {
      method:"POST",
      headers:{
        "Content-Type":"application/json",
        "Authorization":`Bearer ${API_KEY}`
      },
      body:JSON.stringify({
        model: "deepseek-v4",
        messages: [
          {role:"system", content: systemPrompt},
          {role:"user", content: text}
        ],
        temperature: 0.3
      })
    })
    const data = await res.json()
    const reply = data.choices[0].message.content
    // 删掉刚才那句“正在分析”
    chatBox.removeChild(chatBox.lastChild)
    addMsg(reply, false)
  } catch(err) {
    chatBox.removeChild(chatBox.lastChild)
    addMsg("调用失败!检查API密钥是否正确、余额是否充足", false)
    console.log(err)
  }
}
<div class="box">
  <div class="title">离职风险智能评估</div>
  <div class="content" id="chatBox">
    <div class="msg bot">你好,请输入厨师信息,我帮你评估离职风险</div>
  </div>
  <div class="input-area">
    <input id="input" placeholder="在这里输入信息">
    <button id="send">发送</button>
  </div>
</div>
*{box-sizing:border-box;margin:0;padding:0;font-family:system-ui}
.box{width:420px;margin:30px auto;border:1px solid #ddd;border-radius:12px;overflow:hidden}
.title{background:#4080ff;color:white;padding:14px;text-align:center;font-size:18px}
.content{height:400px;padding:12px;overflow-y:auto;background:#f8f9fa}
.msg{margin:8px 0;padding:10px;border-radius:8px;max-width:85%}
.bot{background:#e8edf8;margin-right:auto}
.user{background:#4080ff;color:white;margin-left:auto;color:#fff}
.input-area{display:flex;border-top:1px solid #ddd}
#input{flex:1;padding:12px;border:none;outline:none;font-size:15px}
#send{padding:12px 18px;border:none;background:#4080ff;color:white;cursor:pointer}