From 7c448235536a448aa2a880d57b9ff3ade3b4ce58 Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 17 Mar 2025 21:03:39 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20Cohere=20provider?= =?UTF-8?q?=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ Dockerfile.database | 2 ++ Dockerfile.pglite | 2 ++ .../settings/llm/ProviderList/providers.tsx | 2 ++ src/config/aiModels/cohere.ts | 23 +++++++++++++++++++ src/config/aiModels/index.ts | 3 +++ src/config/llm.ts | 6 +++++ src/config/modelProviders/cohere.ts | 18 +++++++++++++++ src/config/modelProviders/index.ts | 4 ++++ src/libs/agent-runtime/cohere/index.ts | 10 ++++++++ src/libs/agent-runtime/runtimeMap.ts | 2 ++ src/libs/agent-runtime/types/type.ts | 1 + src/types/user/settings/keyVaults.ts | 1 + 13 files changed, 76 insertions(+) create mode 100644 src/config/aiModels/cohere.ts create mode 100644 src/config/modelProviders/cohere.ts create mode 100644 src/libs/agent-runtime/cohere/index.ts diff --git a/Dockerfile b/Dockerfile index 272d53d49a86d..433d561ef64ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -157,6 +157,8 @@ ENV \ BAICHUAN_API_KEY="" BAICHUAN_MODEL_LIST="" \ # Cloudflare CLOUDFLARE_API_KEY="" CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID="" CLOUDFLARE_MODEL_LIST="" \ + # Cohere + COHERE_API_KEY="" COHERE_MODEL_LIST="" \ # DeepSeek DEEPSEEK_API_KEY="" DEEPSEEK_MODEL_LIST="" \ # Fireworks AI diff --git a/Dockerfile.database b/Dockerfile.database index abd9108d4462f..14da552516230 100644 --- a/Dockerfile.database +++ b/Dockerfile.database @@ -200,6 +200,8 @@ ENV \ BAICHUAN_API_KEY="" BAICHUAN_MODEL_LIST="" \ # Cloudflare CLOUDFLARE_API_KEY="" CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID="" CLOUDFLARE_MODEL_LIST="" \ + # Cohere + COHERE_API_KEY="" COHERE_MODEL_LIST="" \ # DeepSeek DEEPSEEK_API_KEY="" DEEPSEEK_MODEL_LIST="" \ # Fireworks AI diff --git a/Dockerfile.pglite b/Dockerfile.pglite index d694cea6eaac7..398509eb05c37 100644 --- a/Dockerfile.pglite +++ b/Dockerfile.pglite @@ -158,6 +158,8 @@ ENV \ BAICHUAN_API_KEY="" BAICHUAN_MODEL_LIST="" \ # Cloudflare CLOUDFLARE_API_KEY="" CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID="" CLOUDFLARE_MODEL_LIST="" \ + # Cohere + COHERE_API_KEY="" COHERE_MODEL_LIST="" \ # DeepSeek DEEPSEEK_API_KEY="" DEEPSEEK_MODEL_LIST="" \ # Fireworks AI diff --git a/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx b/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx index 6d503a1aae6d6..05176e79fcddc 100644 --- a/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx +++ b/src/app/[variants]/(main)/settings/llm/ProviderList/providers.tsx @@ -5,6 +5,7 @@ import { Ai360ProviderCard, AnthropicProviderCard, BaichuanProviderCard, + CohereProviderCard, DeepSeekProviderCard, FireworksAIProviderCard, GiteeAIProviderCard, @@ -82,6 +83,7 @@ export const useProviderList = (): ProviderItem[] => { XAIProviderCard, JinaProviderCard, SambaNovaProviderCard, + CohereProviderCard, QwenProviderCard, WenxinProviderCard, HunyuanProviderCard, diff --git a/src/config/aiModels/cohere.ts b/src/config/aiModels/cohere.ts new file mode 100644 index 0000000000000..795358d63922d --- /dev/null +++ b/src/config/aiModels/cohere.ts @@ -0,0 +1,23 @@ +import { AIChatModelCard } from '@/types/aiModel'; + +const cohereChatModels: AIChatModelCard[] = [ + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 16_000, + description: '', + displayName: 'Command', + enabled: true, + id: 'command', + pricing: { + input: 0.6, + output: 1.2 + }, + type: 'chat' + }, +] + +export const allModels = [...cohereChatModels]; + +export default allModels; diff --git a/src/config/aiModels/index.ts b/src/config/aiModels/index.ts index 7cd0ed49c669d..da4936415d762 100644 --- a/src/config/aiModels/index.ts +++ b/src/config/aiModels/index.ts @@ -8,6 +8,7 @@ import { default as azureai } from './azureai'; import { default as baichuan } from './baichuan'; import { default as bedrock } from './bedrock'; import { default as cloudflare } from './cloudflare'; +import { default as cohere } from './cohere'; import { default as deepseek } from './deepseek'; import { default as doubao } from './doubao'; import { default as fireworksai } from './fireworksai'; @@ -77,6 +78,7 @@ export const LOBE_DEFAULT_MODEL_LIST = buildDefaultModelList({ baichuan, bedrock, cloudflare, + cohere, deepseek, doubao, fireworksai, @@ -127,6 +129,7 @@ export { default as azureai } from './azureai'; export { default as baichuan } from './baichuan'; export { default as bedrock } from './bedrock'; export { default as cloudflare } from './cloudflare'; +export { default as cohere } from './cohere'; export { default as deepseek } from './deepseek'; export { default as doubao } from './doubao'; export { default as fireworksai } from './fireworksai'; diff --git a/src/config/llm.ts b/src/config/llm.ts index c4e1411c454a5..f0637da3d8ba9 100644 --- a/src/config/llm.ts +++ b/src/config/llm.ts @@ -150,6 +150,9 @@ export const getLLMConfig = () => { ENABLED_PPIO: z.boolean(), PPIO_API_KEY: z.string().optional(), + + ENABLED_COHERE: z.boolean(), + COHERE_API_KEY: z.string().optional(), }, runtimeEnv: { API_KEY_SELECT_MODE: process.env.API_KEY_SELECT_MODE, @@ -298,6 +301,9 @@ export const getLLMConfig = () => { ENABLED_PPIO: !!process.env.PPIO_API_KEY, PPIO_API_KEY: process.env.PPIO_API_KEY, + + ENABLED_COHERE: !!process.env.COHERE_API_KEY, + COHERE_API_KEY: process.env.COHERE_API_KEY, }, }); }; diff --git a/src/config/modelProviders/cohere.ts b/src/config/modelProviders/cohere.ts new file mode 100644 index 0000000000000..691db9f964c67 --- /dev/null +++ b/src/config/modelProviders/cohere.ts @@ -0,0 +1,18 @@ +import { ModelProviderCard } from '@/types/llm'; + +const Cohere: ModelProviderCard = { + chatModels: [], + checkModel: 'command', + description: 'Cohere', + //disableBrowserRequest: true, + id: 'cohere', + modelsUrl: 'https://docs.cohere.com/v2/docs/models', + name: 'Cohere', + settings: { + //disableBrowserRequest: true, + sdkType: 'openai', + }, + url: 'https://cohere.com', +}; + +export default Cohere; diff --git a/src/config/modelProviders/index.ts b/src/config/modelProviders/index.ts index 84b8d701264e2..f8271ecb7a21d 100644 --- a/src/config/modelProviders/index.ts +++ b/src/config/modelProviders/index.ts @@ -8,6 +8,7 @@ import AzureAIProvider from './azureai'; import BaichuanProvider from './baichuan'; import BedrockProvider from './bedrock'; import CloudflareProvider from './cloudflare'; +import CohereProvider from './cohere'; import DeepSeekProvider from './deepseek'; import DoubaoProvider from './doubao'; import FireworksAIProvider from './fireworksai'; @@ -75,6 +76,7 @@ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [ XAIProvider.chatModels, JinaProvider.chatModels, SambaNovaProvider.chatModels, + CohereProvider.chatModels, ZeroOneProvider.chatModels, StepfunProvider.chatModels, NovitaProvider.chatModels, @@ -124,6 +126,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [ XAIProvider, JinaProvider, SambaNovaProvider, + CohereProvider, QwenProvider, WenxinProvider, TencentcloudProvider, @@ -164,6 +167,7 @@ export { default as AzureAIProviderCard } from './azureai'; export { default as BaichuanProviderCard } from './baichuan'; export { default as BedrockProviderCard } from './bedrock'; export { default as CloudflareProviderCard } from './cloudflare'; +export { default as CohereProviderCard } from './cohere'; export { default as DeepSeekProviderCard } from './deepseek'; export { default as DoubaoProviderCard } from './doubao'; export { default as FireworksAIProviderCard } from './fireworksai'; diff --git a/src/libs/agent-runtime/cohere/index.ts b/src/libs/agent-runtime/cohere/index.ts new file mode 100644 index 0000000000000..dfac2a7d739f4 --- /dev/null +++ b/src/libs/agent-runtime/cohere/index.ts @@ -0,0 +1,10 @@ +import { ModelProvider } from '../types'; +import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory'; + +export const LobeCohereAI = LobeOpenAICompatibleFactory({ + baseURL: 'https://api.cohere.ai/compatibility/v1', + debug: { + chatCompletion: () => process.env.DEBUG_COHERE_CHAT_COMPLETION === '1', + }, + provider: ModelProvider.Cohere, +}); diff --git a/src/libs/agent-runtime/runtimeMap.ts b/src/libs/agent-runtime/runtimeMap.ts index fbe1d080070cb..e5d2b55192bbd 100644 --- a/src/libs/agent-runtime/runtimeMap.ts +++ b/src/libs/agent-runtime/runtimeMap.ts @@ -6,6 +6,7 @@ import { LobeAzureAI } from './azureai'; import { LobeBaichuanAI } from './baichuan'; import LobeBedrockAI from './bedrock'; import { LobeCloudflareAI } from './cloudflare'; +import { LobeCohereAI } from './cohere'; import { LobeDeepSeekAI } from './deepseek'; import { LobeFireworksAI } from './fireworksai'; import { LobeGiteeAI } from './giteeai'; @@ -54,6 +55,7 @@ export const providerRuntimeMap = { baichuan: LobeBaichuanAI, bedrock: LobeBedrockAI, cloudflare: LobeCloudflareAI, + cohere: LobeCohereAI, deepseek: LobeDeepSeekAI, doubao: LobeVolcengineAI, fireworksai: LobeFireworksAI, diff --git a/src/libs/agent-runtime/types/type.ts b/src/libs/agent-runtime/types/type.ts index 80ca857f49f29..c64a002e1677f 100644 --- a/src/libs/agent-runtime/types/type.ts +++ b/src/libs/agent-runtime/types/type.ts @@ -30,6 +30,7 @@ export enum ModelProvider { Baichuan = 'baichuan', Bedrock = 'bedrock', Cloudflare = 'cloudflare', + Cohere = 'cohere', DeepSeek = 'deepseek', /** * @deprecated diff --git a/src/types/user/settings/keyVaults.ts b/src/types/user/settings/keyVaults.ts index bf0abcb21fe7f..2bac7c43c5130 100644 --- a/src/types/user/settings/keyVaults.ts +++ b/src/types/user/settings/keyVaults.ts @@ -41,6 +41,7 @@ export interface UserKeyVaults extends SearchEngineKeyVaults { baichuan?: OpenAICompatibleKeyVault; bedrock?: AWSBedrockKeyVault; cloudflare?: CloudflareKeyVault; + cohere?: OpenAICompatibleKeyVault; deepseek?: OpenAICompatibleKeyVault; doubao?: OpenAICompatibleKeyVault; fireworksai?: OpenAICompatibleKeyVault; From 22ec8cd54b1daa7d61ad021e76e491605471ce9d Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 17 Mar 2025 22:07:33 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=92=84=20style:=20update=20cohere=20m?= =?UTF-8?q?odel=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/aiModels/cohere.ts | 222 ++++++++++++++++++++++++- src/config/modelProviders/cohere.ts | 5 +- src/libs/agent-runtime/cohere/index.ts | 38 +++++ 3 files changed, 260 insertions(+), 5 deletions(-) diff --git a/src/config/aiModels/cohere.ts b/src/config/aiModels/cohere.ts index 795358d63922d..8699237bb4b80 100644 --- a/src/config/aiModels/cohere.ts +++ b/src/config/aiModels/cohere.ts @@ -5,14 +5,228 @@ const cohereChatModels: AIChatModelCard[] = [ abilities: { functionCall: true, }, - contextWindowTokens: 16_000, - description: '', + contextWindowTokens: 256_000, + description: 'Command A is our most performant model to date, excelling at tool use, agents, retrieval augmented generation (RAG), and multilingual use cases. Command A has a context length of 256K, only requires two GPUs to run, and has 150% higher throughput compared to Command R+ 08-2024.', + displayName: 'Command A', + enabled: true, + id: 'command-a-03-2025', + maxOutput: 8000, + pricing: { + input: 2.5, + output: 10 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 128_000, + description: 'command-r-plus is an alias for command-r-plus-04-2024, so if you use command-r-plus in the API, that’s the model you’re pointing to.', + displayName: 'Command R+', + enabled: true, + id: 'command-r-plus', + maxOutput: 4000, + pricing: { + input: 2.5, + output: 10 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 128_000, + description: 'Command R+ is an instruction-following conversational model that performs language tasks at a higher quality, more reliably, and with a longer context than previous models. It is best suited for complex RAG workflows and multi-step tool use.', + displayName: 'Command R+ 04-2024', + id: 'command-r-plus-04-2024', + maxOutput: 4000, + pricing: { + input: 3, + output: 15 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 128_000, + description: 'command-r is an alias for command-r-03-2024, so if you use command-r in the API, that’s the model you’re pointing to.', + displayName: 'Command R', + enabled: true, + id: 'command-r', + maxOutput: 4000, + pricing: { + input: 0.15, + output: 0.6 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 128_000, + description: 'command-r-08-2024 is an update of the Command R model, delivered in August 2024.', + displayName: 'Command R 08-2024', + id: 'command-r-08-2024', + maxOutput: 4000, + pricing: { + input: 0.15, + output: 0.6 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 128_000, + description: 'Command R is an instruction-following conversational model that performs language tasks at a higher quality, more reliably, and with a longer context than previous models. It can be used for complex workflows like code generation, retrieval augmented generation (RAG), tool use, and agents.', + displayName: 'Command R 03-2024', + id: 'command-r-03-2024', + maxOutput: 4000, + pricing: { + input: 0.5, + output: 1.5 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 128_000, + description: 'command-r7b-12-2024 is a small, fast update delivered in December 2024. It excels at RAG, tool use, agents, and similar tasks requiring complex reasoning and multiple steps.', + displayName: 'Command R7B 12-2024', + enabled: true, + id: 'command-r7b-12-2024', + maxOutput: 4000, + pricing: { + input: 0.0375, + output: 0.15 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 4000, + description: 'An instruction-following conversational model that performs language tasks with high quality, more reliably and with a longer context than our base generative models.', displayName: 'Command', enabled: true, id: 'command', + maxOutput: 4000, + pricing: { + input: 1, + output: 2 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 128_000, + description: 'To reduce the time between major releases, we put out nightly versions of command models. For command, that is command-nightly. Be advised that command-nightly is the latest, most experimental, and (possibly) unstable version of its default counterpart. Nightly releases are updated regularly, without warning, and are not recommended for production use.', + displayName: 'Command Nightly', + id: 'command-nightly', + maxOutput: 4000, + pricing: { + input: 1, + output: 2 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 4000, + description: 'A smaller, faster version of command. Almost as capable, but a lot faster.', + displayName: 'Command Light', + enabled: true, + id: 'command-light', + maxOutput: 4000, + pricing: { + input: 0.3, + output: 0.6 + }, + type: 'chat' + }, + { + abilities: { + functionCall: true, + }, + contextWindowTokens: 4000, + description: 'To reduce the time between major releases, we put out nightly versions of command models. For command-light, that is command-light-nightly. Be advised that command-light-nightly is the latest, most experimental, and (possibly) unstable version of its default counterpart. Nightly releases are updated regularly, without warning, and are not recommended for production use.', + displayName: 'Command Light Nightly', + id: 'command-light-nightly', + maxOutput: 4000, + pricing: { + input: 0.3, + output: 0.6 + }, + type: 'chat' + }, + { + contextWindowTokens: 128_000, + description: 'Aya Expanse is a highly performant 32B multilingual model, designed to rival monolingual performance through innovations in instruction tuning with data arbitrage, preference training, and model merging. Serves 23 languages.', + displayName: 'Aya Expanse 32B', + enabled: true, + id: 'c4ai-aya-expanse-32b', + maxOutput: 4000, + pricing: { + input: 0.5, + output: 1.5 + }, + type: 'chat' + }, + { + contextWindowTokens: 8000, + description: 'Aya Expanse is a highly performant 8B multilingual model, designed to rival monolingual performance through innovations in instruction tuning with data arbitrage, preference training, and model merging. Serves 23 languages.', + displayName: 'Aya Expanse 8B', + enabled: true, + id: 'c4ai-aya-expanse-8b', + maxOutput: 4000, + pricing: { + input: 0.5, + output: 1.5 + }, + type: 'chat' + }, + { + abilities: { + vision: true, + }, + contextWindowTokens: 16_000, + description: 'Aya Vision is a state-of-the-art multimodal model excelling at a variety of critical benchmarks for language, text, and image capabilities. Serves 23 languages. This 32 billion parameter variant is focused on state-of-art multilingual performance.', + displayName: 'Aya Vision 32B', + enabled: true, + id: 'c4ai-aya-vision-32b', + maxOutput: 4000, + pricing: { + input: 0.5, + output: 1.5 + }, + type: 'chat' + }, + { + abilities: { + vision: true, + }, + contextWindowTokens: 16_000, + description: 'Aya Vision is a state-of-the-art multimodal model excelling at a variety of critical benchmarks for language, text, and image capabilities. This 8 billion parameter variant is focused on low latency and best-in-class performance.', + displayName: 'Aya Vision 8B', + enabled: true, + id: 'c4ai-aya-vision-8b', + maxOutput: 4000, pricing: { - input: 0.6, - output: 1.2 + input: 0.5, + output: 1.5 }, type: 'chat' }, diff --git a/src/config/modelProviders/cohere.ts b/src/config/modelProviders/cohere.ts index 691db9f964c67..03856b349f339 100644 --- a/src/config/modelProviders/cohere.ts +++ b/src/config/modelProviders/cohere.ts @@ -2,7 +2,7 @@ import { ModelProviderCard } from '@/types/llm'; const Cohere: ModelProviderCard = { chatModels: [], - checkModel: 'command', + checkModel: 'command-r7b-12-2024', description: 'Cohere', //disableBrowserRequest: true, id: 'cohere', @@ -10,6 +10,9 @@ const Cohere: ModelProviderCard = { name: 'Cohere', settings: { //disableBrowserRequest: true, + proxyUrl: { + placeholder: 'https://api.cohere.ai/compatibility/v1', + }, sdkType: 'openai', }, url: 'https://cohere.com', diff --git a/src/libs/agent-runtime/cohere/index.ts b/src/libs/agent-runtime/cohere/index.ts index dfac2a7d739f4..49aee416bdc7c 100644 --- a/src/libs/agent-runtime/cohere/index.ts +++ b/src/libs/agent-runtime/cohere/index.ts @@ -1,10 +1,48 @@ import { ModelProvider } from '../types'; import { LobeOpenAICompatibleFactory } from '../utils/openaiCompatibleFactory'; +import type { ChatModelCard } from '@/types/llm'; + +export interface CohereModelCard { + context_length: number; + features: string[]; + name: string; + supports_vision: boolean; +} + export const LobeCohereAI = LobeOpenAICompatibleFactory({ baseURL: 'https://api.cohere.ai/compatibility/v1', debug: { chatCompletion: () => process.env.DEBUG_COHERE_CHAT_COMPLETION === '1', }, + models: async ({ client }) => { + const { LOBE_DEFAULT_MODEL_LIST } = await import('@/config/aiModels'); + + client.baseURL = 'https://api.cohere.com/v1'; + + const modelsPage = await client.models.list() as any; + const modelList: CohereModelCard[] = modelsPage.models; + + return modelList + .map((model) => { + const knownModel = LOBE_DEFAULT_MODEL_LIST.find((m) => model.name.toLowerCase() === m.id.toLowerCase()); + + return { + contextWindowTokens: model.context_length, + displayName: knownModel?.displayName ?? undefined, + enabled: knownModel?.enabled || false, + functionCall: + model.features.includes("tools") + || knownModel?.abilities?.functionCall + || false, + id: model.name, + vision: + model.supports_vision + || knownModel?.abilities?.vision + || false, + }; + }) + .filter(Boolean) as ChatModelCard[]; + }, provider: ModelProvider.Cohere, }); From bed01e3aa428b876d00a4bb7778df4194686c774 Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 17 Mar 2025 22:55:08 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20cohere=20callin?= =?UTF-8?q?g,=20exclude=20user=20and=20stream=5Foptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/agent-runtime/cohere/index.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/libs/agent-runtime/cohere/index.ts b/src/libs/agent-runtime/cohere/index.ts index 49aee416bdc7c..9747084abdd8f 100644 --- a/src/libs/agent-runtime/cohere/index.ts +++ b/src/libs/agent-runtime/cohere/index.ts @@ -12,6 +12,21 @@ export interface CohereModelCard { export const LobeCohereAI = LobeOpenAICompatibleFactory({ baseURL: 'https://api.cohere.ai/compatibility/v1', + chatCompletion: { + // https://docs.cohere.com/v2/docs/compatibility-api#unsupported-parameters + excludeUsage: true, + handlePayload: (payload) => { + const { frequency_penalty, presence_penalty, top_p, ...rest } = payload; + + return { + ...rest, + frequency_penalty: frequency_penalty !== undefined ? Math.max(0, Math.min(1, frequency_penalty / 2)) : undefined, + presence_penalty: presence_penalty !== undefined ? Math.max(0, Math.min(1, presence_penalty / 2)) : undefined, + top_p: top_p !== undefined ? Math.max(0.01, Math.min(0.99, top_p)) : undefined, + } as any; + }, + noUserId: true, + }, debug: { chatCompletion: () => process.env.DEBUG_COHERE_CHAT_COMPLETION === '1', }, @@ -21,7 +36,7 @@ export const LobeCohereAI = LobeOpenAICompatibleFactory({ client.baseURL = 'https://api.cohere.com/v1'; const modelsPage = await client.models.list() as any; - const modelList: CohereModelCard[] = modelsPage.models; + const modelList: CohereModelCard[] = modelsPage.body.models; return modelList .map((model) => { From c3ba74cb839f6858f9ee3d20b875a4a65d6ec63f Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 17 Mar 2025 23:20:19 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=92=84=20style:=20update=20model=20de?= =?UTF-8?q?scription?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- Dockerfile.database | 2 +- Dockerfile.pglite | 2 +- src/config/aiModels/cohere.ts | 54 ++++++++++++++++------------- src/config/modelProviders/cohere.ts | 2 -- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 433d561ef64ff..a04fe07ef5193 100644 --- a/Dockerfile +++ b/Dockerfile @@ -158,7 +158,7 @@ ENV \ # Cloudflare CLOUDFLARE_API_KEY="" CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID="" CLOUDFLARE_MODEL_LIST="" \ # Cohere - COHERE_API_KEY="" COHERE_MODEL_LIST="" \ + COHERE_API_KEY="" COHERE_MODEL_LIST="" COHERE_PROXY_URL="" \ # DeepSeek DEEPSEEK_API_KEY="" DEEPSEEK_MODEL_LIST="" \ # Fireworks AI diff --git a/Dockerfile.database b/Dockerfile.database index 14da552516230..1df8987b5fa18 100644 --- a/Dockerfile.database +++ b/Dockerfile.database @@ -201,7 +201,7 @@ ENV \ # Cloudflare CLOUDFLARE_API_KEY="" CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID="" CLOUDFLARE_MODEL_LIST="" \ # Cohere - COHERE_API_KEY="" COHERE_MODEL_LIST="" \ + COHERE_API_KEY="" COHERE_MODEL_LIST="" COHERE_PROXY_URL="" \ # DeepSeek DEEPSEEK_API_KEY="" DEEPSEEK_MODEL_LIST="" \ # Fireworks AI diff --git a/Dockerfile.pglite b/Dockerfile.pglite index 398509eb05c37..c0309ca8947d1 100644 --- a/Dockerfile.pglite +++ b/Dockerfile.pglite @@ -159,7 +159,7 @@ ENV \ # Cloudflare CLOUDFLARE_API_KEY="" CLOUDFLARE_BASE_URL_OR_ACCOUNT_ID="" CLOUDFLARE_MODEL_LIST="" \ # Cohere - COHERE_API_KEY="" COHERE_MODEL_LIST="" \ + COHERE_API_KEY="" COHERE_MODEL_LIST="" COHERE_PROXY_URL="" \ # DeepSeek DEEPSEEK_API_KEY="" DEEPSEEK_MODEL_LIST="" \ # Fireworks AI diff --git a/src/config/aiModels/cohere.ts b/src/config/aiModels/cohere.ts index 8699237bb4b80..be35991620fd6 100644 --- a/src/config/aiModels/cohere.ts +++ b/src/config/aiModels/cohere.ts @@ -6,7 +6,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 256_000, - description: 'Command A is our most performant model to date, excelling at tool use, agents, retrieval augmented generation (RAG), and multilingual use cases. Command A has a context length of 256K, only requires two GPUs to run, and has 150% higher throughput compared to Command R+ 08-2024.', + description: + 'Command A 是我们迄今为止性能最强的模型,在工具使用、代理、检索增强生成(RAG)和多语言应用场景方面表现出色。Command A 具有 256K 的上下文长度,仅需两块 GPU 即可运行,并且相比于 Command R+ 08-2024,吞吐量提高了 150%。', displayName: 'Command A', enabled: true, id: 'command-a-03-2025', @@ -22,7 +23,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 128_000, - description: 'command-r-plus is an alias for command-r-plus-04-2024, so if you use command-r-plus in the API, that’s the model you’re pointing to.', + description: + 'command-r-plus 是 command-r-plus-04-2024 的别名,因此如果您在 API 中使用 command-r-plus,实际上指向的就是该模型。', displayName: 'Command R+', enabled: true, id: 'command-r-plus', @@ -38,7 +40,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 128_000, - description: 'Command R+ is an instruction-following conversational model that performs language tasks at a higher quality, more reliably, and with a longer context than previous models. It is best suited for complex RAG workflows and multi-step tool use.', + description: + 'Command R+ 是一个遵循指令的对话模型,在语言任务方面表现出更高的质量、更可靠,并且相比以往模型具有更长的上下文长度。它最适用于复杂的 RAG 工作流和多步工具使用。', displayName: 'Command R+ 04-2024', id: 'command-r-plus-04-2024', maxOutput: 4000, @@ -53,7 +56,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 128_000, - description: 'command-r is an alias for command-r-03-2024, so if you use command-r in the API, that’s the model you’re pointing to.', + description: + 'command-r 是 command-c-03-2024 的别名,因此如果您在 API 中使用 command-r,实际上指向的就是该模型。', displayName: 'Command R', enabled: true, id: 'command-r', @@ -69,7 +73,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 128_000, - description: 'command-r-08-2024 is an update of the Command R model, delivered in August 2024.', + description: + 'command-r-08-2024 是 Command R 模型的更新版本,于 2024 年 8 月发布。', displayName: 'Command R 08-2024', id: 'command-r-08-2024', maxOutput: 4000, @@ -84,7 +89,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 128_000, - description: 'Command R is an instruction-following conversational model that performs language tasks at a higher quality, more reliably, and with a longer context than previous models. It can be used for complex workflows like code generation, retrieval augmented generation (RAG), tool use, and agents.', + description: + 'Command R 是一个遵循指令的对话模型,在语言任务方面表现出更高的质量、更可靠,并且相比以往模型具有更长的上下文长度。它可用于复杂的工作流程,如代码生成、检索增强生成(RAG)、工具使用和代理。', displayName: 'Command R 03-2024', id: 'command-r-03-2024', maxOutput: 4000, @@ -99,7 +105,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 128_000, - description: 'command-r7b-12-2024 is a small, fast update delivered in December 2024. It excels at RAG, tool use, agents, and similar tasks requiring complex reasoning and multiple steps.', + description: + 'command-r7b-12-2024 是一个小型且高效的更新版本,于 2024 年 12 月发布。它在 RAG、工具使用、代理等需要复杂推理和多步处理的任务中表现出色。', displayName: 'Command R7B 12-2024', enabled: true, id: 'command-r7b-12-2024', @@ -111,11 +118,9 @@ const cohereChatModels: AIChatModelCard[] = [ type: 'chat' }, { - abilities: { - functionCall: true, - }, contextWindowTokens: 4000, - description: 'An instruction-following conversational model that performs language tasks with high quality, more reliably and with a longer context than our base generative models.', + description: + '一个遵循指令的对话模型,在语言任务中表现出高质量、更可靠,并且相比我们的基础生成模型具有更长的上下文长度。', displayName: 'Command', enabled: true, id: 'command', @@ -131,7 +136,8 @@ const cohereChatModels: AIChatModelCard[] = [ functionCall: true, }, contextWindowTokens: 128_000, - description: 'To reduce the time between major releases, we put out nightly versions of command models. For command, that is command-nightly. Be advised that command-nightly is the latest, most experimental, and (possibly) unstable version of its default counterpart. Nightly releases are updated regularly, without warning, and are not recommended for production use.', + description: + '为了缩短主要版本发布之间的时间间隔,我们推出了 Command 模型的每夜版本。对于 Command 系列,这一版本称为 command-cightly。请注意,command-nightly 是最新、最具实验性且(可能)不稳定的版本。每夜版本会定期更新,且不会提前通知,因此不建议在生产环境中使用。', displayName: 'Command Nightly', id: 'command-nightly', maxOutput: 4000, @@ -142,11 +148,9 @@ const cohereChatModels: AIChatModelCard[] = [ type: 'chat' }, { - abilities: { - functionCall: true, - }, contextWindowTokens: 4000, - description: 'A smaller, faster version of command. Almost as capable, but a lot faster.', + description: + '一个更小、更快的 Command 版本,几乎同样强大,但速度更快。', displayName: 'Command Light', enabled: true, id: 'command-light', @@ -158,11 +162,9 @@ const cohereChatModels: AIChatModelCard[] = [ type: 'chat' }, { - abilities: { - functionCall: true, - }, contextWindowTokens: 4000, - description: 'To reduce the time between major releases, we put out nightly versions of command models. For command-light, that is command-light-nightly. Be advised that command-light-nightly is the latest, most experimental, and (possibly) unstable version of its default counterpart. Nightly releases are updated regularly, without warning, and are not recommended for production use.', + description: + '为了缩短主要版本发布之间的时间间隔,我们推出了 Command 模型的每夜版本。对于 command-light 系列,这一版本称为 command-light-nightly。请注意,command-light-nightly 是最新、最具实验性且(可能)不稳定的版本。每夜版本会定期更新,且不会提前通知,因此不建议在生产环境中使用。', displayName: 'Command Light Nightly', id: 'command-light-nightly', maxOutput: 4000, @@ -174,7 +176,8 @@ const cohereChatModels: AIChatModelCard[] = [ }, { contextWindowTokens: 128_000, - description: 'Aya Expanse is a highly performant 32B multilingual model, designed to rival monolingual performance through innovations in instruction tuning with data arbitrage, preference training, and model merging. Serves 23 languages.', + description: + 'Aya Expanse 是一款高性能的 32B 多语言模型,旨在通过指令调优、数据套利、偏好训练和模型合并的创新,挑战单语言模型的表现。它支持 23 种语言。', displayName: 'Aya Expanse 32B', enabled: true, id: 'c4ai-aya-expanse-32b', @@ -187,7 +190,8 @@ const cohereChatModels: AIChatModelCard[] = [ }, { contextWindowTokens: 8000, - description: 'Aya Expanse is a highly performant 8B multilingual model, designed to rival monolingual performance through innovations in instruction tuning with data arbitrage, preference training, and model merging. Serves 23 languages.', + description: + 'Aya Expanse 是一款高性能的 8B 多语言模型,旨在通过指令调优、数据套利、偏好训练和模型合并的创新,挑战单语言模型的表现。它支持 23 种语言。', displayName: 'Aya Expanse 8B', enabled: true, id: 'c4ai-aya-expanse-8b', @@ -203,7 +207,8 @@ const cohereChatModels: AIChatModelCard[] = [ vision: true, }, contextWindowTokens: 16_000, - description: 'Aya Vision is a state-of-the-art multimodal model excelling at a variety of critical benchmarks for language, text, and image capabilities. Serves 23 languages. This 32 billion parameter variant is focused on state-of-art multilingual performance.', + description: + 'Aya Vision 是一款最先进的多模态模型,在语言、文本和图像能力的多个关键基准上表现出色。它支持 23 种语言。这个 320 亿参数的版本专注于最先进的多语言表现。', displayName: 'Aya Vision 32B', enabled: true, id: 'c4ai-aya-vision-32b', @@ -219,7 +224,8 @@ const cohereChatModels: AIChatModelCard[] = [ vision: true, }, contextWindowTokens: 16_000, - description: 'Aya Vision is a state-of-the-art multimodal model excelling at a variety of critical benchmarks for language, text, and image capabilities. This 8 billion parameter variant is focused on low latency and best-in-class performance.', + description: + 'Aya Vision 是一款最先进的多模态模型,在语言、文本和图像能力的多个关键基准上表现出色。这个 80 亿参数的版本专注于低延迟和最佳性能。', displayName: 'Aya Vision 8B', enabled: true, id: 'c4ai-aya-vision-8b', diff --git a/src/config/modelProviders/cohere.ts b/src/config/modelProviders/cohere.ts index 03856b349f339..5211f22fe1cf7 100644 --- a/src/config/modelProviders/cohere.ts +++ b/src/config/modelProviders/cohere.ts @@ -4,12 +4,10 @@ const Cohere: ModelProviderCard = { chatModels: [], checkModel: 'command-r7b-12-2024', description: 'Cohere', - //disableBrowserRequest: true, id: 'cohere', modelsUrl: 'https://docs.cohere.com/v2/docs/models', name: 'Cohere', settings: { - //disableBrowserRequest: true, proxyUrl: { placeholder: 'https://api.cohere.ai/compatibility/v1', }, From 94cb887b336ae26e3aa0906ba4eab93c1d717bc4 Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 17 Mar 2025 23:37:27 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20cohere=20model?= =?UTF-8?q?=20list=20fetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/agent-runtime/cohere/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/agent-runtime/cohere/index.ts b/src/libs/agent-runtime/cohere/index.ts index 9747084abdd8f..dbf99eeaf150c 100644 --- a/src/libs/agent-runtime/cohere/index.ts +++ b/src/libs/agent-runtime/cohere/index.ts @@ -5,7 +5,7 @@ import type { ChatModelCard } from '@/types/llm'; export interface CohereModelCard { context_length: number; - features: string[]; + features: string[] | null; name: string; supports_vision: boolean; } @@ -47,7 +47,7 @@ export const LobeCohereAI = LobeOpenAICompatibleFactory({ displayName: knownModel?.displayName ?? undefined, enabled: knownModel?.enabled || false, functionCall: - model.features.includes("tools") + (model.features && model.features.includes("tools")) || knownModel?.abilities?.functionCall || false, id: model.name, From 45e529658609533219bf9c6a6f4d4a2cd86876dc Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 17 Mar 2025 23:50:16 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20cohere=20callin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libs/agent-runtime/cohere/index.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libs/agent-runtime/cohere/index.ts b/src/libs/agent-runtime/cohere/index.ts index dbf99eeaf150c..89bf9303a20d6 100644 --- a/src/libs/agent-runtime/cohere/index.ts +++ b/src/libs/agent-runtime/cohere/index.ts @@ -20,9 +20,15 @@ export const LobeCohereAI = LobeOpenAICompatibleFactory({ return { ...rest, - frequency_penalty: frequency_penalty !== undefined ? Math.max(0, Math.min(1, frequency_penalty / 2)) : undefined, - presence_penalty: presence_penalty !== undefined ? Math.max(0, Math.min(1, presence_penalty / 2)) : undefined, - top_p: top_p !== undefined ? Math.max(0.01, Math.min(0.99, top_p)) : undefined, + frequency_penalty: + frequency_penalty !== undefined && frequency_penalty > 0 && frequency_penalty <= 1 + ? frequency_penalty + : undefined, + presence_penalty: + presence_penalty !== undefined && presence_penalty > 0 && presence_penalty <= 1 + ? presence_penalty + : undefined, + top_p: top_p !== undefined && top_p > 0 && top_p < 1 ? top_p : undefined, } as any; }, noUserId: true, From 116e162f13efab91448a6a4c864ed3aa04bc6cb4 Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Mon, 17 Mar 2025 23:54:14 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=92=84=20style:=20update=20provider?= =?UTF-8?q?=20desc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/modelProviders/cohere.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/modelProviders/cohere.ts b/src/config/modelProviders/cohere.ts index 5211f22fe1cf7..8380cd33399b3 100644 --- a/src/config/modelProviders/cohere.ts +++ b/src/config/modelProviders/cohere.ts @@ -3,7 +3,7 @@ import { ModelProviderCard } from '@/types/llm'; const Cohere: ModelProviderCard = { chatModels: [], checkModel: 'command-r7b-12-2024', - description: 'Cohere', + description: 'Cohere 为您带来最前沿的多语言模型、先进的检索功能以及为现代企业量身定制的 AI 工作空间 — 一切都集成在一个安全的平台中。', id: 'cohere', modelsUrl: 'https://docs.cohere.com/v2/docs/models', name: 'Cohere', From 219a27c30c8edb3f5676f849421ed0168146141c Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Tue, 18 Mar 2025 00:01:03 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=92=84=20style:=20update=20model=20na?= =?UTF-8?q?me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/aiModels/cohere.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/aiModels/cohere.ts b/src/config/aiModels/cohere.ts index be35991620fd6..05d8082573c58 100644 --- a/src/config/aiModels/cohere.ts +++ b/src/config/aiModels/cohere.ts @@ -8,7 +8,7 @@ const cohereChatModels: AIChatModelCard[] = [ contextWindowTokens: 256_000, description: 'Command A 是我们迄今为止性能最强的模型,在工具使用、代理、检索增强生成(RAG)和多语言应用场景方面表现出色。Command A 具有 256K 的上下文长度,仅需两块 GPU 即可运行,并且相比于 Command R+ 08-2024,吞吐量提高了 150%。', - displayName: 'Command A', + displayName: 'Command A 03-2025', enabled: true, id: 'command-a-03-2025', maxOutput: 8000,