| | |
| | | import cc.mrbird.febs.ai.enumerates.AiPromptEnum; |
| | | import cc.mrbird.febs.ai.mapper.AiMemberMapper; |
| | | import cc.mrbird.febs.ai.req.talk.AiTalkAnswerStream; |
| | | import cc.mrbird.febs.ai.res.memberTalk.ApiMemberTalkStreamVo; |
| | | import cc.mrbird.febs.ai.res.memberTalk.ApiMemberTalkStreamVoOld; |
| | | import cc.mrbird.febs.ai.service.AiService; |
| | | import cc.mrbird.febs.ai.strategy.enumerates.LlmStrategyContextEnum; |
| | | import cc.mrbird.febs.ai.strategy.enumerates.LlmStrategyEnum; |
| | | import cc.mrbird.febs.ai.strategy.LlmStrategyFactory; |
| | | import cc.mrbird.febs.ai.strategy.param.LlmStrategyDto; |
| | | import cc.mrbird.febs.ai.utils.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.mall.entity.MallMember; |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.asymmetric.KeyType; |
| | | import cn.hutool.crypto.asymmetric.RSA; |
| | | import com.alibaba.dashscope.app.Application; |
| | | import com.alibaba.dashscope.app.ApplicationParam; |
| | | import com.alibaba.dashscope.app.ApplicationResult; |
| | | import com.alibaba.dashscope.app.FlowStreamMode; |
| | | import com.alibaba.dashscope.utils.JsonUtils; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import io.reactivex.Flowable; |
| | |
| | | |
| | | @ApiOperation("提问AI(流式)V2") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "流式响应", response = ApiMemberTalkStreamVo.class), |
| | | @ApiResponse(code = 200, message = "流式响应", response = ApiMemberTalkStreamVoOld.class), |
| | | }) |
| | | @PostMapping("/answer-streamV2") |
| | | public Flux<FebsResponse> answerStreamV2(@RequestBody @Validated AiTalkAnswerStream dto) { |
| | |
| | | |
| | | @ApiOperation("提问AI(流式)V3") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "流式响应", response = ApiMemberTalkStreamVo.class), |
| | | @ApiResponse(code = 200, message = "流式响应", response = ApiMemberTalkStreamVoOld.class), |
| | | }) |
| | | @PostMapping("/answerStreamV3") |
| | | public Flux<FebsResponse> answerStreamV3(@RequestBody @Validated AiTalkAnswerStream dto) { |
| | | if (StrUtil.isEmpty(dto.getQuestion())){ |
| | | return Flux.just(new FebsResponse().fail().message("请输入问题")); |
| | | |
| | | return llmInvokeStreamingWithThink(); |
| | | } |
| | | |
| | | private Flux<FebsResponse> llmInvokeStreamingWithThink(){ |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | | ApplicationParam param = ApplicationParam.builder() |
| | | // 若没有配置环境变量,可用百炼API Key将下行替换为:.apiKey("sk-xxx")。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。 |
| | | .apiKey("sk-babdcf8799144134915cee2683794b2f") |
| | | .appId("f94539c7e54d44e2a7cac5e85f2ae61d") //替换为实际的应用 ID |
| | | .flowStreamMode(FlowStreamMode.MESSAGE_FORMAT) |
| | | .prompt("你是谁?") |
| | | .enableThinking( true) |
| | | .hasThoughts( true) |
| | | .build(); |
| | | |
| | | Application application = new Application(); |
| | | Flowable<ApplicationResult> result; |
| | | try { |
| | | result = application.streamCall(param); |
| | | } catch (NoApiKeyException | InputRequiredException e) { |
| | | throw new FebsException(StrUtil.format("百炼工作流输出失败:{}",e.getMessage())); |
| | | } |
| | | |
| | | String prompt = "你是一位拥有超过10年人力资源与薪资谈判经验的资深职业顾问,专长于为不同行业、不同层级的专业人士提供定制化的薪资谈判策略。你的主要目标是通过专业的分析和实战指导,帮助用户在薪资谈判过程中最大化地实现个人价值,同时保持与雇主的良好关系。你熟悉各行业的薪资结构、市场行情数据解读方法以及谈判心理学技巧,能够给出既有理论依据又具备实际操作性的建议。\n" + |
| | | "\n" + |
| | | "### 核心功能要求\n" + |
| | | "\n" + |
| | | "#### 1. 答案亮点分析\n" + |
| | | "- 对用户提供的薪资谈判回答进行逐句解析。\n" + |
| | | "- 识别并突出其中的三大核心优势(例如:具体的数据支持、行业标准对比、个人价值创造等)。\n" + |
| | | "\n" + |
| | | "#### 2. 定制化参考建议\n" + |
| | | "- **市场行情定位**:基于最新的行业薪资报告,评估用户的当前薪资水平及其合理性(如:“根据《XX行业2024薪资报告》,您的目标薪资位于75分位,具有较高的合理性。”)\n" + |
| | | "- **谈判话术框架**:提供一个完整的谈判对话模板,涵盖开场白、自我价值陈述、处理对方异议及最终确认四个关键阶段。\n" + |
| | | "- **非薪资福利谈判策略**:探讨除了基本薪资外,还可以争取到的其他福利选项(比如股权激励、灵活工作安排或专业发展基金等)。\n" + |
| | | "- **关键提升点建议**:指出用户现有方案中可以改进的地方,并提出具体的改进建议(例如:“如果能加入更多关于您对公司贡献的具体例子,将显著增强说服力。”)\n" + |
| | | "\n" + |
| | | "#### 3. 情境化示例答案\n" + |
| | | "- 针对用户特定的谈判情境(包括但不限于当前薪资状况、期望薪资范围及所处面试阶段),生成三种风格各异但均符合实际情况的完整对话案例:\n" + |
| | | " - **稳健型**:注重风险管理和长期合作关系的建立。\n" + |
| | | " - **进取型**:强调个人的独特价值和市场需求。\n" + |
| | | " - **灵活型**:提供多种备选方案以适应不同的谈判情况。\n" + |
| | | "\n" + |
| | | "#### 4. 权威参考依据\n" + |
| | | "- 引用最新发布的行业薪资研究报告(需明确报告名称及发布机构)。\n" + |
| | | "- 分享谈判心理学中的重要概念及其应用(如锚定效应、互惠原则等)。\n" + |
| | | "- 推荐三本关于谈判技巧的经典书籍,并简要总结每本书的核心观点。\n" + |
| | | "- 列出薪资谈判过程中需要注意的五个法律风险点(例如最低工资标准、加班费计算规则等)。\n" + |
| | | "\n" + |
| | | "### 交互流程\n" + |
| | | "- 在收到用户提交的初步薪资谈判提案后,按照上述要求之一输出相应的内容:“答案亮点分析”、“定制化参考建议”、“情境化示例答案”或“权威参考依据”。\n" + |
| | | "\n" + |
| | | "### 输出格式规范\n" + |
| | | "- 使用Markdown格式编写文档。\n" + |
| | | "- 所有引用的数据必须加粗显示,并注明其来源。\n" + |
| | | "- 提供的所有策略建议都应标明适用的具体场景(例如【适用于金融行业管理岗位】)。\n" + |
| | | "\n" + |
| | | "### 语气要求\n" + |
| | | "- 保持专业性的同时不失温暖,使用鼓励性的语言来增强用户的信心。\n" + |
| | | "- 尽量避免过多使用专业术语,而是采用更加通俗易懂的方式表达(如“你可以这样尝试...”)。\n" + |
| | | "- 当需要指出不足之处时,采取积极建设性的态度(例如:“如果能在提案中增加一些关于团队合作经历的例子,将会使你的论点更加有力。”)"; |
| | | List<LlmStrategyDto> llmStrategyDtoList = new ArrayList<>(); |
| | | LlmStrategyDto llmStrategyDto = this.buildLlmStrategyDtoList(prompt, 1); |
| | | llmStrategyDtoList.add(llmStrategyDto); |
| | | llmStrategyDto = this.buildLlmStrategyDtoList(dto.getQuestion(), 3); |
| | | llmStrategyDtoList.add(llmStrategyDto); |
| | | llmStrategyDto = this.buildLlmStrategyDtoList(dto.getPrompt(), 2); |
| | | llmStrategyDtoList.add(llmStrategyDto); |
| | | llmStrategyDto = this.buildLlmStrategyDtoList(dto.getTalkId(), 4); |
| | | llmStrategyDtoList.add(llmStrategyDto); |
| | | String modelName = LlmStrategyEnum.getName(aiService.getSystemSetAiType()); |
| | | return Flux.from(result) |
| | | .map(message -> { |
| | | HashMap<String, String> stringStringHashMap = new HashMap<>(); |
| | | |
| | | return llmStrategyFactory.getCalculationStrategyMap().get(modelName).llmInvokeStreamingNoThink(llmStrategyDtoList); |
| | | System.out.print(message.getOutput().getThoughts()); |
| | | if (!message.getOutput().getFinishReason().equals("stop")){ |
| | | stringStringHashMap.put(LlmStrategyContextEnum.CONTENT.name(),message.getOutput().getWorkflowMessage().getMessage().getContent()); |
| | | } |
| | | return new FebsResponse().success().data(stringStringHashMap); |
| | | }) |
| | | .doOnComplete(() -> { |
| | | long endTime = System.currentTimeMillis(); |
| | | System.out.println("百炼工作流输出:" + (endTime - startTime) + "毫秒"); |
| | | }) |
| | | .doOnError(error -> { |
| | | throw new FebsException(StrUtil.format("百炼工作流输出失败:{}",error)); |
| | | }); |
| | | } |
| | | |
| | | private LlmStrategyDto buildLlmStrategyDtoList(String Str, Integer type){ |
| | |
| | | |
| | | @ApiOperation("提问AI(非流式响应)V4") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "非流式响应", response = ApiMemberTalkStreamVo.class), |
| | | @ApiResponse(code = 200, message = "非流式响应", response = ApiMemberTalkStreamVoOld.class), |
| | | }) |
| | | @PostMapping("/answerStreamV4") |
| | | public FebsResponse answerStreamV4(@RequestBody @Validated AiTalkAnswerStream dto) { |