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 <tukon479@gmail.com>
This commit is contained in:
@@ -13,6 +13,7 @@ export class AiService {
|
|||||||
public async getOpenAiChain(options?: { maxTokens?: number }) {
|
public async getOpenAiChain(options?: { maxTokens?: number }) {
|
||||||
const {
|
const {
|
||||||
ai: { openAiKey, openAiEndpoint, openAiPreferredModel },
|
ai: { openAiKey, openAiEndpoint, openAiPreferredModel },
|
||||||
|
url: { webUrl },
|
||||||
} = await this.configService.waitForConfigReady()
|
} = await this.configService.waitForConfigReady()
|
||||||
if (!openAiKey) {
|
if (!openAiKey) {
|
||||||
throw new BizException(ErrorCodeEnum.AINotEnabled, 'Key not found')
|
throw new BizException(ErrorCodeEnum.AINotEnabled, 'Key not found')
|
||||||
@@ -23,6 +24,10 @@ export class AiService {
|
|||||||
apiKey: openAiKey,
|
apiKey: openAiKey,
|
||||||
configuration: {
|
configuration: {
|
||||||
baseURL: openAiEndpoint || void 0,
|
baseURL: openAiEndpoint || void 0,
|
||||||
|
defaultHeaders: {
|
||||||
|
'X-Title': 'Mix Space AI Client',
|
||||||
|
'HTTP-Referer': webUrl,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
maxTokens: options?.maxTokens,
|
maxTokens: options?.maxTokens,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user