增加第三种模型

This commit is contained in:
liuyalei 2024-03-18 15:43:40 +08:00
parent 58de9e9af5
commit 8d15c3004f
2 changed files with 70 additions and 30 deletions

View File

@ -82,7 +82,7 @@
</div>
</div> -->
<div class="message-container" id="chatform">
<div class="message" v-for="(message, index) in messages" :key="message.id">
<div class="message" v-for="(message, index) in messages" :key="message.usrid">
<div class="Left" v-if="!message.isMe">
<div class="Left_mesg">
<div v-if="message.type == 'txt'" class="txt txt_l"> {{ message.text }}</div>
@ -285,16 +285,23 @@ import { v4 as uuidv4 } from 'uuid';
import http from '@/api/http.js'
// import http from '@/utils/request.js'
let recomanTags = ref(['公积金查询', '2024放假安排', '附近推荐的锻炼场所'])
let modeldata = ref(['模型一', '模型二'])
//
let sinalModel = ref(false)
let pathname = ref('')
let modeldata = ref('')
if (sinalModel.value) {
pathname.value='/three'
modeldata.value = ['模型三']
} else {
pathname.value='/generate'
modeldata.value = ['模型一', '模型二', '模型三']
}
let inputText = ref('')
let messages = reactive([
]);
// let lastMessageId = ref(0); // ID
// let messages = ref([
// ]);
console.log("pathname", pathname.value);
let kearr = reactive([{ name: '神经内科', path: '' }, { name: '儿科', path: '' }, { name: '外科', path: '' }])
let messagesCopy = reactive([
{ id: 1, type: 'fstxt', text: '您可以点击下方快捷方式选择问题,或直接编辑问题发送给我哟', isMe: false },/* */
@ -320,10 +327,15 @@ const cksend = (val) => {
let modelnum = ref('')
const changetype = (num) => {
modelnum.value = num
if (num == 1) {
if (sinalModel.value) { pathname.value = '/three' }
else {
if (num == 0) {
pathname.value = '/generate'
} else if (num == 1) {
pathname.value = '/main_serve'
} else {
pathname.value = '/generate'
pathname.value = '/three'
}
}
console.log("模型", pathname.value);
}
@ -331,20 +343,33 @@ const handleInputFocus = () => {
console.log("聚焦了");
scollToButtom();
}
let pathname = ref('/generate')
const uid = uuidv4()
const event = new EventSource('/three/srv/platform/chat/connect/' + uid, { withCredentials: true });
event.onmessage = function (e) {
console.log("e", JSON.parse(e.data));
var strpart = JSON.parse(e.data)
messages.map((vv, ii) => {
if (vv.qid == strpart.qid) {
vv.text = vv.text.replace('思考中...', '')
vv.text += strpart.text
}
})
scollToButtom()
}
const sendMessage = () => {
console.log("信息发送成功", inputText.value);
let messageValue = inputText.value.trim()
if (inputText.value.trim()) {
// lastMessageId.value += 1;
messages.push({ id: uuidv4(), text: inputText.value, isMe: true, type: 'txt', });
console.log("模型", pathname.value, messages);
messages.push({ usrid: uid, qid: uuidv4(), text: inputText.value, isMe: true, type: 'txt', });
// console.log("", pathname.value, messages);
console.log("模型", pathname.value );
if (pathname.value == '/generate') {
messages.push({ id: uuidv4(), text: '思考中。。。', isMe: true, type: 'loading', });
messages.push({ usrid: uid, qid: uuidv4(), text: '思考中。。。', isMe: true, type: 'loading', });
http.post(pathname.value, { "text": messageValue }).then((res) => {
// var msg = JSON.parse(res.name)
var msg = res.response
messages.push({ id: uuidv4(), text: msg, isMe: false, type: 'txt' });
messages.push({ usrid: uid, qid: uuidv4(), text: msg, isMe: false, type: 'txt' });
messages.map((vv, ii) => {
if (vv.type == 'loading') {
messages.splice(ii, 1)
@ -361,8 +386,8 @@ const sendMessage = () => {
})
} else if (pathname.value == '/main_serve') {
var mgsid = uuidv4()
messages.push({ id: mgsid, text: '加载中...', isMe: false, type: 'txt' });
fetchEventSource('/main_serve', {
messages.push({ usrid: uid, qid: mgsid, text: '加载中...', isMe: false, type: 'txt' });
fetchEventSource('/main_serve?id=' + uuidv4(), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ -373,7 +398,7 @@ const sendMessage = () => {
onmessage(ev) {
console.log("媒体流", JSON.parse(ev.data).response);
messages.map((v, i) => {
if(v.id==mgsid){
if (v.qid == mgsid) {
v.text = v.text.replace('加载中...', '')
v.text += JSON.parse(ev.data).response
scollToButtom()
@ -381,6 +406,14 @@ const sendMessage = () => {
})
}
});
} else if (pathname.value == '/three') {
var msid = uuidv4()
http.post(pathname.value + '/srv/platform/chat', { 'id': uid, 'qid': msid, "prompt": messageValue }).then((res) => {
console.log("three message", res);
messages.push({ usrid: uid, qid: msid, text: '思考中...', isMe: false, type: 'txt' });
scollToButtom()
}).catch(error => {
})
}
// if (inputText.value.indexOf('') != -1 || inputText.value.indexOf('') != -1) {
@ -412,9 +445,9 @@ const goke = () => {
// console.log("goke");
const insertWord = '您想看普通还是专家门诊?如有其他需求,也请告诉我'
// messagesCopy[11].id = Date.now();
messagesCopy[11].id = uuidv4();
messagesCopy[11].usrid = uid;
messagesCopy[11].qid = uuidv4();
messagesCopy[11].text = insertWord
messages.push(messagesCopy[11]);
scollToButtom();
};
@ -451,7 +484,7 @@ onMounted(() => {
// messages
setTimeout(() => {
// messages.push({ id: Date.now(), type: 'fstxt', text: '', isMe: false });
messages.push({ id: uuidv4(), type: 'fstxt', text: '您可以点击下方快捷方式选择问题,或直接编辑问题发送给我哟', isMe: false });
messages.push({ usrid: uid,qid:uuidv4(), type: 'fstxt', text: '您可以点击下方快捷方式选择问题,或直接编辑问题发送给我哟', isMe: false });
}, 500);
})
@ -549,7 +582,7 @@ onMounted(() => {
border: 1px solid #000;
width: 40%;
height: 100%;
right: 20%;
right: 4%;
font-size: 12px;
text-align: center;
line-height: 28px;

View File

@ -25,6 +25,13 @@ export default defineConfig({
changeOrigin: true,
// rewrite: path => path.replace(/^\/main_serve/, '/main_serve/')
},
"/three": {
target: "http://192.168.1.2:10001/",
// target: "https://yx.cityme.com.cn/",
changeOrigin: true,
// rewrite: path => path.replace(/^\/three/, '')
rewrite: path => path.replace(/\/three/, '')
},
'/srv': {
// target: "https://aiai.cityme.com.cn",