Просмотр исходного кода

feat(aiChat): 更新AI聊天接口以支持多参数传递

修改chat_stream和chat_no_stream接口,新增agentId、userId和language参数
重构ChatParams接口定义,更新默认参数和请求体结构
添加getAgentModel方法用于获取agent模型类型
SanHQin 3 недель назад
Родитель
Сommit
d327aac714
3 измененных файлов с 58 добавлено и 28 удалено
  1. 54 25
      src/tools/aiChat.ts
  2. 3 2
      src/views/Student/components/choiceQuestionDetailDialog.vue
  3. 1 1
      src/views/Student/index.vue

+ 54 - 25
src/tools/aiChat.ts

@@ -2,42 +2,53 @@ import axios from "@/services/config"
 import { v4 as uuidv4 } from 'uuid'
 import { v4 as uuidv4 } from 'uuid'
 import { fetchEventSource } from '@microsoft/fetch-event-source'
 import { fetchEventSource } from '@microsoft/fetch-event-source'
 
 
+let model = {}
+
 interface ChatParams {
 interface ChatParams {
+  id: string;
+  message: string;
+  userId: string;
   model: string;
   model: string;
+  file_ids: string[];
+  sound_url: string;
   temperature: number;
   temperature: number;
-  max_tokens: number;
   top_p: number;
   top_p: number;
-  frequency_penalty: number;
-  presence_penalty: number;
-  messages: Array<{ role: string; content: string }>;
-  uid: string;
-  mind_map_question: string;
+  max_completion_tokens: number;
   stream: boolean;
   stream: boolean;
-  response_format: { type: string };
+  uid: string;
+  session_name: string;
+  tts_language: string;
 }
 }
 
 
