Kaynağa Gözat

聊天调整

CzRger 3 hafta önce
ebeveyn
işleme
e8d6edd958

+ 1 - 1
src/api/modules/app/make.ts

@@ -10,7 +10,7 @@ export const promptTemplatesSave = (params) =>
 // 提示词模板-详情
 export const promptTemplatesDetail = (id) =>
   get(`/prompt-templates/${id}`, {}, {}, proxy)
-// 编排信息-详情
+// 编排信息-详情   0-暂存  1-已发布
 export const appModelConfigDetail = (id, status) =>
   get(`/app/model-config/${id}/${status}`, {}, {}, proxy)
 // 编排信息-详情(暂存)

+ 1 - 0
src/types/chat.ts

@@ -10,4 +10,5 @@ export type AnswerStruct = {
   prologueQuestions?: Array<string>
   feedback: 'good' | 'bad'
   finished?: boolean
+  error?: boolean
 }

+ 26 - 11
src/views/chat/answer/index.vue

@@ -6,15 +6,17 @@
     <div class="flex flex-1 flex-col overflow-hidden">
       <template v-if="item.prologue">
         <div
-          class="w-fit rounded-lg rounded-tl-none bg-[#EAF1FF] p-2.75 text-[#303133]"
-          style="line-height: 1.5"
+          class="answer-markdown w-fit overflow-hidden rounded-lg rounded-tl-none bg-[#EAF1FF] p-2.75 text-[#303133]"
           v-html="item.prologue"
         />
         <template v-if="item.prologueQuestions?.length > 0">
-          <template v-if="item.prologueType === 'three'">
+          <template v-if="item.prologueNum == 0">
             <div class="mt-2 ml-2.5 flex flex-col gap-2">
               <template v-for="pq in item.prologueQuestions">
-                <div class="__hover w-fit text-sm text-[var(--czr-main-color)]">
+                <div
+                  class="__hover w-fit text-sm text-[var(--czr-main-color)]"
+                  @click="$emit('setText', { text: pq, send: true })"
+                >
                   {{ pq }}
                 </div>
               </template>
@@ -22,9 +24,14 @@
           </template>
           <template v-else>
             <div class="mt-2 flex flex-wrap gap-x-6 gap-y-1.5">
-              <template v-for="pq in item.prologueQuestions">
+              <template
+                v-for="pq in item.prologueQuestions.filter(
+                  (v, i) => i < item.prologueNum,
+                )"
+              >
                 <div
                   class="__hover w-fit rounded-sm bg-[#F6F6F6] px-2.5 py-1 text-sm text-[var(--czr-main-color)]"
+                  @click="$emit('setText', { text: pq, send: true })"
                 >
                   {{ pq }}
                 </div>
@@ -51,6 +58,7 @@
             <template v-else>
               <div
                 class="answer-markdown"
+                :class="{ error: item.error }"
                 v-html="md.render(part.text.replace(/^<think>/, ''))"
               />
             </template>
@@ -62,12 +70,14 @@
           <div v-if="item.time">{{ formatTimeDuration(item.time) }}</div>
           <div v-if="item.tokens">{{ item.tokens }} Tokens</div>
           <div class="mx-auto" />
-          <el-tooltip content="喜欢" placement="top">
-            <SvgIcon class="__hover" name="good" size="20" />
-          </el-tooltip>
-          <el-tooltip content="不喜欢" placement="top">
-            <SvgIcon class="__hover" name="good" size="20" rotate="180" />
-          </el-tooltip>
+          <template v-if="!item.error">
+            <el-tooltip content="喜欢" placement="top">
+              <SvgIcon class="__hover" name="good" size="20" />
+            </el-tooltip>
+            <el-tooltip content="不喜欢" placement="top">
+              <SvgIcon class="__hover" name="good" size="20" rotate="180" />
+            </el-tooltip>
+          </template>
           <el-tooltip content="复制" placement="top">
             <SvgIcon
               class="__hover"
@@ -121,6 +131,7 @@ const md = new MarkdownIt({
     return `<pre class="hljs"><code>${md.utils.escapeHtml(str)}</code></pre>`
   },
 })
