mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
fix: refactor provider headers logic in providerConfig (#11849)
Simplifies and centralizes header construction by merging defaultAppHeaders and extra_headers, and sets X-Api-Key for OpenAI providers. Removes redundant header assignment logic for improved maintainability.
This commit is contained in:
parent
784fdd4fed
commit
bfeef7ef91
@ -32,6 +32,7 @@ import {
|
|||||||
isSupportStreamOptionsProvider,
|
isSupportStreamOptionsProvider,
|
||||||
isVertexProvider
|
isVertexProvider
|
||||||
} from '@renderer/utils/provider'
|
} from '@renderer/utils/provider'
|
||||||
|
import { defaultAppHeaders } from '@shared/utils'
|
||||||
import { cloneDeep, isEmpty } from 'lodash'
|
import { cloneDeep, isEmpty } from 'lodash'
|
||||||
|
|
||||||
import type { AiSdkConfig } from '../types'
|
import type { AiSdkConfig } from '../types'
|
||||||
@ -197,18 +198,13 @@ export function providerToAiSdkConfig(actualProvider: Provider, model: Model): A
|
|||||||
extraOptions.mode = 'chat'
|
extraOptions.mode = 'chat'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加额外headers
|
extraOptions.headers = {
|
||||||
if (actualProvider.extra_headers) {
|
...defaultAppHeaders(),
|
||||||
extraOptions.headers = actualProvider.extra_headers
|
...actualProvider.extra_headers
|
||||||
// copy from openaiBaseClient/openaiResponseApiClient
|
}
|
||||||
if (aiSdkProviderId === 'openai') {
|
|
||||||
extraOptions.headers = {
|
if (aiSdkProviderId === 'openai') {
|
||||||
...extraOptions.headers,
|
extraOptions.headers['X-Api-Key'] = baseConfig.apiKey
|
||||||
'HTTP-Referer': 'https://cherry-ai.com',
|
|
||||||
'X-Title': 'Cherry Studio',
|
|
||||||
'X-Api-Key': baseConfig.apiKey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// azure
|
// azure
|
||||||
// https://learn.microsoft.com/en-us/azure/ai-foundry/openai/latest
|
// https://learn.microsoft.com/en-us/azure/ai-foundry/openai/latest
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user