فهرست منبع

allows to configure the model by env var

Yuki Takei 1 سال پیش
والد
کامیت
08c2f417a2

+ 9 - 1
apps/app/src/features/openai/server/services/assistant/assistant.ts

@@ -10,6 +10,12 @@ const AssistantType = {
   CHAT: 'Chat',
 } as const;
 
+const AssistantDefaultModelMap: Record<AssistantType, OpenAI.Chat.ChatModel> = {
+  [AssistantType.SEARCH]: 'gpt-4o-mini',
+  [AssistantType.CHAT]: 'gpt-4o-mini',
+};
+
+
 type AssistantType = typeof AssistantType[keyof typeof AssistantType];
 
 
@@ -38,18 +44,20 @@ const getOrCreateAssistant = async(type: AssistantType): Promise<OpenAI.Beta.Ass
   const appSiteUrl = configManager.getConfig('crowi', 'app:siteUrl');
   const assistantNameSuffix = configManager.getConfig('crowi', 'openai:assistantNameSuffix');
   const assistantName = `GROWI ${type} Assistant for ${appSiteUrl}${assistantNameSuffix != null ? ` ${assistantNameSuffix}` : ''}`;
+  const assistantModel = configManager.getConfig('crowi', `openai:assistantModel:${type}`) ?? AssistantDefaultModelMap[type];
 
   const assistant = await findAssistantByName(assistantName)
     ?? (
       await openaiClient.beta.assistants.create({
         name: assistantName,
-        model: 'gpt-4o',
+        model: assistantModel,
       }));
 
   // update instructions
   const instructions = configManager.getConfig('crowi', 'openai:chatAssistantInstructions');
   openaiClient.beta.assistants.update(assistant.id, {
     instructions,
+    model: assistantModel,
     tools: [{ type: 'file_search' }],
   });
 

+ 6 - 0
apps/app/src/server/service/config-loader.ts

@@ -809,6 +809,12 @@ Guideline as a RAG:
     type: ValueType.STRING,
     default: null,
   },
+  OPENAI_CHAT_ASSISTANT_MODEL: {
+    ns: 'crowi',
+    key: 'openai:assistantModel:chat',
+    type: ValueType.STRING,
+    default: undefined,
+  },
   OPENAI_THREAD_DELETION_CRON_EXPRESSION: {
     ns: 'crowi',
     key: 'openai:threadDeletionCronExpression',