-const DEFAULT_PARAMS: Omit<ChatParams, 'messages' | 'uid'> = {
-  model: "gpt-4o-2024-11-20",
-  temperature: 0,
-  max_tokens: 4096,
+const DEFAULT_PARAMS: Omit<ChatParams, 'message' | 'uid' | 'stream'> = {
+  id: "a7741704-ba56-40b7-a6b8-62a423ef9376",
+  userId: "6c56ec0e-2c74-11ef-bee5-005056b86db5",
+  model: "open-doubao",
+  file_ids: [],
+  sound_url: "",
+  temperature: 0.2,
   top_p: 1,
   top_p: 1,
-  frequency_penalty: 0,
-  presence_penalty: 0,
-  mind_map_question: "",
-  stream: false,
-  response_format: { type: "text" }
-};
+  max_completion_tokens: 4096,
+  session_name: "pptSession_name",
+  tts_language: "zh-CN"
+}
 
 
-export const chat_no_stream = async (msg: string): Promise<string> => {
+export const chat_no_stream = async (msg: string, agentId: string, userId: string, language: string): Promise<string> => {
+  let modelType = await getAgentModel(agentId)
   const params: ChatParams = {
   const params: ChatParams = {
     ...DEFAULT_PARAMS,
     ...DEFAULT_PARAMS,
-    messages: [{ role: "user", content: msg }],
+    id: agentId,
+    message: msg,
     uid: uuidv4(),
     uid: uuidv4(),
-    stream: false
-  };
+    stream: false,
+    model: modelType,
+    userId: userId,
+    tts_language: language,
+    session_name:uuidv4()
+   };
 
 
   try {
   try {
-    const res = await axios.post('https://appapi.cocorobo.cn/api/common/chat', params);
+    const res = await axios.post('https://appapi.cocorobo.cn/api/agentchats/ai_agent_chat', params);
     let content = res.FunctionResponse.choices[0].message.content;
     let content = res.FunctionResponse.choices[0].message.content;
 
 
     // 清理可能的 markdown 格式
     // 清理可能的 markdown 格式
@@ -63,19 +74,28 @@ export const chat_no_stream = async (msg: string): Promise<string> => {
 
 
 export const chat_stream = async (
 export const chat_stream = async (
   msg: string,
   msg: string,
+  agentId: string,
+  userId: string,
+  language: string,
   onMessage: (event: { type: 'message' | 'close' | 'error' | 'messageEnd'; data: string }) => void
   onMessage: (event: { type: 'message' | 'close' | 'error' | 'messageEnd'; data: string }) => void
 ): Promise<void> => {
 ): Promise<void> => {
+  let modelType = await getAgentModel(agentId)
   const params: ChatParams = {
   const params: ChatParams = {
     ...DEFAULT_PARAMS,
     ...DEFAULT_PARAMS,
-    messages: [{ role: "user", content: msg }],
+    id: agentId,
+    message: msg,
     uid: uuidv4(),
     uid: uuidv4(),
-    stream: true
+    stream: true,
+    model: modelType,
+    userId: userId,
+    tts_language: language,
+    session_name:uuidv4()
   };
   };
 
 
   const ctrl = new AbortController();
   const ctrl = new AbortController();
   let content = ''
   let content = ''
   try {
   try {
-    await fetchEventSource('https://appapi.cocorobo.cn/api/common/chat', {
+    await fetchEventSource('https://appapi.cocorobo.cn/api/agentchats/ai_agent_chat', {
       method: 'POST',
       method: 'POST',
       body: JSON.stringify(params),
       body: JSON.stringify(params),
       signal: ctrl.signal,
       signal: ctrl.signal,
@@ -119,3 +139,12 @@ export const chat_stream = async (
     ctrl.abort();
     ctrl.abort();
   }
   }
 };
 };
+
+export const getAgentModel = async (agentId: string) => {
+  if (model[agentId]) {
+    return model[agentId]
+  }
+  let res = await axios.get(`https://appapi.cocorobo.cn/api/agents/agent/${agentId}`)
+  model[agentId] = res['modelType']
+  return model[agentId]
+}

+ 3 - 2
src/views/Student/components/choiceQuestionDetailDialog.vue

@@ -241,6 +241,7 @@ const props = defineProps<{
   showData: any;
   showData: any;
   workArray: any[];
   workArray: any[];
   courseDetail: any;
   courseDetail: any;
+  userId: string;
 }>()
 }>()
 
 
 const emit = defineEmits<{
 const emit = defineEmits<{
@@ -827,7 +828,7 @@ if(!currentAnalysis.value){
     }).json = ""
     }).json = ""
 }
 }
 
 
-chat_stream(msg, (event) => {
+chat_stream(msg,'a7741704-ba56-40b7-a6b8-62a423ef9376', props.userId, 'zh-CN', (event) => {
   if (event.type === 'message') { 
   if (event.type === 'message') { 
     aiAnalysisData.value.find((item:any)=>{
     aiAnalysisData.value.find((item:any)=>{
       return item.pid === props.showData.workDetail.id && item.index === props.showData.workIndex
       return item.pid === props.showData.workDetail.id && item.index === props.showData.workIndex
@@ -902,7 +903,7 @@ if(!currentAnalysis.value){
     }).json = ""
     }).json = ""
 }
 }
 
 
-chat_stream(msg, (event) => {
+chat_stream(msg,'a7741704-ba56-40b7-a6b8-62a423ef9376', props.userId, 'zh-CN', (event) => {
   if (event.type === 'message') { 
   if (event.type === 'message') { 
     aiAnalysisData.value.find((item:any)=>{
     aiAnalysisData.value.find((item:any)=>{
       return item.pid === props.showData.workDetail.id && item.index === props.showData.workIndex
       return item.pid === props.showData.workDetail.id && item.index === props.showData.workIndex

+ 1 - 1
src/views/Student/index.vue

@@ -89,7 +89,7 @@
           <ScreenSlideList :style="{ width: isFullscreen ? '100%' : slideWidth2 * canvasScale + 'px', height: isFullscreen ? '100%' : slideHeight2 * canvasScale + 'px', margin: '0 auto' }" :slideWidth="isFullscreen ? slideWidth * canvasScale : slideWidth2 * canvasScale" :slideHeight="isFullscreen ? slideHeight * canvasScale : slideHeight2 * canvasScale"
           <ScreenSlideList :style="{ width: isFullscreen ? '100%' : slideWidth2 * canvasScale + 'px', height: isFullscreen ? '100%' : slideHeight2 * canvasScale + 'px', margin: '0 auto' }" :slideWidth="isFullscreen ? slideWidth * canvasScale : slideWidth2 * canvasScale" :slideHeight="isFullscreen ? slideHeight * canvasScale : slideHeight2 * canvasScale"
             :animationIndex="0" :turnSlideToId="() => { }" :manualExitFullscreen="() => { }"  :slideIndex="slideIndex" v-show="!choiceQuestionDetailDialogOpenList.includes(slideIndex)"/>
             :animationIndex="0" :turnSlideToId="() => { }" :manualExitFullscreen="() => { }"  :slideIndex="slideIndex" v-show="!choiceQuestionDetailDialogOpenList.includes(slideIndex)"/>
 
 
-          <choiceQuestionDetailDialog v-if="choiceQuestionDetailDialogOpenList.includes(slideIndex)" :courseDetail="courseDetail" :workArray="workArray" @changeWorkIndex="changeWorkIndex" v-model:visible="choiceQuestionDetailDialogOpenList" :showData="answerTheResultRef" :slideIndex="slideIndex" :workIndex="0" :style="{ width: isFullscreen ? '100%' : slideWidth2 * canvasScale + 'px', height: isFullscreen ? '100%' : slideHeight2 * canvasScale + 'px', margin: '0 auto' }" :slideWidth="isFullscreen ? slideWidth * canvasScale : slideWidth2 * canvasScale" :slideHeight="isFullscreen ? slideHeight * canvasScale : slideHeight2 * canvasScale"/>
+          <choiceQuestionDetailDialog v-if="choiceQuestionDetailDialogOpenList.includes(slideIndex)" :userId="props.userid" :courseDetail="courseDetail" :workArray="workArray" @changeWorkIndex="changeWorkIndex" v-model:visible="choiceQuestionDetailDialogOpenList" :showData="answerTheResultRef" :slideIndex="slideIndex" :workIndex="0" :style="{ width: isFullscreen ? '100%' : slideWidth2 * canvasScale + 'px', height: isFullscreen ? '100%' : slideHeight2 * canvasScale + 'px', margin: '0 auto' }" :slideWidth="isFullscreen ? slideWidth * canvasScale : slideWidth2 * canvasScale" :slideHeight="isFullscreen ? slideHeight * canvasScale : slideHeight2 * canvasScale"/>
 
 
 
 
           <div class="slide-bottom" v-if="!isFullscreen">
           <div class="slide-bottom" v-if="!isFullscreen">