Procházet zdrojové kódy

feat: 新增input修改,增加深度思考显示

sunxiao před 1 měsícem
rodič
revize
9c5b101100

+ 1 - 1
src/assets/styles/github-markdown-light.scss

@@ -547,7 +547,7 @@
   margin-top: 16px;
 }
 .markdown-body p, .markdown-body li {
-  font-size: 14px;
+  font-size: 16px;
 }
 
 .markdown-body li+li {

+ 39 - 12
src/components/Chat/ChatAgentInput.vue

@@ -1,6 +1,6 @@
 <script setup>
 import { ref, unref, onMounted, onUnmounted, computed, watch } from 'vue';
-import { useMessage, NInput, NSwitch, NPopover, NScrollbar, NUpload, NTooltip, NProgress, NButton } from 'naive-ui';
+import { useMessage, NInput, NPopover, NScrollbar, NUpload, NTooltip, NProgress, NButton } from 'naive-ui';
 import { useUserStore } from '@/stores/modules/userStore';
 import { baseURL } from '@/utils/request';
 import { getFormatYesterDay } from '@/utils/format';
@@ -24,16 +24,15 @@ const MAX_NUM = 5;
 const useStore = useUserStore();
 
 const modelLoading = defineModel('loading');
+const modelOnline = defineModel('online');
+const switchStatus = defineModel('switch');
 
 const selectOptions = [
   { title: 'LibraAl', subTitle: '水务行业专家', value: 0 },
   { title: 'Deepseek', subTitle: '适合深度思考', value: 1 },
 ]
 
-const switchStatus = defineModel('switch');
-
 const message = useMessage();
-const isTempActiveStatus = ref(false);
 
 const inpVal = ref('');
 const inpRef = ref(null);
@@ -72,7 +71,15 @@ watch(inpVal, (curVal) => {
 })
 
 watch(() => props.activeItem, (curVal) => {
-  selectedOption.value = curVal?.tools ? curVal :  null;
+  // console.log(curVal);
+  selectedOption.value = curVal?.tools ? curVal : null;
+  // TODO: 这里后续大概率要删除
+  if ( curVal?.tools ) {
+    // 选中智能体,没有联网搜索
+    modelOnline.value = false;
+    // 选中智能体,需要使用默认的libraAi
+    switchStatus.value = 0;
+  }
 })
 
 const handleInpFocus = () => {
@@ -204,6 +211,10 @@ const selectOption = (index) => {
   highlightedIndex.value = index;
   isOpen.value = false;
   inpVal.value = selectedOption.value.content;
+  // 选中智能体,没有联网搜索
+  modelOnline.value = false;
+  // 选中智能体,需要使用默认的libraAi
+  switchStatus.value = 0;
 }
 
 const beforeUpload = ({ file }) => {
@@ -272,6 +283,7 @@ const clearFileList = () => {
 // 切换智能体
 const onChangeAgent = ({ value }) => {
   switchStatus.value = value;
+  modelOnline.value = false;
 }
 
 onMounted(async () => {
@@ -311,7 +323,7 @@ defineExpose({
         <div class="chat-inp-outer border-[1px]" :class="[{ 'border-[#2454FF]': isFocusState }]">
           <ul class="chat-tools-inner py-[10px] px-[10px] bg-[#fcfcfc]" v-show="selectedOption">
             <li class="tools-tips space-x-[10px]">
-              <span>与</span>            
+              <span>与</span>       
               <p class="agent-name space-x-[5px]" @click="isOpen = true">
                 <img src="https://static.fuxicarbon.com/userupload/db77ffe0cef843278a23b0d2db9505fa.png" alt="">
                 <span>{{ selectedOption?.title }}</span>
@@ -378,7 +390,7 @@ defineExpose({
                   size="medium"
                   placeholder="输入@,召唤智能体"
                   v-model:value="inpVal" 
-                  :autosize="{ minRows: 1, maxRows: 3 }"
+                  :autosize="{ minRows: 2, maxRows: 4 }"
                   @focus="focusInput"
                   @blur="blurInput"
                   @keypress="handleInpEnter"
@@ -388,11 +400,22 @@ defineExpose({
 
             <div class="option-wrapper">
               <div class="option-list space-x-[10px]">
-                <n-popover trigger="focus" to=".option-wrapper" raw :show-arrow="false" placement="top-start" :width="150" content-class="content-class" content-style="padding: 0;">
+                <n-popover 
+                  trigger="focus" 
+                  to=".option-wrapper" 
+                  raw 
+                  :show-arrow="false"
+                  placement="top-start"
+                  :width="150"
+                  content-class="content-class"
+                  content-style="padding: 0;"
+                  isOpen
+                  :disabled="selectedOption"
+                >
                   <template #trigger>
                     <n-button text>
                       <div class="switch-agent option">
-                        <span>{{ selectOptions[switchStatus].title }}</span>
+                        <span>{{ selectOptions[switchStatus]?.title }}</span>
                         <i class="n-base-icon n-base-suffix__arrow"><svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3.14645 5.64645C3.34171 5.45118 3.65829 5.45118 3.85355 5.64645L8 9.79289L12.1464 5.64645C12.3417 5.45118 12.6583 5.45118 12.8536 5.64645C13.0488 5.84171 13.0488 6.15829 12.8536 6.35355L8.35355 10.8536C8.15829 11.0488 7.84171 11.0488 7.64645 10.8536L3.14645 6.35355C2.95118 6.15829 2.95118 5.84171 3.14645 5.64645Z" fill="currentColor"></path></svg></i>
                       </div>
                     </n-button>
@@ -408,8 +431,12 @@ defineExpose({
                   </ul>
                 </n-popover>
 
-                <div class="internet-agent option space-x-[4px]" :class="{'agent-active': isTempActiveStatus}" @click="isTempActiveStatus = !isTempActiveStatus">
-                  <!-- <SvgIcon name="chat-icon-internet"></SvgIcon> -->
+                <div 
+                  class="internet-agent option space-x-[4px]"
+                  :class="{'agent-active': modelOnline}"
+                  @click="modelOnline = !modelOnline"
+                  v-show="switchStatus == 1"
+                >
                   <span class="icon"></span>
                   <span>联网搜索</span>
                   <span class="circle"></span>
@@ -509,7 +536,7 @@ defineExpose({
 
     .inp-wrapper {
       @include flex(x, start, center);
-      margin-bottom: 30px;
+      margin-bottom: 10px;
 
       .upload-inner {
         width: 30px;

+ 15 - 15
src/components/Chat/ChatText.vue

@@ -239,29 +239,27 @@ const thinkParser = (content) => {
   const thinkTagRegex = /<think>/;
   const match = regex.exec(content);
   if ( match !== null ) {
-    return match[1];
+    return match[1]
   }
-  if (thinkTagRegex.test("<think>")) {
+  if (thinkTagRegex.test(content)) {
     return content.slice(7);
   }
-  return content;
 }
 
 
 watchEffect(() => {
   const { content } = props;
- 
-  // if ( content.includes('<think>') ) {
-  //   if (  ) {
-
-  //   }
-  // }
+  const thinkValue = thinkParser(content);
+  // const tempStr = !thinkValue ? content : content.replace(thinkValue, '')
 
+  const tempStr = !thinkValue ? content : content.replace(thinkValue, '')
+  
   // processStreamData(content);
 
-  thinkStr.value = thinkParser(content);
+  thinkStr.value = thinkValue && mdi.render(thinkValue || '');
 
-  const value = mdi.render(processedValue(content));
+  const value = mdi.render(tempStr);
+  // const value = mdi.render(processedValue(content));
 
   const result = splitStringByChartDiv(value)
 
@@ -281,14 +279,13 @@ const text = computed(() => {
     return mdi.render(value)
   return value
 })
-
 </script>
 
 <template>
   <div class="markdown-body text-[15px] break-all" v-if="content">
-    <n-collapse arrow-placement="right" display-directive="show" class="collapse-wrapper">
-      <n-collapse-item title="已深度思考(用时22秒)" name="1">
-        <div class="think-container">{{ thinkStr }}</div>
+    <n-collapse arrow-placement="right" display-directive="show" class="collapse-wrapper" :default-expanded-names="['thinkTag']" v-if="thinkStr">
+      <n-collapse-item title="已深度思考" name="thinkTag">
+        <div class="think-container" v-html="thinkStr"></div>
       </n-collapse-item>
     </n-collapse>
     <div v-for="item, index in markdownText" :key="index" v-html="item"></div>
@@ -319,6 +316,9 @@ const text = computed(() => {
     font-size: 14px;
     line-height: 26px;
     color: rgba(0, 0, 0, 0.6);
+    p, li, span {
+      font-size: 14px;
+    }
   }
 
 

+ 3 - 1
src/views/answer/AnswerView.vue

@@ -21,6 +21,7 @@ const { recommendList } = useRecommend({ type: 0 });
 
 const message = useMessage();
 
+const onlineSearch = ref(false);
 const switchActive = ref(0);
 const activeItem = ref({});
 
@@ -107,7 +108,6 @@ const onRegenerate = async ({ showVal, question, realQuestion, tools, uploadFile
     const [ fileItem ] = uploadFileList;
     fileQuestionStr = `file:${fileItem.name + fileItem.originSuffix}||${fileItem.url}||${question}`
   }
-
   const params = {
     data: {
       sessionId,
@@ -116,6 +116,7 @@ const onRegenerate = async ({ showVal, question, realQuestion, tools, uploadFile
       module: 0,
       modelType: Number(unref(switchActive)),
       isStrong: Number(unref(switchActive)),
+      onlineSearch: Boolean(unref(onlineSearch)),
       tools,
       prompt: null
       // TODO: 后续大概率需要删除
@@ -281,6 +282,7 @@ onUnmounted(() => {
           ref="inputRef"
           v-model:loading="isLoading"
           v-model:switch="switchActive"
+          v-model:online="onlineSearch"
           @on-click="handleSubmit"
           @on-enter="handleSubmit"
         ></ChatAgentInput>

+ 6 - 3
src/views/work/WorkView.vue

@@ -20,7 +20,8 @@ const { chatDataSource, addChat, updateChat, clearChat, updateById } = useChat()
 const helperList = ref([]);
 const message = useMessage();
 
-const switchActive = ref(false);
+const switchActive = ref(0);
+const onlineSearch = ref(false);
 
 const isLoading = ref(false);
 const inputRef = ref(null);
@@ -111,11 +112,12 @@ const onRegenerate = async ({ showVal, question, tools, uploadFileList }) => {
   const params = {
     data: {
       sessionId,
-      showVal,                        // 展示问题
+      showVal,                                  // 展示问题
       question: fileQuestionStr || question,    // 给大模型的问题
       module: 2,
       tools: activeItem.value.tools || tools,
-      isStrong: Number(unref(switchActive))
+      isStrong: Number(unref(switchActive)),
+      onlineSearch: Boolean(unref(onlineSearch)),
     },
     signal: controller.signal,
     onDownloadProgress: ({ event }) => {
@@ -287,6 +289,7 @@ onUnmounted(() => {
           ref="inputRef"
           v-model:loading="isLoading"
           v-model:switch="switchActive"
+          v-model:online="onlineSearch"
           @on-click="handleSubmit"
           @on-enter="handleSubmit"
         ></ChatAgentInput>