Browse Source

对话区修啊改

SanHQin 4 days ago
parent
commit
add27f77c8
1 changed files with 38 additions and 15 deletions
  1. 38 15
      src/views/Student/components/DialoguePanel.vue

+ 38 - 15
src/views/Student/components/DialoguePanel.vue

@@ -24,7 +24,7 @@
           <div class="dp_ml_i_m_msgArea">
             <div class="dp_ml_i_m_ma_name" v-if="item.aiName" v-text="item.aiName"></div>
             <div class="dp_ml_i_m_ma_textBlok">
-              <span v-if="item.aiContent" v-html="item.aiContent"></span>
+              <span v-if="item.aiContent" v-html="htmlContent(item.aiContent)"></span>
               <svg v-else xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><!-- Icon from SVG Spinners by Utkarsh Verma - https://github.com/n3r4zzurr0/svg-spinners/blob/main/LICENSE --><circle cx="4" cy="12" r="3" fill="currentColor"><animate id="svgSpinners3DotsBounce0" attributeName="cy" begin="0;svgSpinners3DotsBounce1.end+0.25s" calcMode="spline" dur="0.6s" keySplines=".33,.66,.66,1;.33,0,.66,.33" values="12;6;12"/></circle><circle cx="12" cy="12" r="3" fill="currentColor"><animate attributeName="cy" begin="svgSpinners3DotsBounce0.begin+0.1s" calcMode="spline" dur="0.6s" keySplines=".33,.66,.66,1;.33,0,.66,.33" values="12;6;12"/></circle><circle cx="20" cy="12" r="3" fill="currentColor"><animate id="svgSpinners3DotsBounce1" attributeName="cy" begin="svgSpinners3DotsBounce0.begin+0.2s" calcMode="spline" dur="0.6s" keySplines=".33,.66,.66,1;.33,0,.66,.33" values="12;6;12"/></circle></svg>
             </div>
           </div>
@@ -103,7 +103,8 @@
 </template>
 
 <script lang="ts" setup>
-import { ref, reactive, onMounted } from 'vue'
+import { ref, reactive, onMounted, computed } from 'vue'
+
 import { fetchEventSource } from '@microsoft/fetch-event-source'
 import MarkdownIt from 'markdown-it'
 import api from '../../../services/course'
@@ -161,6 +162,14 @@ const curRequestController = ref<AbortController | null>(null)
 // 用户名称
 const userName = ref<string>('')
 
+const htmlContent = computed(() => {
+  const md = new MarkdownIt()
+  return (_md:string) => {
+    return md.render(_md)
+  }
+})
+
+
 // 发送消息
 const sendMessage = () => {
   if (sendMessageLoading.value) return
@@ -181,26 +190,40 @@ const sendMessage = () => {
   messageList.push(newMessage)
   messageListScrollBottom()
 
-  const md = new MarkdownIt()
+  // const params = {
+  //   model: 'gpt-4o-2024-11-20',
+  //   temperature: 0,
+  //   max_tokens: 4096,
+  //   top_p: 1,
+  //   frequency_penalty: 0,
+  //   presence_penalty: 0,
+  //   messages: [{ role: 'user', content: userInput}],
+  //   uid: new Date().getTime().toString(),
+  //   mind_map_question: '',
+  //   stream: true,
+  // }
 
   const params = {
-    model: 'gpt-4o-2024-11-20',
-    temperature: 0,
-    max_tokens: 4096,
+    id: '978252d7-a26e-4e70-8d75-3336497abac1',
+    message: userInput,
+    userId: props.userid,
+    // model: node.properties.item.modelType,
+    model: 'open-gpt-4.1',
+    file_ids: [],
+    sound_url: '',
+    temperature: 0.2,
     top_p: 1,
-    frequency_penalty: 0,
-    presence_penalty: 0,
-    messages: [{ role: 'user', content: userInput}],
-    uid: new Date().getTime().toString(),
-    mind_map_question: '',
+    max_completion_tokens: 4096,
     stream: true,
+    uid: _uid,
+    session_name: `${props.userid}_${props.courseid}_pptCourse`,
   }
 
   let _addText = ''
   curRequestController.value = new AbortController()
 
   fetchEventSource(
-    'https://gpt4.cocorobo.cn/chat_post_stream',
+    'https://appapi.cocorobo.cn/api/agentchats/ai_agent_chat',
     {
       method: 'POST',
       headers: {
@@ -209,7 +232,7 @@ const sendMessage = () => {
       body: JSON.stringify(params),
       signal: curRequestController.value.signal,
       onmessage(ev) {
-        const _data = ev.data
+        const _data = JSON.parse(ev.data).content
         if (_data === '[DONE]') {
           insertChat(_uid)
           return (sendMessageLoading.value = false)
@@ -218,7 +241,7 @@ const sendMessage = () => {
         const msgItem = messageList.find((item) => item.id === _uid)
         
         if (msgItem) {
-          msgItem.aiContent = md.render(_addText)
+          msgItem.aiContent = _addText
           msgItem.loading = false
         }
         messageListScrollBottom()
@@ -229,7 +252,7 @@ const sendMessage = () => {
         console.log('连接关闭')
       },
       onerror(err) {
-        console.error(err)
+        console.log(err)
         sendMessageLoading.value = false
         const errorMsgItem = messageList.find((item) => item.id === _uid)
         if (errorMsgItem) {