Skip to content

Commit dc4de43

Browse files
authored
Merge pull request #6728 from menloresearch/fix/anthropic-model-load
Fix: Anthropic request to add models
2 parents c378d76 + 9046927 commit dc4de43

File tree

6 files changed

+100
-5
lines changed

6 files changed

+100
-5
lines changed

web-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"remark-math": "6.0.0",
8383
"sonner": "2.0.5",
8484
"tailwindcss": "4.1.4",
85-
"token.js": "npm:[email protected].27",
85+
"token.js": "npm:[email protected].29",
8686
"tw-animate-css": "1.2.8",
8787
"ulidx": "2.4.1",
8888
"unified": "11.0.5",

web-app/src/consts/providers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const predefinedProviders = [
9696
{
9797
active: true,
9898
api_key: '',
99-
base_url: 'https://api.anthropic.com',
99+
base_url: 'https://api.anthropic.com/v1',
100100
provider: 'anthropic',
101101
explore_models_url:
102102
'https://docs.anthropic.com/en/docs/about-claude/models',
@@ -127,11 +127,21 @@ export const predefinedProviders = [
127127
},
128128
],
129129
models: [],
130+
custom_header: [
131+
{
132+
header: 'anthropic-version',
133+
value: '2023-06-01'
134+
},
135+
{
136+
header: 'anthropic-dangerous-direct-browser-access',
137+
value: 'true'
138+
}
139+
]
130140
},
131141
{
132142
active: true,
133143
api_key: '',
134-
base_url: 'https://api.cohere.ai/compatibility/v1',
144+
base_url: 'https://api.cohere.ai/v1',
135145
explore_models_url: 'https://docs.cohere.com/v2/docs/models',
136146
provider: 'cohere',
137147
settings: [

web-app/src/hooks/useModelProvider.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,82 @@ export const useModelProvider = create<ModelProviderState>()(
320320
})
321321
}
322322

323+
if (version <= 3 && state?.providers) {
324+
state.providers.forEach((provider) => {
325+
// Migrate Anthropic provider base URL and add custom headers
326+
if (provider.provider === 'anthropic') {
327+
if (provider.base_url === 'https://api.anthropic.com') {
328+
provider.base_url = 'https://api.anthropic.com/v1'
329+
}
330+
331+
// Update base-url in settings
332+
if (provider.settings) {
333+
const baseUrlSetting = provider.settings.find(
334+
(s) => s.key === 'base-url'
335+
)
336+
if (
337+
baseUrlSetting?.controller_props?.value ===
338+
'https://api.anthropic.com'
339+
) {
340+
baseUrlSetting.controller_props.value =
341+
'https://api.anthropic.com/v1'
342+
}
343+
if (
344+
baseUrlSetting?.controller_props?.placeholder ===
345+
'https://api.anthropic.com'
346+
) {
347+
baseUrlSetting.controller_props.placeholder =
348+
'https://api.anthropic.com/v1'
349+
}
350+
}
351+
352+
if (!provider.custom_header) {
353+
provider.custom_header = [
354+
{
355+
header: 'anthropic-version',
356+
value: '2023-06-01',
357+
},
358+
{
359+
header: 'anthropic-dangerous-direct-browser-access',
360+
value: 'true',
361+
},
362+
]
363+
}
364+
}
365+
366+
if (provider.provider === 'cohere') {
367+
if (provider.base_url === 'https://api.cohere.ai/compatibility/v1') {
368+
provider.base_url = 'https://api.cohere.ai/v1'
369+
}
370+
371+
// Update base-url in settings
372+
if (provider.settings) {
373+
const baseUrlSetting = provider.settings.find(
374+
(s) => s.key === 'base-url'
375+
)
376+
if (
377+
baseUrlSetting?.controller_props?.value ===
378+
'https://api.cohere.ai/compatibility/v1'
379+
) {
380+
baseUrlSetting.controller_props.value =
381+
'https://api.cohere.ai/v1'
382+
}
383+
if (
384+
baseUrlSetting?.controller_props?.placeholder ===
385+
'https://api.cohere.ai/compatibility/v1'
386+
) {
387+
baseUrlSetting.controller_props.placeholder =
388+
'https://api.cohere.ai/v1'
389+
}
390+
}
391+
}
392+
393+
})
394+
}
395+
323396
return state
324397
},
325-
version: 3,
398+
version: 4,
326399
}
327400
)
328401
)

web-app/src/routes/settings/providers/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function ModelProviders() {
3939
toast.error(t('providerAlreadyExists', { name }))
4040
return
4141
}
42-
const newProvider = {
42+
const newProvider: ProviderObject = {
4343
provider: name,
4444
active: true,
4545
models: [],

web-app/src/services/providers/tauri.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ export class TauriProvidersService extends DefaultProvidersService {
151151
headers['Authorization'] = `Bearer ${provider.api_key}`
152152
}
153153

154+
if (provider.custom_header) {
155+
provider.custom_header.forEach((header) => {
156+
headers[header.header] = header.value
157+
})
158+
}
159+
154160
// Always use Tauri's fetch to avoid CORS issues
155161
const response = await fetchTauri(`${provider.base_url}/models`, {
156162
method: 'GET',

web-app/src/types/modelProviders.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type ProviderObject = {
4848
settings: ProviderSetting[]
4949
models: Model[]
5050
persist?: boolean
51+
custom_header?: ProviderCustomHeader[] | null
5152
}
5253

5354
/**
@@ -71,3 +72,8 @@ type ProxyOptions = {
7172
verifyHostSSL: boolean
7273
noProxy: string
7374
}
75+
76+
type ProviderCustomHeader = {
77+
header: string
78+
value: string
79+
}

0 commit comments

Comments
 (0)