|
|
@@ -3,27 +3,32 @@
|
|
|
Author: BaiQi
|
|
|
Created Date: 2024-6-21
|
|
|
-->
|
|
|
+<!--TODO: 设置单次ai对话次数:10次-->
|
|
|
<template>
|
|
|
- <div :class="$style.container">
|
|
|
+ <div :class="[{'teacher-view': props.isTeacher},$style.container]">
|
|
|
<!--大语言模型选择器-->
|
|
|
- <div :class="$style.header">
|
|
|
- <div :class="$style['model-selector']">
|
|
|
- <el-dropdown trigger="click" @command="handleCommand">
|
|
|
- <span style="font-size: 16px">
|
|
|
- {{ data.model }}<el-icon ><arrow-down/></el-icon>
|
|
|
- </span>
|
|
|
- <template #dropdown>
|
|
|
- <el-dropdown-menu>
|
|
|
- <el-dropdown-item v-for="model in modelOptions" :command="model">{{ model }}</el-dropdown-item>
|
|
|
- </el-dropdown-menu>
|
|
|
- </template>
|
|
|
- </el-dropdown>
|
|
|
+ <!-- Update: 目前只有glm4可用 删掉其他选项 -->
|
|
|
+ <div v-if="!props.isTeacher">
|
|
|
+ <div :class="$style.header">
|
|
|
+ <div :class="$style['model-selector']">
|
|
|
+ <el-dropdown trigger="click" @command="handleCommand">
|
|
|
+ <span style="font-size: 16px">
|
|
|
+ {{ data.model }}<el-icon ><arrow-down/></el-icon>
|
|
|
+ </span>
|
|
|
+ <template #dropdown>
|
|
|
+ <el-dropdown-menu>
|
|
|
+ <el-dropdown-item v-for="model in modelOptions" :command="model">{{ model }}</el-dropdown-item>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </template>
|
|
|
+ </el-dropdown>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
<!-- 消息区域,采用ChatGPT的交互模式 -->
|
|
|
<div :class="$style['message-box']" ref="containerTopRef">
|
|
|
<div
|
|
|
- v-for="(item, index) in data.messages"
|
|
|
+ v-for="(item, index) in messageList"
|
|
|
:key="index"
|
|
|
:class="$style.item"
|
|
|
>
|
|
|
@@ -48,38 +53,40 @@
|
|
|
</div>
|
|
|
|
|
|
<!-- 对话框区域,用于AI提问和提示词模版展现 -->
|
|
|
- <div :class="$style['question-box']">
|
|
|
- <div :class="$style['input-group']">
|
|
|
- <el-input
|
|
|
- v-model="data.questionContent"
|
|
|
- ref="inputRef"
|
|
|
- :placeholder="`Message ${data.model} ...`"
|
|
|
- >
|
|
|
- </el-input>
|
|
|
- <el-button
|
|
|
- :disabled="data.questionContent === ''"
|
|
|
- @click="handleSendQuestion"
|
|
|
- style="width: 40px; border: none"
|
|
|
- v-loading="data.loading"
|
|
|
- >
|
|
|
- <el-icon><Top/></el-icon>
|
|
|
- </el-button>
|
|
|
- <el-dropdown @command="handleMenuClick">
|
|
|
- <el-button type="text" style="width: 40px;">
|
|
|
- <el-icon><ArrowDown/></el-icon>
|
|
|
+ <div v-if="!props.isTeacher">
|
|
|
+ <div :class="$style['question-box']">
|
|
|
+ <div :class="$style['input-group']">
|
|
|
+ <el-input
|
|
|
+ v-model="data.questionContent"
|
|
|
+ ref="inputRef"
|
|
|
+ :placeholder="`Message ${data.model} ...`"
|
|
|
+ >
|
|
|
+ </el-input>
|
|
|
+ <el-button
|
|
|
+ :disabled="data.questionContent === ''"
|
|
|
+ @click="handleSendQuestion"
|
|
|
+ style="width: 40px; border: none"
|
|
|
+ v-loading="data.loading"
|
|
|
+ >
|
|
|
+ <el-icon><Top/></el-icon>
|
|
|
</el-button>
|
|
|
- <template #dropdown>
|
|
|
- <el-dropdown-menu>
|
|
|
- <el-dropdown-item
|
|
|
- v-for="(template, index) in questionTemplates"
|
|
|
- :key="index"
|
|
|
- :command="index"
|
|
|
- >
|
|
|
- {{ template }}
|
|
|
- </el-dropdown-item>
|
|
|
- </el-dropdown-menu>
|
|
|
- </template>
|
|
|
- </el-dropdown>
|
|
|
+ <el-dropdown @command="handleMenuClick">
|
|
|
+ <el-button type="text" style="width: 40px;">
|
|
|
+ <el-icon><ArrowDown/></el-icon>
|
|
|
+ </el-button>
|
|
|
+ <template #dropdown>
|
|
|
+ <el-dropdown-menu>
|
|
|
+ <el-dropdown-item
|
|
|
+ v-for="(template, index) in questionTemplates"
|
|
|
+ :key="index"
|
|
|
+ :command="index"
|
|
|
+ >
|
|
|
+ {{ template }}
|
|
|
+ </el-dropdown-item>
|
|
|
+ </el-dropdown-menu>
|
|
|
+ </template>
|
|
|
+ </el-dropdown>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -103,21 +110,23 @@
|
|
|
L 15 15
|
|
|
" style="fill: rgba(0, 0, 0, 0)"/>
|
|
|
`
|
|
|
-
|
|
|
+//update: 加入isTeacher属性,用于判断是否是教师批改界面
|
|
|
interface IProps {
|
|
|
dialogueId: string;
|
|
|
messages: IDialogue[]
|
|
|
+ isTeacher: boolean
|
|
|
}
|
|
|
|
|
|
const props = defineProps<{
|
|
|
dialogueId: string,
|
|
|
messages: IDialogue[]
|
|
|
+ isTeacher: boolean
|
|
|
}>()
|
|
|
|
|
|
const apis = useApis()
|
|
|
const store = useStore()
|
|
|
- // ChatGLM改为4
|
|
|
- const modelOptions = ["ChatGPT", "ChatGLM4", "QWen14B"]
|
|
|
+ //UPDATE: 目前只有ChatGLM4
|
|
|
+ const modelOptions = ["ChatGLM4"]
|
|
|
const questionTemplates = [
|
|
|
"xxx是什么意思?",
|
|
|
"英文如何描述xxx",
|
|
|
@@ -129,6 +138,9 @@
|
|
|
const messagesEndRef = ref(null);
|
|
|
const containerTopRef = ref(null);
|
|
|
|
|
|
+ // 用于处理ai对话展示异常问题
|
|
|
+ let messageList:IDialogue[] = []
|
|
|
+
|
|
|
let data = reactive<{
|
|
|
model: string;
|
|
|
questionContent: string;
|
|
|
@@ -148,6 +160,7 @@
|
|
|
// 加载聊天记录,并滚动至最后
|
|
|
onMounted(() => {
|
|
|
if (props.messages) data.messages = props.messages;
|
|
|
+ // console.log(props.messages)
|
|
|
scrollToEnd();
|
|
|
});
|
|
|
|
|
|
@@ -158,6 +171,8 @@
|
|
|
watch(() => props.messages, (newMessages:any) => {
|
|
|
if (newMessages)
|
|
|
data.messages = newMessages;
|
|
|
+ console.log(newMessages)
|
|
|
+ handleMessageList()
|
|
|
scrollToEnd();
|
|
|
});
|
|
|
|
|
|
@@ -185,6 +200,7 @@
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ // BUG: 按这套逻辑显示的名字可能与内容对不上
|
|
|
const handleSendQuestion = () => {
|
|
|
data.loading = true;
|
|
|
|
|
|
@@ -197,8 +213,8 @@
|
|
|
apis.requestAI(props.dialogueId, data.model, requestBody)
|
|
|
.then((_res:any) => {
|
|
|
const resDialogue = _res.data.data;
|
|
|
- console.log(resDialogue);
|
|
|
data.messages.push(resDialogue);
|
|
|
+ handleMessageList()
|
|
|
})
|
|
|
.catch((_err:any) => {
|
|
|
console.log(_err);
|
|
|
@@ -216,10 +232,34 @@
|
|
|
|
|
|
// 选择模板问题
|
|
|
const handleMenuClick = (key:any) => {
|
|
|
- data.questionContent = questionTemplates[key];
|
|
|
- inputRef.value.focus();// 设置焦点自动回到Input
|
|
|
+ // data.questionContent = questionTemplates[key];
|
|
|
+ // inputRef.value.focus();// 设置焦点自动回到Input
|
|
|
+ console.log(data.messages)
|
|
|
};
|
|
|
|
|
|
+ // 处理ai对话显示异常问题
|
|
|
+ const handleMessageList = () => {
|
|
|
+ let count1 = 0
|
|
|
+ let count2 = 1
|
|
|
+ for(let message of data.messages){
|
|
|
+ if(message.role == "user"){
|
|
|
+ messageList[count1] = {
|
|
|
+ role: "user",
|
|
|
+ content: message.content
|
|
|
+ }
|
|
|
+ count1+=2
|
|
|
+ }
|
|
|
+ if(message.role == "assistant"){
|
|
|
+ messageList[count2] = {
|
|
|
+ role: "assistant",
|
|
|
+ content: message.content
|
|
|
+ }
|
|
|
+ count2+=2
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<script lang="ts">
|