Skip to content

Commit bfa1435

Browse files
Merge pull request #65 from intelligentnode/64-add-anthropic
add Claude models
2 parents e88c538 + 3706587 commit bfa1435

File tree

9 files changed

+46
-4
lines changed

9 files changed

+46
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ https://github.com/intelligentnode/IntelliChat/assets/2751950/47d7db12-e299-449f
2525
- **Cohere Coral**.
2626
- **Replicate**: Llama (70b-chat, 13b-chat, 34b-code, 34b-python 13b-code-instruct).
2727
- **Mistral AI**: Open-weight models.
28+
- **Anthropic**: claude 3.
2829
- Manage your API keys via the UI.
2930
- Access your data using intellinode one key.
3031

intellichat/intellinode.d.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ declare module 'intellinode' {
66
| 'azure'
77
| 'gemini'
88
| 'cohere'
9-
| 'mistral';
9+
| 'mistral'
10+
| 'anthropic';
1011

1112
class Chatbot {
1213
constructor(
@@ -23,6 +24,7 @@ declare module 'intellinode' {
2324
| LLamaReplicateInput
2425
| CohereInput
2526
| GeminiInput
27+
| AnthropicInput
2628
);
2729
}
2830

@@ -104,6 +106,19 @@ declare module 'intellinode' {
104106
addAssistantMessage(message: string): void;
105107
}
106108

109+
class AnthropicInput {
110+
constructor(
111+
message: string,
112+
options?: {
113+
model?: string;
114+
attachReference?: boolean;
115+
}
116+
);
117+
118+
addUserMessage(message: string): void;
119+
addAssistantMessage(message: string): void;
120+
}
121+
107122
class ChatContext {
108123
constructor(
109124
apiKey: string,

intellichat/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"clsx": "2.0.0",
3232
"eslint": "8.48.0",
3333
"eslint-config-next": "13.4.19",
34-
"intellinode": "^1.8.0",
34+
"intellinode": "^1.8.5",
3535
"lucide-react": "0.274.0",
3636
"nanoid": "4.0.2",
3737
"next": "13.4.19",

intellichat/src/app/api/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export async function GET() {
99
const GoogleKey = getChatProviderKey('google');
1010
const AzureKey = getChatProviderKey('azure');
1111
const MistralKey = getChatProviderKey('mistral');
12+
const anthropicKey = getChatProviderKey('anthropic');
1213

1314
return NextResponse.json({
1415
openai: !!OpenAIKey,
@@ -17,5 +18,6 @@ export async function GET() {
1718
google: !!GoogleKey,
1819
azure: !!AzureKey,
1920
mistral: !!MistralKey,
21+
anthropic: !!anthropicKey,
2022
});
2123
}

intellichat/src/lib/ai-providers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ReplicateModels = [
1313
const CohereModels = ['command'] as const;
1414
const GoogleModels = ['gemini'] as const;
1515
const MistralModels = ['mistral-tiny', 'mistral-medium'] as const;
16+
const AnthropicModels = ['claude-3-sonnet-20240229', 'claude-3-opus-20240229'] as const;
1617

1718
export const AIProviders = {
1819
openai: {
@@ -35,6 +36,10 @@ export const AIProviders = {
3536
name: 'mistral' as const,
3637
models: MistralModels,
3738
},
39+
anthropic: {
40+
name: 'anthropic' as const,
41+
models: AnthropicModels,
42+
},
3843
// azure is a special case, it has a different validator
3944
// and the model names are entered manually instead of being a list
4045
azure: {

intellichat/src/lib/intellinode.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
GeminiInput,
77
LLamaReplicateInput,
88
MistralInput,
9+
AnthropicInput,
910
ProxyHelper,
1011
} from 'intellinode';
1112
import { ChatProvider } from './types';
@@ -17,10 +18,13 @@ import {
1718
googleType,
1819
googleValidator,
1920
mistralValidator,
21+
mistralType,
2022
openAIType,
2123
openAIValidator,
2224
replicateType,
2325
replicateValidator,
26+
anthropicType,
27+
anthropicValidator,
2428
} from './validators';
2529

2630
// We can use this function to get the default provider key if onekey is provided and starts with 'in'
@@ -40,6 +44,8 @@ export function getDefaultProviderKey(provider: ChatProvider, oneKey?: string) {
4044
return process.env.INTELLI_COHERE_API_KEY;
4145
case 'google':
4246
return process.env.INTELLI_GOOGLE_API_KEY;
47+
case 'anthropic':
48+
return process.env.INTELLI_Anthropic_API_KEY;
4349
default:
4450
return null;
4551
}
@@ -59,6 +65,8 @@ export function getChatProviderKey(provider: ChatProvider) {
5965
return process.env.GOOGLE_API_KEY;
6066
case 'mistral':
6167
return process.env.MISTRAL_API_KEY;
68+
case 'anthropic':
69+
return process.env.Anthropic_API_KEY;
6270
default:
6371
return null;
6472
}
@@ -126,7 +134,7 @@ type getChatResponseParams = {
126134
role: 'user' | 'assistant';
127135
content: string;
128136
}[];
129-
provider?: openAIType | replicateType | cohereType | googleType;
137+
provider?: openAIType | replicateType | cohereType | googleType | mistralType | anthropicType;
130138
withContext: boolean;
131139
n: number;
132140
contextKey?: string | null;
@@ -146,6 +154,8 @@ const validateProvider = (name: string) => {
146154
return googleValidator;
147155
case 'mistral':
148156
return mistralValidator;
157+
case 'anthropic':
158+
return anthropicValidator;
149159
default:
150160
throw new Error('provider is not supported');
151161
}
@@ -218,6 +228,8 @@ function getChatInput(provider: string, model: string, systemMessage: string) {
218228
return new GeminiInput(systemMessage, { model, attachReference: true });
219229
case 'mistral':
220230
return new MistralInput(systemMessage, { model, attachReference: true });
231+
case 'anthropic':
232+
return new AnthropicInput(systemMessage, { model, attachReference: true });
221233
default:
222234
throw new Error('provider is not supported');
223235
}

intellichat/src/lib/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export type ChatProvider =
1111
| 'azure'
1212
| 'cohere'
1313
| 'google'
14-
| 'mistral';
14+
| 'mistral'
15+
| 'anthropic';

intellichat/src/lib/validators.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ export type azureType = z.infer<typeof azureValidator>;
4040
export const mistralValidator = createProviderValidator(AIProviders.mistral);
4141
export type mistralType = z.infer<typeof mistralValidator>;
4242

43+
export const anthropicValidator = createProviderValidator(AIProviders.anthropic);
44+
export type anthropicType = z.infer<typeof anthropicValidator>;
45+
4346
export const ProvidersValidator = z.object({
4447
openai: openAIValidator.optional(),
4548
replicate: replicateValidator.optional(),
4649
cohere: cohereValidator.optional(),
4750
google: googleValidator.optional(),
4851
azure: azureValidator.optional(),
4952
mistral: mistralValidator.optional(),
53+
anthropic: anthropicValidator.optional()
5054
});
5155
export type SupportedProvidersType = z.infer<typeof ProvidersValidator>;
5256
export type SupportedProvidersNamesType = keyof SupportedProvidersType;

intellichat/src/store/chat-settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const initialProviders: ChatSettingsState['providers'] = {
4040
apiKey: '',
4141
},
4242
google: { name: 'google', model: 'gemini', apiKey: '' },
43+
4344
azure: {
4445
name: 'azure',
4546
model: '',
@@ -48,6 +49,7 @@ const initialProviders: ChatSettingsState['providers'] = {
4849
embeddingName: '',
4950
},
5051
mistral: { name: 'mistral', model: 'mistral-tiny', apiKey: '' },
52+
anthropic: { name: 'anthropic', model: 'claude-3-sonnet-20240229', apiKey: '' },
5153
};
5254

5355
const initialState = {

0 commit comments

Comments
 (0)