Browse Source

[feat][ai生涯访谈][聊天接口调试]

hizhangling 1 month ago
parent
commit
a5829534cc

+ 13 - 4
src/api/xjc-integratedmachine/environment/ai-career.js

@@ -2,15 +2,15 @@ import request from '@/utils/request'
 
 export function getHotOccupationList(data) {
     return request({
-        url: '/ai/career/hotOccupation/list',
+        url: '/ai/career/hot/occupation/list',
         method: 'get',
         params : data
     })
 }
-export function getOccupationList(data) {
+export function getCareerChatRecordList(data) {
     return request({
-        url: '/ai/career/occupation/list',
-        method: 'get',
+        url: '/ai/career/chat/record/list',
+        method: 'post',
         data : data
     })
 }
@@ -21,3 +21,12 @@ export function getOccupationByKeyword(data) {
         data : data
     })
 }
+
+// 增加生涯聊天记录
+export function addCareerChatRecord(data) {
+    return request({
+        url: '/ai/career/chat/record/add',
+        method: 'post',
+        data : data
+    })
+}

+ 24 - 2
src/views/xjc-integratedmachine/environment/ai_interview/ai_career_interview.vue

@@ -39,7 +39,7 @@
                         <div class="hot-search">
                             <div class="title">热门搜索:</div>
                             <div class="content">
-                                <div class="search-item" v-for="(item, index) in hotOccupationList" :key="index" @click="toChatPage(item)">
+                                <div class="search-item" v-for="(item, index) in hotOccupationList" :key="index" @click="hotToChatPage(item)">
                                     {{item.occupationName}}
                                 </div>
                             </div>
@@ -137,11 +137,33 @@
         router.push({
             path: '/xjc-integratedmachine/environment/ai_career_interview_chat',
             query: {
-                id: row.id
+                occupationId: row.id,
+                occupationName: extractChineseCharacters(row.name)
             }
         })
     }
 
+    function hotToChatPage(row) {
+        router.push({
+            path: '/xjc-integratedmachine/environment/ai_career_interview_chat',
+            query: {
+                occupationId: row.occupationId,
+                occupationName: extractChineseCharacters(row.occupationName)
+            }
+        })
+    }
+
+    /**
+     * 只获取中文
+     */
+    function extractChineseCharacters(str) {
+        // 正则表达式匹配所有汉字
+        const regex = /[\u4e00-\u9fa5]+/g;
+        // 使用match方法找到所有匹配项
+        const matches = str.match(regex);
+        return matches ? matches.join('') : '';
+    }
+
     function getHotOccupation(){
         getHotOccupationList().then(resp => {
             hotOccupationList.value = resp.rows

+ 32 - 16
src/views/xjc-integratedmachine/environment/ai_interview/ai_career_interview_chat.vue

@@ -29,7 +29,7 @@
             <div class="center-header">
                 <div style="margin-left: 30px"></div>
                 <div>小新老师</div>
-                <div class="header-exit-btn">退出</div>
+                <div class="header-exit-btn" @click="exitChatPage">退出</div>
             </div>
             <div v-loading="loadingHistoryRecord" class="chat-container">
                 <div class="message-list" ref="chatContainerRef">
@@ -122,6 +122,7 @@
     import {Base64} from 'js-base64'
     import * as AudioPlayer from "/public/ai/tts/dist/index.umd.js"
     import {aiChatRecordList, aiChatRecordAdd} from '@/api/xjc-integratedmachine/common/aiChat.js'
+    import {getCareerChatRecordList, addCareerChatRecord} from "@/api/xjc-integratedmachine/environment/ai-career.js";
     import msgFold from '@/assets/images/environment/ai-career-msg-fold.png'
     import msgExpand from '@/assets/images/environment/ai-career-msg-expand.png'
     import mutePlayer from '@/assets/images/environment/ai-career-mute-player.png'
@@ -131,7 +132,6 @@
 
     const param = route.query
 
-
     const loadingHistoryRecord = ref(false)
     // 聊天记录
     let chatRecordList = ref([])
@@ -154,14 +154,18 @@
     // 播放按钮状态
     let playActiveIndex = ref(0)
     let playButtonFlag = ref(false)
+
+    const HELLO_MSG = '你是谁?'
     // 查看所有聊天记录
     function list() {
         loadingHistoryRecord.value = true
         let queryForm = {
             pageNum: 1,
-            pageSize: 10000
+            pageSize: 10000,
+            occupationId: param.occupationId,
         }
-        aiChatRecordList(queryForm).then(resp =>{
+        console.log("=======>"+JSON.stringify(queryForm))
+        getCareerChatRecordList(queryForm).then(resp =>{
             chatRecordList.value = resp.rows;
             loadingHistoryRecord.value = false
             setTimeout(()=>{
@@ -175,10 +179,12 @@
 
     function addRecord(content) {
         let queryForm = {
-            content: content,
-            isUser: 0
+            'occupationName': param.occupationName,
+            'occupationId': param.occupationId,
+            'content': content,
+            'isUser': 0
         }
-        aiChatRecordAdd(queryForm).then(resp =>{
+        addCareerChatRecord(queryForm).then(resp =>{
             console.log(resp)
 
         })
@@ -192,7 +198,7 @@
         }
         chatRecordList.value.push(botMsg);*/
 
-        sendRequest('你是谁?')
+        sendRequest(HELLO_MSG)
     }
 
     const sendMessage = () => {
@@ -203,14 +209,17 @@
     }
 
     const sendRequest = async(message) => {
-        // 用户信息
-        const userMsg = {
-            isUser: true,
-            content: message,
-            isTyping: false
+        if(message !== HELLO_MSG){
+            // 用户信息
+            const userMsg = {
+                isUser: true,
+                content: message,
+                isTyping: false
+            }
+            // 消息加入聊天记录
+            chatRecordList.value.push(userMsg)
         }
-        // 消息加入聊天记录
-        chatRecordList.value.push(userMsg)
+
         const botMsg = {
             isUser: false,
             content: '', // 增量填充
@@ -229,10 +238,12 @@
 
             // 请求体
             let form = {
+                'occupationName': param.occupationName,
+                'occupationId': param.occupationId,
                 "content": message? message: "你是谁?"
             }
             // 发送fetch请求
-            const response = await fetch('/dev-api/ai/chat/record/stream', {
+            const response = await fetch('/dev-api/ai/career/chat/record/stream', {
                 method: 'POST',
                 headers: {
                     'Content-Type': 'application/json',
@@ -732,6 +743,10 @@
         }
     }
 
+    function exitChatPage(){
+        router.go(-1)
+    }
+
     onMounted(()=>{
         nextTick(()=>{
             initSpeechRecognition();
@@ -839,6 +854,7 @@
                     align-items: center;
                     justify-content: center;
                     margin-right: 30px;
+                    cursor: pointer;
                 }
             }
             .chat-container {