Merge pull request #6728 from menloresearch/fix/anthropic-model-load
Fix: Anthropic request to add models
This commit is contained in:
parent
61c3fd4b5a
commit
4828f34fec
@ -82,7 +82,7 @@
|
||||
"remark-math": "6.0.0",
|
||||
"sonner": "2.0.5",
|
||||
"tailwindcss": "4.1.4",
|
||||
"token.js": "npm:token.js-fork@0.7.27",
|
||||
"token.js": "npm:token.js-fork@0.7.29",
|
||||
"tw-animate-css": "1.2.8",
|
||||
"ulidx": "2.4.1",
|
||||
"unified": "11.0.5",
|
||||
|
||||
@ -96,7 +96,7 @@ export const predefinedProviders = [
|
||||
{
|
||||
active: true,
|
||||
api_key: '',
|
||||
base_url: 'https://api.anthropic.com',
|
||||
base_url: 'https://api.anthropic.com/v1',
|
||||
provider: 'anthropic',
|
||||
explore_models_url:
|
||||
'https://docs.anthropic.com/en/docs/about-claude/models',
|
||||
@ -127,11 +127,21 @@ export const predefinedProviders = [
|
||||
},
|
||||
],
|
||||
models: [],
|
||||
custom_header: [
|
||||
{
|
||||
header: 'anthropic-version',
|
||||
value: '2023-06-01'
|
||||
},
|
||||
{
|
||||
header: 'anthropic-dangerous-direct-browser-access',
|
||||
value: 'true'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
active: true,
|
||||
api_key: '',
|
||||
base_url: 'https://api.cohere.ai/compatibility/v1',
|
||||
base_url: 'https://api.cohere.ai/v1',
|
||||
explore_models_url: 'https://docs.cohere.com/v2/docs/models',
|
||||
provider: 'cohere',
|
||||
settings: [
|
||||
|
||||
@ -320,9 +320,82 @@ export const useModelProvider = create<ModelProviderState>()(
|
||||
})
|
||||
}
|
||||
|
||||
if (version <= 3 && state?.providers) {
|
||||
state.providers.forEach((provider) => {
|
||||
// Migrate Anthropic provider base URL and add custom headers
|
||||
if (provider.provider === 'anthropic') {
|
||||
if (provider.base_url === 'https://api.anthropic.com') {
|
||||
provider.base_url = 'https://api.anthropic.com/v1'
|
||||
}
|
||||
|
||||
// Update base-url in settings
|
||||
if (provider.settings) {
|
||||
const baseUrlSetting = provider.settings.find(
|
||||
(s) => s.key === 'base-url'
|
||||
)
|
||||
if (
|
||||
baseUrlSetting?.controller_props?.value ===
|
||||
'https://api.anthropic.com'
|
||||
) {
|
||||
baseUrlSetting.controller_props.value =
|
||||
'https://api.anthropic.com/v1'
|
||||
}
|
||||
if (
|
||||
baseUrlSetting?.controller_props?.placeholder ===
|
||||
'https://api.anthropic.com'
|
||||
) {
|
||||
baseUrlSetting.controller_props.placeholder =
|
||||
'https://api.anthropic.com/v1'
|
||||
}
|
||||
}
|
||||
|
||||
if (!provider.custom_header) {
|
||||
provider.custom_header = [
|
||||
{
|
||||
header: 'anthropic-version',
|
||||
value: '2023-06-01',
|
||||
},
|
||||
{
|
||||
header: 'anthropic-dangerous-direct-browser-access',
|
||||
value: 'true',
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (provider.provider === 'cohere') {
|
||||
if (provider.base_url === 'https://api.cohere.ai/compatibility/v1') {
|
||||
provider.base_url = 'https://api.cohere.ai/v1'
|
||||
}
|
||||
|
||||
// Update base-url in settings
|
||||
if (provider.settings) {
|
||||
const baseUrlSetting = provider.settings.find(
|
||||
(s) => s.key === 'base-url'
|
||||
)
|
||||
if (
|
||||
baseUrlSetting?.controller_props?.value ===
|
||||
'https://api.cohere.ai/compatibility/v1'
|
||||
) {
|
||||
baseUrlSetting.controller_props.value =
|
||||
'https://api.cohere.ai/v1'
|
||||
}
|
||||
if (
|
||||
baseUrlSetting?.controller_props?.placeholder ===
|
||||
'https://api.cohere.ai/compatibility/v1'
|
||||
) {
|
||||
baseUrlSetting.controller_props.placeholder =
|
||||
'https://api.cohere.ai/v1'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
return state
|
||||
},
|
||||
version: 3,
|
||||
version: 4,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@ -39,7 +39,7 @@ function ModelProviders() {
|
||||
toast.error(t('providerAlreadyExists', { name }))
|
||||
return
|
||||
}
|
||||
const newProvider = {
|
||||
const newProvider: ProviderObject = {
|
||||
provider: name,
|
||||
active: true,
|
||||
models: [],
|
||||
|
||||
@ -151,6 +151,12 @@ export class TauriProvidersService extends DefaultProvidersService {
|
||||
headers['Authorization'] = `Bearer ${provider.api_key}`
|
||||
}
|
||||
|
||||
if (provider.custom_header) {
|
||||
provider.custom_header.forEach((header) => {
|
||||
headers[header.header] = header.value
|
||||
})
|
||||
}
|
||||
|
||||
// Always use Tauri's fetch to avoid CORS issues
|
||||
const response = await fetchTauri(`${provider.base_url}/models`, {
|
||||
method: 'GET',
|
||||
|
||||
6
web-app/src/types/modelProviders.d.ts
vendored
6
web-app/src/types/modelProviders.d.ts
vendored
@ -48,6 +48,7 @@ type ProviderObject = {
|
||||
settings: ProviderSetting[]
|
||||
models: Model[]
|
||||
persist?: boolean
|
||||
custom_header?: ProviderCustomHeader[] | null
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,3 +72,8 @@ type ProxyOptions = {
|
||||
verifyHostSSL: boolean
|
||||
noProxy: string
|
||||
}
|
||||
|
||||
type ProviderCustomHeader = {
|
||||
header: string
|
||||
value: string
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user