Skip to content

Commit

Permalink
Merge pull request #65 from intelligentnode/64-add-anthropic
Browse files Browse the repository at this point in the history
add Claude models
  • Loading branch information
intelligentnode authored Mar 12, 2024
2 parents e88c538 + 3706587 commit bfa1435
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ https://github.com/intelligentnode/IntelliChat/assets/2751950/47d7db12-e299-449f
- **Cohere Coral**.
- **Replicate**: Llama (70b-chat, 13b-chat, 34b-code, 34b-python 13b-code-instruct).
- **Mistral AI**: Open-weight models.
- **Anthropic**: claude 3.
- Manage your API keys via the UI.
- Access your data using intellinode one key.

Expand Down
17 changes: 16 additions & 1 deletion intellichat/intellinode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ declare module 'intellinode' {
| 'azure'
| 'gemini'
| 'cohere'
| 'mistral';
| 'mistral'
| 'anthropic';

class Chatbot {
constructor(
Expand All @@ -23,6 +24,7 @@ declare module 'intellinode' {
| LLamaReplicateInput
| CohereInput
| GeminiInput
| AnthropicInput
);
}

Expand Down Expand Up @@ -104,6 +106,19 @@ declare module 'intellinode' {
addAssistantMessage(message: string): void;
}

class AnthropicInput {
constructor(
message: string,
options?: {
model?: string;
attachReference?: boolean;
}
);

addUserMessage(message: string): void;
addAssistantMessage(message: string): void;
}

class ChatContext {
constructor(
apiKey: string,
Expand Down
2 changes: 1 addition & 1 deletion intellichat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"clsx": "2.0.0",
"eslint": "8.48.0",
"eslint-config-next": "13.4.19",
"intellinode": "^1.8.0",
"intellinode": "^1.8.5",
"lucide-react": "0.274.0",
"nanoid": "4.0.2",
"next": "13.4.19",
Expand Down
2 changes: 2 additions & 0 deletions intellichat/src/app/api/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function GET() {
const GoogleKey = getChatProviderKey('google');
const AzureKey = getChatProviderKey('azure');
const MistralKey = getChatProviderKey('mistral');
const anthropicKey = getChatProviderKey('anthropic');

return NextResponse.json({
openai: !!OpenAIKey,
Expand All @@ -17,5 +18,6 @@ export async function GET() {
google: !!GoogleKey,
azure: !!AzureKey,
mistral: !!MistralKey,
anthropic: !!anthropicKey,
});
}
5 changes: 5 additions & 0 deletions intellichat/src/lib/ai-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ReplicateModels = [
const CohereModels = ['command'] as const;
const GoogleModels = ['gemini'] as const;
const MistralModels = ['mistral-tiny', 'mistral-medium'] as const;
const AnthropicModels = ['claude-3-sonnet-20240229', 'claude-3-opus-20240229'] as const;

export const AIProviders = {
openai: {
Expand All @@ -35,6 +36,10 @@ export const AIProviders = {
name: 'mistral' as const,
models: MistralModels,
},
anthropic: {
name: 'anthropic' as const,
models: AnthropicModels,
},
// azure is a special case, it has a different validator
// and the model names are entered manually instead of being a list
azure: {
Expand Down
14 changes: 13 additions & 1 deletion intellichat/src/lib/intellinode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
GeminiInput,
LLamaReplicateInput,
MistralInput,
AnthropicInput,
ProxyHelper,
} from 'intellinode';
import { ChatProvider } from './types';
Expand All @@ -17,10 +18,13 @@ import {
googleType,
googleValidator,
mistralValidator,
mistralType,
openAIType,
openAIValidator,
replicateType,
replicateValidator,
anthropicType,
anthropicValidator,
} from './validators';

// We can use this function to get the default provider key if onekey is provided and starts with 'in'
Expand All @@ -40,6 +44,8 @@ export function getDefaultProviderKey(provider: ChatProvider, oneKey?: string) {
return process.env.INTELLI_COHERE_API_KEY;
case 'google':
return process.env.INTELLI_GOOGLE_API_KEY;
case 'anthropic':
return process.env.INTELLI_Anthropic_API_KEY;
default:
return null;
}
Expand All @@ -59,6 +65,8 @@ export function getChatProviderKey(provider: ChatProvider) {
return process.env.GOOGLE_API_KEY;
case 'mistral':
return process.env.MISTRAL_API_KEY;
case 'anthropic':
return process.env.Anthropic_API_KEY;
default:
return null;
}
Expand Down Expand Up @@ -126,7 +134,7 @@ type getChatResponseParams = {
role: 'user' | 'assistant';
content: string;
}[];
provider?: openAIType | replicateType | cohereType | googleType;
provider?: openAIType | replicateType | cohereType | googleType | mistralType | anthropicType;
withContext: boolean;
n: number;
contextKey?: string | null;
Expand All @@ -146,6 +154,8 @@ const validateProvider = (name: string) => {
return googleValidator;
case 'mistral':
return mistralValidator;
case 'anthropic':
return anthropicValidator;
default:
throw new Error('provider is not supported');
}
Expand Down Expand Up @@ -218,6 +228,8 @@ function getChatInput(provider: string, model: string, systemMessage: string) {
return new GeminiInput(systemMessage, { model, attachReference: true });
case 'mistral':
return new MistralInput(systemMessage, { model, attachReference: true });
case 'anthropic':
return new AnthropicInput(systemMessage, { model, attachReference: true });
default:
throw new Error('provider is not supported');
}
Expand Down
3 changes: 2 additions & 1 deletion intellichat/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type ChatProvider =
| 'azure'
| 'cohere'
| 'google'
| 'mistral';
| 'mistral'
| 'anthropic';
4 changes: 4 additions & 0 deletions intellichat/src/lib/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ export type azureType = z.infer<typeof azureValidator>;
export const mistralValidator = createProviderValidator(AIProviders.mistral);
export type mistralType = z.infer<typeof mistralValidator>;

export const anthropicValidator = createProviderValidator(AIProviders.anthropic);
export type anthropicType = z.infer<typeof anthropicValidator>;

export const ProvidersValidator = z.object({
openai: openAIValidator.optional(),
replicate: replicateValidator.optional(),
cohere: cohereValidator.optional(),
google: googleValidator.optional(),
azure: azureValidator.optional(),
mistral: mistralValidator.optional(),
anthropic: anthropicValidator.optional()
});
export type SupportedProvidersType = z.infer<typeof ProvidersValidator>;
export type SupportedProvidersNamesType = keyof SupportedProvidersType;
Expand Down
2 changes: 2 additions & 0 deletions intellichat/src/store/chat-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const initialProviders: ChatSettingsState['providers'] = {
apiKey: '',
},
google: { name: 'google', model: 'gemini', apiKey: '' },

azure: {
name: 'azure',
model: '',
Expand All @@ -48,6 +49,7 @@ const initialProviders: ChatSettingsState['providers'] = {
embeddingName: '',
},
mistral: { name: 'mistral', model: 'mistral-tiny', apiKey: '' },
anthropic: { name: 'anthropic', model: 'claude-3-sonnet-20240229', apiKey: '' },
};

const initialState = {
Expand Down

0 comments on commit bfa1435

Please sign in to comment.