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

fix: add aiAssistantId to request body for editor assistant

Yuki Takei 9 месяцев назад
Родитель
Сommit
2c3fcadded

+ 1 - 0
apps/app/src/features/openai/client/services/editor-assistant/use-editor-assistant.tsx

@@ -191,6 +191,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
 
     const requestBody = {
       threadId,
+      aiAssistantId: selectedAiAssistant?._id,
       userMessage: formData.input,
       selectedText,
       pageBody: pageBodyContext.content,

+ 5 - 3
apps/app/src/features/openai/server/routes/edit/index.ts

@@ -172,7 +172,7 @@ export const postMessageToEditHandlersFactory: PostMessageHandlersFactory = (cro
         userMessage,
         pageBody, isPageBodyPartial, partialPageBodyStartIndex,
         selectedText, selectedPosition,
-        threadId,
+        threadId, aiAssistantId: _aiAssistantId,
       } = req.body;
 
       // Parameter check
@@ -192,14 +192,16 @@ export const postMessageToEditHandlersFactory: PostMessageHandlersFactory = (cro
       }
 
       // Check if usable
-      if (threadRelation.aiAssistant != null) {
-        const aiAssistantId = getIdStringForRef(threadRelation.aiAssistant);
+      const aiAssistantId = _aiAssistantId ?? (threadRelation.aiAssistant != null ? getIdStringForRef(threadRelation.aiAssistant) : undefined);
+      if (aiAssistantId != null) {
         const isAiAssistantUsable = await openaiService.isAiAssistantUsable(aiAssistantId, req.user);
         if (!isAiAssistantUsable) {
           return res.apiv3Err(new ErrorV3('The specified AI assistant is not usable'), 400);
         }
       }
 
+      const aiAssistant = aiAssistantId != null ? await AiAssistantModel.findById(aiAssistantId) : undefined;
+
       // Initialize SSE helper and stream processor
       const sseHelper = new SseHelper(res);
       const streamProcessor = new LlmResponseStreamProcessor({