fix ollama error (#6418)

This commit is contained in:
Dinh Long Nguyen 2025-09-11 18:38:06 +07:00 committed by GitHub
parent e709d200aa
commit db52057030
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -182,6 +182,13 @@ export const sendCompletion = async (
'X-Title': 'Jan', 'X-Title': 'Jan',
}, },
}), }),
// Add Origin header for local providers to avoid CORS issues
...((provider.base_url?.includes('localhost:') || provider.base_url?.includes('127.0.0.1:')) && {
fetch: getServiceHub().providers().fetch(),
defaultHeaders: {
'Origin': 'tauri://localhost',
},
}),
} as ExtendedConfigOptions) } as ExtendedConfigOptions)
if ( if (

View File

@ -143,6 +143,12 @@ export class TauriProvidersService extends DefaultProvidersService {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
} }
// Add Origin header for local providers to avoid CORS issues
// Some local providers (like Ollama) require an Origin header
if (provider.base_url.includes('localhost:') || provider.base_url.includes('127.0.0.1:')) {
headers['Origin'] = 'tauri://localhost'
}
// Only add authentication headers if API key is provided // Only add authentication headers if API key is provided
if (provider.api_key) { if (provider.api_key) {
headers['x-api-key'] = provider.api_key headers['x-api-key'] = provider.api_key