diff --git a/.env.example b/.env.example index db09bb471f..944bfd5c9b 100644 --- a/.env.example +++ b/.env.example @@ -838,6 +838,8 @@ OPENWEATHER_API_KEY= # JINA_API_KEY=your_jina_api_key # or # COHERE_API_KEY=your_cohere_api_key +# Optional: Custom Cohere API URL (defaults to https://api.cohere.ai/v1) +# COHERE_API_URL=http://litellm:8000/v1 #======================# # MCP Configuration # diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index ca40ec2c8c..c018a6fc20 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -1959,30 +1959,33 @@ export enum ForkOptions { } /** - * Enum for Cohere related constants + * Cohere related constants */ -export enum CohereConstants { +export const CohereConstants = { /** * Cohere API Endpoint, for special handling + * Uses COHERE_API_URL environment variable if set, otherwise defaults to official API */ - API_URL = 'https://api.cohere.ai/v1', + get API_URL(): string { + return process.env.COHERE_API_URL || 'https://api.cohere.ai/v1'; + }, /** * Role for "USER" messages */ - ROLE_USER = 'USER', + ROLE_USER: 'USER' as const, /** * Role for "SYSTEM" messages */ - ROLE_SYSTEM = 'SYSTEM', + ROLE_SYSTEM: 'SYSTEM' as const, /** * Role for "CHATBOT" messages */ - ROLE_CHATBOT = 'CHATBOT', + ROLE_CHATBOT: 'CHATBOT' as const, /** * Title message as required by Cohere */ - TITLE_MESSAGE = 'TITLE:', -} + TITLE_MESSAGE: 'TITLE:' as const, +} as const; export enum SystemCategories { ALL = 'sys__all__sys', diff --git a/packages/data-schemas/src/app/web.spec.ts b/packages/data-schemas/src/app/web.spec.ts index 787d7809a3..fcf6b28b0f 100644 --- a/packages/data-schemas/src/app/web.spec.ts +++ b/packages/data-schemas/src/app/web.spec.ts @@ -55,6 +55,7 @@ describe('loadWebSearchConfig', () => { jinaApiKey: '${JINA_API_KEY}', jinaApiUrl: '${JINA_API_URL}', cohereApiKey: '${COHERE_API_KEY}', + cohereApiUrl: '${COHERE_API_URL}', safeSearch: SafeSearchTypes.MODERATE, }); }); @@ -154,6 +155,7 @@ describe('loadWebSearchConfig', () => { expect(result?.searxngInstanceUrl).toBe('${SEARXNG_INSTANCE_URL}'); expect(result?.firecrawlApiUrl).toBe('${FIRECRAWL_API_URL}'); expect(result?.jinaApiUrl).toBe('${JINA_API_URL}'); + expect(result?.cohereApiUrl).toBe('${COHERE_API_URL}'); }); it('should preserve custom URLs', () => { @@ -161,6 +163,7 @@ describe('loadWebSearchConfig', () => { searxngInstanceUrl: 'https://custom-searxng.com', firecrawlApiUrl: 'https://custom-firecrawl.com', jinaApiUrl: 'https://custom-jina.com', + cohereApiUrl: 'https://custom-cohere.com', }; const result = loadWebSearchConfig(config); @@ -168,6 +171,7 @@ describe('loadWebSearchConfig', () => { expect(result?.searxngInstanceUrl).toBe('https://custom-searxng.com'); expect(result?.firecrawlApiUrl).toBe('https://custom-firecrawl.com'); expect(result?.jinaApiUrl).toBe('https://custom-jina.com'); + expect(result?.cohereApiUrl).toBe('https://custom-cohere.com'); }); }); }); diff --git a/packages/data-schemas/src/app/web.ts b/packages/data-schemas/src/app/web.ts index a61e1f1611..c11cc5e71e 100644 --- a/packages/data-schemas/src/app/web.ts +++ b/packages/data-schemas/src/app/web.ts @@ -30,7 +30,11 @@ export const webSearchAuth = { /** Optional (0) */ jinaApiUrl: 0 as const, }, - cohere: { cohereApiKey: 1 as const }, + cohere: { + cohereApiKey: 1 as const, + /** Optional (0) */ + cohereApiUrl: 0 as const, + }, }, }; @@ -72,6 +76,7 @@ export function loadWebSearchConfig( const jinaApiKey = config?.jinaApiKey ?? '${JINA_API_KEY}'; const jinaApiUrl = config?.jinaApiUrl ?? '${JINA_API_URL}'; const cohereApiKey = config?.cohereApiKey ?? '${COHERE_API_KEY}'; + const cohereApiUrl = config?.cohereApiUrl ?? '${COHERE_API_URL}'; const safeSearch = config?.safeSearch ?? SafeSearchTypes.MODERATE; return { @@ -80,6 +85,7 @@ export function loadWebSearchConfig( jinaApiKey, jinaApiUrl, cohereApiKey, + cohereApiUrl, serperApiKey, searxngApiKey, firecrawlApiKey, diff --git a/packages/data-schemas/src/types/web.ts b/packages/data-schemas/src/types/web.ts index a9cc1f0cc6..7896a00dc8 100644 --- a/packages/data-schemas/src/types/web.ts +++ b/packages/data-schemas/src/types/web.ts @@ -9,7 +9,8 @@ export type TWebSearchKeys = | 'firecrawlVersion' | 'jinaApiKey' | 'jinaApiUrl' - | 'cohereApiKey'; + | 'cohereApiKey' + | 'cohereApiUrl'; export type TWebSearchCategories = | SearchCategories.PROVIDERS