Browse Source

feat: 清上下文接口对接

sheldon 1 month ago
parent
commit
e08a79388a
2 changed files with 20 additions and 4 deletions
  1. 9 1
      src/pages/chat/components/PersonalCard/index.tsx
  2. 11 3
      src/service/chat.ts

+ 9 - 1
src/pages/chat/components/PersonalCard/index.tsx

@@ -9,6 +9,8 @@ import IconArrowRightGray from '@/components/icon/IconArrowRightGray';
 import IconClean from '@/components/icon/IconClean';
 import IconArrowVerticalFilled from '@/components/icon/IconArrowVerticalFilled';
 import { useTextChat } from '@/store/textChatStore';
+import { cleanContext } from '@/service/chat';
+import { getLoginId, isSuccess } from "@/utils";
 
 import style from './index.module.less'
 
@@ -32,11 +34,17 @@ export default ({haveBg, agent, onClear}:IProps) => {
     e.stopPropagation()
     setShow(!show)
   }
-  const handleClean = (e:any) => {
+  const handleClean = async (e:any) => {
     // e.stopPropagation()
     console.log('clean')
     setShow(false)
     setIsNewChat(true)
+    Taro.showLoading()
+    await cleanContext({
+      agentId: agent?.agentId || '',
+      loginId: getLoginId()
+    })
+    Taro.hideLoading()
     onClear()
   }
   const handleVoiceChoose = (e:any) => {

+ 11 - 3
src/service/chat.ts

@@ -21,7 +21,7 @@ export const getMessageHistories = (data: TGetMessageHistoriesParams) => {
     { params: data }
   );
 };
-// 推荐提问引导。在获取完成并保存完成后,调用推荐提示获取提问引导 
+// 推荐提问引导。在获取完成并保存完成后,调用推荐提示获取提问引导
 export const getRecommendPrompt = (data: {agentId: string, sessionId: string}) => {
   return request.get<{questions: string[]}>(
     `${bluebookAiAgent}api/v1/chat/recommend/prompt`,
@@ -100,7 +100,7 @@ export const requestStream = <T>({
   jsonParser.onParseComplete((m) => {
     onFinished(m);
   });
-  
+
   const onChunkReceived = (chunk: {data: ArrayBuffer}) => {
     // console.log('chunkReceived: ', chunk);
     const uint8Array = new Uint8Array(chunk.data);
@@ -113,7 +113,7 @@ export const requestStream = <T>({
     }, onAudioParsed);
   };
   const header = getSimpleHeader()
-  
+
   try {
     reqTask = Taro.request({
       url: url,
@@ -238,3 +238,11 @@ export const requestTextToChat = ({
     onError,
   })
 };
+
+// 清除会话上下文
+export const cleanContext = (params: {
+  "agentId": string,
+  "loginId": string
+})=> {
+  return request.post(`${bluebookAiAgent}api/v1/chat/context/clean`, params)
+}