Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial implementation for Cohere provider support #2539

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0430b7f
Add initial implementation for Cohere provider support
ystoneman May 16, 2024
158adf6
Use lobehub cohere icons
ystoneman May 29, 2024
91bbaef
Add Cohere to model provider config
ystoneman May 29, 2024
a302ce9
add placeholder draft for cohere helpers
ystoneman May 30, 2024
a089ab4
Add LobeCohereAI across files
ystoneman Jun 5, 2024
7242abf
cohere typescript package now includes stream
ystoneman Jun 11, 2024
b0a669d
Resolved verification errors
ystoneman Jun 12, 2024
88eafb4
Use CohereClient types
ystoneman Jun 26, 2024
05a009f
Fix stream types
ystoneman Jun 26, 2024
e1b1cc5
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jun 27, 2024
9632ef2
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jun 27, 2024
f5149a2
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jun 28, 2024
a321a9e
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jun 29, 2024
e7d3bed
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jun 29, 2024
f4df440
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 1, 2024
27a0187
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 1, 2024
c08fac0
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 2, 2024
ca5c632
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 2, 2024
d904cec
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 2, 2024
5e4fd74
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 3, 2024
ad0020c
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 3, 2024
eaa9f26
Merge branch 'main' into main
arvinxx Jul 3, 2024
971907c
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 3, 2024
35b5219
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 4, 2024
a4d81b4
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 5, 2024
6d23228
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 7, 2024
33870a1
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 7, 2024
339840a
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 7, 2024
ac2fb12
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 8, 2024
96237e9
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 9, 2024
35f302b
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 9, 2024
3662b1a
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 9, 2024
94cfc76
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 10, 2024
71efbf2
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 11, 2024
34c54f3
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 12, 2024
442d3dc
Merge branch 'main' of https://github.com/lobehub/lobe-chat
actions-user Jul 12, 2024
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"antd-style": "^3.6.2",
"brotli-wasm": "^3.0.1",
"chroma-js": "^2.4.2",
"cohere-ai": "^7.10.5",
"dayjs": "^1.11.11",
"debug": "^4.3.5",
"dexie": "^3.2.7",
Expand Down
17 changes: 16 additions & 1 deletion src/app/api/chat/agentRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
LobeAnthropicAI,
LobeAzureOpenAI,
LobeBedrockAI,
LobeCohereAI,
LobeDeepSeekAI,
LobeGoogleAI,
LobeGroq,
Expand Down Expand Up @@ -37,7 +38,7 @@ vi.mock('@/config/llm', () => ({

AZURE_API_KEY: 'test-azure-key',
AZURE_ENDPOINT: 'endpoint',

COHERE_API_KEY: 'test-cohere-key',
ZHIPU_API_KEY: 'test.zhipu-key',
MOONSHOT_API_KEY: 'test-moonshot-key',
AWS_SECRET_ACCESS_KEY: 'test-aws-secret',
Expand Down Expand Up @@ -145,6 +146,13 @@ describe('initAgentRuntimeWithUserPayload method', () => {
expect(runtime['_runtime']).toBeInstanceOf(LobeAnthropicAI);
});

it('Cohere AI provider: with apikey', async () => {
const jwtPayload: JWTPayload = { apiKey: 'user-cohere-key' };
const runtime = await initAgentRuntimeWithUserPayload(ModelProvider.Cohere, jwtPayload);
expect(runtime).toBeInstanceOf(AgentRuntime);
expect(runtime['_runtime']).toBeInstanceOf(LobeCohereAI);
});

it('Minimax AI provider: with apikey', async () => {
const jwtPayload: JWTPayload = { apiKey: 'user-minimax-key' };
const runtime = await initAgentRuntimeWithUserPayload(ModelProvider.Minimax, jwtPayload);
Expand Down Expand Up @@ -266,6 +274,13 @@ describe('initAgentRuntimeWithUserPayload method', () => {
expect(runtime['_runtime']).toBeInstanceOf(LobeBedrockAI);
});

it('Cohere AI provider: without apikey', async () => {
const jwtPayload = {};
const runtime = await initAgentRuntimeWithUserPayload(ModelProvider.Cohere, jwtPayload);

expect(runtime['_runtime']).toBeInstanceOf(LobeCohereAI);
});

it('Ollama provider: without endpoint', async () => {
const jwtPayload = {};
const runtime = await initAgentRuntimeWithUserPayload(ModelProvider.Ollama, jwtPayload);
Expand Down
33 changes: 33 additions & 0 deletions src/config/modelProviders/cohere.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ModelProviderCard } from '@/types/llm';

// ref https://cohere.com/command
const Cohere: ModelProviderCard = {
chatModels: [
{
description:
'An instruction-following conversational model that performs language tasks at a higher quality, more reliably, and with a longer context than previous models. Best suited for complex RAG workflows and multi-step tool use.',
displayName: 'Command R+',
enabled: true,
functionCall: true,
id: 'command-r-plus',
maxOutput: 4096,
tokens: 128_000,
vision: false,
},
{
description:
'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',
enabled: true,
functionCall: true,
id: 'command-r',
maxOutput: 4096,
tokens: 128_000,
vision: false,
}
], // TODO: what about embed models? I only see chatModels on other modelProviders
id: 'cohere',
name: 'Cohere',
};

export default Cohere;
4 changes: 4 additions & 0 deletions src/config/modelProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AnthropicProvider from './anthropic';
import AzureProvider from './azure';
import BaichuanProvider from './baichuan';
import BedrockProvider from './bedrock';
import CohereProvider from './cohere';
import DeepSeekProvider from './deepseek';
import GoogleProvider from './google';
import GroqProvider from './groq';
Expand All @@ -27,6 +28,7 @@ export const LOBE_DEFAULT_MODEL_LIST: ChatModelCard[] = [
QwenProvider.chatModels,
ZhiPuProvider.chatModels,
BedrockProvider.chatModels,
CohereProvider.chatModels,
DeepSeekProvider.chatModels,
GoogleProvider.chatModels,
GroqProvider.chatModels,
Expand All @@ -51,6 +53,7 @@ export const DEFAULT_MODEL_PROVIDER_LIST = [
QwenProvider,
OllamaProvider,
AnthropicProvider,
CohereProvider,
DeepSeekProvider,
GoogleProvider,
OpenRouterProvider,
Expand Down Expand Up @@ -83,6 +86,7 @@ export { default as AnthropicProviderCard } from './anthropic';
export { default as AzureProviderCard } from './azure';
export { default as BaichuanProviderCard } from './baichuan';
export { default as BedrockProviderCard } from './bedrock';
export { default as CohereProviderCard } from './cohere';
export { default as DeepSeekProviderCard } from './deepseek';
export { default as GoogleProviderCard } from './google';
export { default as GroqProviderCard } from './groq';
Expand Down
5 changes: 5 additions & 0 deletions src/const/settings/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AnthropicProviderCard,
BaichuanProviderCard,
BedrockProviderCard,
CohereProviderCard,
DeepSeekProviderCard,
GoogleProviderCard,
GroqProviderCard,
Expand Down Expand Up @@ -44,6 +45,10 @@ export const DEFAULT_LLM_CONFIG: UserModelProviderConfig = {
enabled: false,
enabledModels: filterEnabledModels(BedrockProviderCard),
},
cohere: {
enabled: false,
enabledModels: filterEnabledModels(CohereProviderCard),
},
deepseek: {
enabled: false,
enabledModels: filterEnabledModels(DeepSeekProviderCard),
Expand Down
3 changes: 2 additions & 1 deletion src/features/ChatInput/ActionBar/Clear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const Clear = memo(() => {
>
<ActionIcon
icon={Eraser}
overlayStyle={{ maxWidth: 'none' }}
// TODO: this property caused validation errors
// overlayStyle={{ maxWidth: 'none' }}
placement={'bottom'}
title={actionTitle} />
</Popconfirm>
Expand Down
13 changes: 13 additions & 0 deletions src/libs/agent-runtime/AgentRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
LobeAnthropicAI,
LobeAzureOpenAI,
LobeBedrockAI,
LobeCohereAI,
LobeGoogleAI,
LobeMistralAI,
LobeMoonshotAI,
Expand Down Expand Up @@ -41,6 +42,7 @@ vi.mock('@/config/server', () => ({
AZURE_API_KEY: 'test-azure-key',
AZURE_ENDPOINT: 'endpoint',

COHERE_API_KEY: 'test-cohere-key',
ZHIPU_API_KEY: 'test.zhipu-key',
MOONSHOT_API_KEY: 'test-moonshot-key',
AWS_SECRET_ACCESS_KEY: 'test-aws-secret',
Expand Down Expand Up @@ -204,6 +206,17 @@ describe('AgentRuntime', () => {
});
});

describe('Cohere AI provider', () => {
it('should initialize correctly', async () => {
const jwtPayload: JWTPayload = { apiKey: 'user-cohere-key' };
const runtime = await AgentRuntime.initializeWithProviderOptions(ModelProvider.Cohere, {
cohere: jwtPayload,
});

expect(runtime['_runtime']).toBeInstanceOf(LobeCohereAI);
});
});

describe('Mistral AI provider', () => {
it('should initialize correctly', async () => {
const jwtPayload: JWTPayload = { apiKey: 'user-mistral-key' };
Expand Down
7 changes: 7 additions & 0 deletions src/libs/agent-runtime/AgentRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { LobeAnthropicAI } from './anthropic';
import { LobeAzureOpenAI } from './azureOpenai';
import { LobeBaichuanAI } from './baichuan';
import { LobeBedrockAI, LobeBedrockAIParams } from './bedrock';
import { LobeCohereAI } from './cohere';
import { LobeDeepSeekAI } from './deepseek';
import { LobeGoogleAI } from './google';
import { LobeGroq } from './groq';
Expand Down Expand Up @@ -109,6 +110,7 @@ class AgentRuntime {
azure: { apiVersion?: string; apikey?: string; endpoint?: string };
baichuan: Partial<ClientOptions>;
bedrock: Partial<LobeBedrockAIParams>;
cohere: Partial<ClientOptions>;
deepseek: Partial<ClientOptions>;
google: { apiKey?: string; baseURL?: string };
groq: Partial<ClientOptions>;
Expand Down Expand Up @@ -181,6 +183,11 @@ class AgentRuntime {
break;
}

case ModelProvider.Cohere: {
runtimeModel = new LobeCohereAI(params.cohere ?? {});
break;
}

case ModelProvider.DeepSeek: {
runtimeModel = new LobeDeepSeekAI(params.deepseek);
break;
Expand Down
Loading