+const emit = defineEmits(['setText'])
 const props = defineProps({
   item: {} as any,
   goodMap: {} as any,
@@ -222,7 +233,11 @@ const formatTimeDuration = (timestamp) => {
 }
 .answer-markdown {
   line-height: 1.5;
+  &.error {
+    color: red;
+  }
   > * {
+    word-break: break-all;
     text-align: justify;
     line-height: inherit;
     margin-bottom: 12px;

+ 3 - 1
src/views/chat/chat.ts

@@ -51,6 +51,7 @@ const handleStream = ({
               return
             }
             const { event } = bufferObj
+            console.log(bufferObj)
             if (event === 'chat_start') {
               onStart?.(bufferObj)
             } else if (event === 'message') {
@@ -64,7 +65,8 @@ const handleStream = ({
                 type: 'error',
                 duration: 0,
               })
-              onError?.(bufferObj)
+            } else {
+              onError?.(bufferObj.message, bufferObj)
             }
           }
         })

+ 8 - 2
src/views/chat/index.vue

@@ -1,9 +1,14 @@
 <template>
   <template v-if="state.isOnline">
-    <onlineChat ref="ref_chat" :test="test" @hangUp="state.isOnline = false" />
+    <onlineChat
+      ref="ref_chat"
+      :ID="ID"
+      :test="test"
+      @hangUp="state.isOnline = false"
+    />
   </template>
   <template v-else>
-    <normalChat ref="ref_chat" :test="test" />
+    <normalChat ref="ref_chat" :ID="ID" :test="test" />
   </template>
 </template>
 
@@ -15,6 +20,7 @@ import onlineChat from './online.vue'
 const props = defineProps({
   online: { default: false },
   test: { default: false },
+  ID: { default: '' },
 })
 const state: any = reactive({
   isOnline: props.online,

+ 89 - 61
src/views/chat/normal.vue

@@ -88,16 +88,19 @@ import { AnswerStruct } from '@/types/chat'
 import { isValue } from '@/utils/czr-util'
 import { ElMessage } from 'element-plus'
 import { chatMessage } from '@/views/chat/chat'
+import { appModelConfigDetail } from '@/api/modules/app/make'
 
 const props = defineProps({
+  ID: { default: '' },
   test: { default: false },
 })
 const state: any = reactive({
   text: '',
   chats: [] as Array<AnswerStruct>,
-  chatConfig: {},
   params: {
+    appId: props.ID,
     query: '',
+    modelConfig: {},
   },
   isWaiting: false,
   isStop: false,
@@ -106,68 +109,78 @@ const ref_text = ref()
 const ref_chatMsg = ref()
 const setText = (text: string, send = false) => {
   if (send) {
-    onSend(text)
+    onSend(text, true)
   } else {
     state.text = text
   }
 }
-const initChat = () => {
-  state.chatConfig = {}
-  state.chats = [
-    {
+const initChat = async () => {
+  state.chats = []
+  const { data }: any = await appModelConfigDetail(props.ID, props.test ? 0 : 1)
+  state.params.modelConfig = data
+  if (state.params.modelConfig.openingStatement.trim()) {
+    state.chats.push({
       type: 'answer',
-      prologue: '您好,请不要问我问题!',
-      prologueType: 'three',
-      prologueQuestions: ['马什么每', '马东什么', '什么冬梅'],
-    },
-    {
-      type: 'answer',
-      prologue: '您好,请不要问我问题!',
-      prologueType: 'all',
-      prologueQuestions: [
-        '马什么每',
-        '马东什么',
-        '什么冬梅',
-        '马什么每',
-        '马东什么',
-        '什么冬梅',
-        '马什么每',
-        '马东什么',
-        '什么冬梅',
-        '马什么每',
-        '马东什么',
-        '什么冬梅',
-      ],
-    },
-    {
-      type: 'ask',
-      text: '现在几点了?',
-    },
-    {
-      type: 'answer',
-      text: '现在是5025年88月99日 77:55:44,星期九。',
-      advise: [],
-      time: 1000 * 2.7,
-      tokens: 22,
-    },
-    {
-      type: 'answer',
-      text: '',
-      advise: [],
-      loading: true,
-    },
-    {
-      type: 'ask',
-      text: '还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?',
-    },
-    {
-      type: 'answer',
-      text: '还有一些问题建议',
-      advise: ['这个时间牛*不', '再问我一个时间吧'],
-      time: 1000 * 457,
-      tokens: 22222222,
-    },
-  ]
+      prologue: state.params.modelConfig.openingStatement,
+      prologueNum: state.params.modelConfig.showAll || 0,
+      prologueQuestions: state.params.modelConfig.suggestedQuestions || [],
+    })
+  }
+  // state.chats = [
+  //   {
+  //     type: 'answer',
+  //     prologue: '您好,请不要问我问题!',
+  //     prologueNum: 'three',
+  //     prologueQuestions: ['马什么每', '马东什么', '什么冬梅'],
+  //   },
+  //   {
+  //     type: 'answer',
+  //     prologue: '您好,请不要问我问题!',
+  //     prologueNum: 'all',
+  //     prologueQuestions: [
+  //       '马什么每',
+  //       '马东什么',
+  //       '什么冬梅',
+  //       '马什么每',
+  //       '马东什么',
+  //       '什么冬梅',
+  //       '马什么每',
+  //       '马东什么',
+  //       '什么冬梅',
+  //       '马什么每',
+  //       '马东什么',
+  //       '什么冬梅',
+  //     ],
+  //   },
+  //   {
+  //     type: 'ask',
+  //     text: '现在几点了?',
+  //   },
+  //   {
+  //     type: 'answer',
+  //     text: '现在是5025年88月99日 77:55:44,星期九。',
+  //     advise: [],
+  //     time: 1000 * 2.7,
+  //     tokens: 22,
+  //   },
+  //   {
+  //     type: 'answer',
+  //     text: '',
+  //     advise: [],
+  //     loading: true,
+  //   },
+  //   {
+  //     type: 'ask',
+  //     text: '还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?还有别的问题建议吗?',
+  //   },
+  //   {
+  //     type: 'answer',
+  //     text: '还有一些问题建议',
+  //     advise: ['这个时间牛*不', '再问我一个时间吧'],
+  //     time: 1000 * 457,
+  //     tokens: 22222222,
+  //   },
+  // ]
   initHistory()
 }
 const initHistory = () => {}
@@ -203,8 +216,11 @@ const scrollToEnd = () => {
     })
   }, 100)
 }
-const onSend = (text = '') => {
-  if ((isValue(state.text.trim()) || text) && !state.loading) {
+const onSend = (text = '', isSet = false) => {
+  if (
+    (isValue(state.text.trim()) || (isSet && isValue(text))) &&
+    !state.loading
+  ) {
     if (state.isWaiting || state.isStop) {
       ElMessage({
         message: '问题回复中,请稍后提问!',
@@ -213,7 +229,7 @@ const onSend = (text = '') => {
       })
       return
     }
-    if (text) {
+    if (isSet) {
       state.params.query = text
     } else {
       state.params.query = state.text + ''
@@ -228,6 +244,7 @@ const onSend = (text = '') => {
       type: 'answer',
       text: '',
       loading: true,
+      error: false,
     })
     state.chats.push(answer)
     scrollToEnd()
@@ -246,7 +263,18 @@ const onSend = (text = '') => {
       onMessageEnd: (data) => {
         state.isStop = false
       },
+      onError: (text, data) => {
+        console.error(text, data)
+        state.isWaiting = false
+        answer.loading = false
+        answer.text += text
+        answer.error = true
+        scrollToEnd()
+        state.isStop = false
+      },
     })
+  } else {
+    ElMessage.warning('请输入问题!')
   }
 }
 const onStop = () => {}

+ 2 - 1
src/views/chat/online.vue

@@ -80,8 +80,9 @@ import useSpeechToAudio from '@/views/chat/audio/useSpeechToAudio'
 import { ElMessage } from 'element-plus'
 import useAudio from '@/views/chat/audio/useAudio'
 
-const emit = defineEmits(['hangUp'])
+const emit = defineEmits(['hangUp', 'onSend'])
 const props = defineProps({
+  ID: { default: '' },
   test: { default: false },
 })
 const state: any = reactive({

+ 5 - 2
src/views/manage/app/make/index.vue

@@ -602,7 +602,7 @@
             </el-tooltip>
           </div>
           <div class="relative flex-1 overflow-hidden rounded-lg">
-            <chat :ID="state.ID" ref="ref_chat" />
+            <chat :ID="state.ID" :test="true" ref="ref_chat" />
             <div
               v-if="!state.canDebug"
               class="absolute inset-0 flex h-full w-full flex-col rounded-lg bg-white/50 p-20 backdrop-blur-sm"
@@ -793,7 +793,7 @@ const state: any = reactive({
   },
   dragRefresh: true,
   canDebug: true,
-  canModelApply: false,
+  canModelApply: true,
   history: [],
 })
 const ref_form = ref()
@@ -1082,6 +1082,9 @@ const onPublishSubmit = () => {
             }).then(() => {
               initHistory()
               state.publish.show = false
+              ElMessage.success(
+                state.publish.form.type == 0 ? '发布成功!' : '提交发布成功!',
+              )
             })
           })
         },