|
|
@@ -136,17 +136,17 @@
|
|
|
<div class="explanation">
|
|
|
<div class="e_header">
|
|
|
<span>{{ lang.ssExplanationTip }}</span>
|
|
|
- <div v-show="false">
|
|
|
+ <div @click="generateExplanation(item, index)" :disabled="chatLoading[index]" v-loading="messagesloading[index]">
|
|
|
<svg t="1774233113566" viewBox="0 0 1027 1024" width="200" height="200">
|
|
|
<path
|
|
|
- d="M511.979521 544.586217a54.525819 54.525819 0 0 1-23.359066-5.247791L31.038758 321.427143a54.397824 54.397824 0 0 1 0-98.236071L488.620455 5.279789c14.719411-7.039718 31.99872-7.039718 46.718131 0l457.581697 217.911283a54.397824 54.397824 0 0 1 0 98.236071l-457.581697 217.911283A54.525819 54.525819 0 0 1 511.979521 544.586217zM180.984761 272.341106L511.979521 429.966801l331.058757-157.625695L511.979521 114.587417 180.984761 272.341106z m354.417823 746.402144l457.517699-217.911283a54.397824 54.397824 0 1 0-46.718131-98.236071L511.979521 909.371625l-434.158634-206.775729a54.397824 54.397824 0 0 0-46.718131 98.236071l457.581697 217.911283a54.525819 54.525819 0 0 0 46.718131 0z m0-239.73441l457.517699-217.847286a54.397824 54.397824 0 1 0-46.718131-98.300068L511.979521 669.573217l-434.158634-206.711731a54.397824 54.397824 0 0 0-46.718131 98.300068l457.581697 217.847286a54.525819 54.525819 0 0 0 46.718131 0z"
|
|
|
+ d="M511.979521 544.586217a54.525819 54.525819 0 0 1-23.359066-5.247791L31.038758 321.427143a54.397824 54.397824 0 0 1 0-98.236071L488.620455 5.279789c14.719411-7.039718 31.99872-7.039718 46.718131 0l457.581697 217.911283a54.397824 54.397824 0 0 1 0 98.236071l-457.581697 217.911283A54.525819 54.525819 0 0 1 511.979521 544.586217zM180.984761 272.341106L511.979521 429.966801l331.058757-157.625695L511.979521 114.587417 180.984761 272.341106z m354.417823 746.402144l457.517699-217.911283a54.397824 54.397824 0 1 0-46.718131-98.236071L511.979521 909.371625l-434.158634-206.775729a54.397824 54.397824 0 0 0-46.718131 98.300068l457.581697 217.847286a54.525819 54.525819 0 0 0 46.718131 0z m0-239.73441l457.517699-217.847286a54.397824 54.397824 0 1 0-46.718131-98.300068L511.979521 669.573217l-434.158634-206.711731a54.397824 54.397824 0 0 0-46.718131 98.300068l457.581697 217.847286a54.525819 54.525819 0 0 0 46.718131 0z"
|
|
|
p-id="9073"></path>
|
|
|
</svg>
|
|
|
- <span>{{ lang.ssAIGenerate }}</span>
|
|
|
+ <span>{{ chatLoading[index] ? lang.ssGenerating : lang.ssAIGenerate }}</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
<el-input type="textarea" rows="3" style="font-size: 1.2rem;" resize="none" v-model="item.explanation"
|
|
|
- :placeholder="lang.ssEnterExplanation" @input="setTestJson()"></el-input>
|
|
|
+ :placeholder="lang.ssEnterExplanation" v-loading="messagesloading[index]" :disabled="chatLoading[index]" @input="setTestJson()"></el-input>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
@@ -167,7 +167,10 @@
|
|
|
<script>
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
import { uploadOneFile } from '@/components/tools/uploadFile'
|
|
|
+import { myMixin } from '@/mixins/mixin'
|
|
|
+
|
|
|
export default {
|
|
|
+ mixins: [myMixin],
|
|
|
emits: ['setTestJson', 'save'],
|
|
|
props: {
|
|
|
workData: {
|
|
|
@@ -180,6 +183,10 @@ export default {
|
|
|
jsonData: {},
|
|
|
dragItem: null,
|
|
|
delJson:null,
|
|
|
+ streamController: [],
|
|
|
+ chatLoading: [],
|
|
|
+ messagesloading: [],
|
|
|
+ userid: this.$route.query.userid,
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
@@ -427,6 +434,56 @@ export default {
|
|
|
this.delJson = null;
|
|
|
}
|
|
|
},
|
|
|
+ // 生成解释
|
|
|
+ async generateExplanation(item, index) {
|
|
|
+ if (this.chatLoading[index]) {
|
|
|
+ this.$message.warning(this.lang.ssPleaseWait);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (this.messagesloading[index]) {
|
|
|
+ this.$message.warning(this.lang.ssPleaseWait);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let zimu = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
+ let prompt = `- 题干:${item.teststitle}
|
|
|
+ - 选项:
|
|
|
+ ${item.checkList.map((check, index) => `${zimu[index]}. ${check}`).join('\n')}
|
|
|
+ - 正确答案(若已知):${item.answer.length > 0 ? item.answer.map(index => zimu[index]).join('、') : '未知'}`
|
|
|
+ this.chatLoading[index] = true
|
|
|
+ this.messagesloading[index] = true
|
|
|
+ this.$forceUpdate()
|
|
|
+ this.chat_stream(prompt, '7dc8f9f4-415e-4cc6-a572-68bd758e9c8b', this.userid || this.workData.userid, this.lang.lang, (event) => {
|
|
|
+ if (event.type === 'message') {
|
|
|
+ this.jsonData.testJson[index].explanation = event.data
|
|
|
+ this.messagesloading[index] = false
|
|
|
+ }
|
|
|
+ else if (event.type === 'messageEnd') {
|
|
|
+ this.jsonData.testJson[index].explanation = event.data
|
|
|
+ this.messagesloading[index] = false
|
|
|
+ this.chatLoading[index] = false
|
|
|
+ this.$forceUpdate()
|
|
|
+ }else if (event.type === 'error') {
|
|
|
+ this.chatLoading[index] = false
|
|
|
+ this.messagesloading[index] = false
|
|
|
+ this.$message.error(event.data)
|
|
|
+ }
|
|
|
+ }).then(controller => {
|
|
|
+ this.streamController[index] = controller
|
|
|
+ }).catch(err => {
|
|
|
+ this.chatLoading[index] = false
|
|
|
+ this.messagesloading[index] = false
|
|
|
+ console.log('err', err)
|
|
|
+ this.stopMessage(index)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ stopMessage(index) {
|
|
|
+ if (this.streamController[index]) {
|
|
|
+ this.streamController[index].abort()
|
|
|
+ this.streamController[index] = null
|
|
|
+ }
|
|
|
+ this.chatLoading[index] = false
|
|
|
+ this.messagesloading[index] = false
|
|
|
+ }
|
|
|
},
|
|
|
mounted() {
|
|
|
window.addEventListener('keydown', (e)=>{
|