Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,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 #
Expand Down
19 changes: 11 additions & 8 deletions packages/data-provider/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1819,30 +1819,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',
Expand Down
4 changes: 4 additions & 0 deletions packages/data-schemas/src/app/web.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand Down Expand Up @@ -154,20 +155,23 @@ 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', () => {
const config: TCustomConfig['webSearch'] = {
searxngInstanceUrl: 'https://custom-searxng.com',
firecrawlApiUrl: 'https://custom-firecrawl.com',
jinaApiUrl: 'https://custom-jina.com',
cohereApiUrl: 'https://custom-cohere.com',
};

const result = loadWebSearchConfig(config);

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');
});
});
});
8 changes: 7 additions & 1 deletion packages/data-schemas/src/app/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
};

Expand Down Expand Up @@ -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 {
Expand All @@ -80,6 +85,7 @@ export function loadWebSearchConfig(
jinaApiKey,
jinaApiUrl,
cohereApiKey,
cohereApiUrl,
serperApiKey,
searxngApiKey,
firecrawlApiKey,
Expand Down
3 changes: 2 additions & 1 deletion packages/data-schemas/src/types/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type TWebSearchKeys =
| 'firecrawlVersion'
| 'jinaApiKey'
| 'jinaApiUrl'
| 'cohereApiKey';
| 'cohereApiKey'
| 'cohereApiUrl';

export type TWebSearchCategories =
| SearchCategories.PROVIDERS
Expand Down