From 9b46a6075048ec870edc814ee159c9847b1d1b11 Mon Sep 17 00:00:00 2001 From: Innei Date: Wed, 7 May 2025 00:41:01 +0800 Subject: [PATCH] feat(ai): enhance OpenAI configuration with additional headers - Added 'X-Title' and 'HTTP-Referer' headers to the OpenAI client configuration for improved request context. - Included web URL in the configuration to support better tracking and analytics. Signed-off-by: Innei --- apps/core/src/modules/ai/ai.service.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/core/src/modules/ai/ai.service.ts b/apps/core/src/modules/ai/ai.service.ts index 120cc025..1e56a425 100644 --- a/apps/core/src/modules/ai/ai.service.ts +++ b/apps/core/src/modules/ai/ai.service.ts @@ -13,6 +13,7 @@ export class AiService { public async getOpenAiChain(options?: { maxTokens?: number }) { const { ai: { openAiKey, openAiEndpoint, openAiPreferredModel }, + url: { webUrl }, } = await this.configService.waitForConfigReady() if (!openAiKey) { throw new BizException(ErrorCodeEnum.AINotEnabled, 'Key not found') @@ -23,6 +24,10 @@ export class AiService { apiKey: openAiKey, configuration: { baseURL: openAiEndpoint || void 0, + defaultHeaders: { + 'X-Title': 'Mix Space AI Client', + 'HTTP-Referer': webUrl, + }, }, maxTokens: options?.maxTokens, })