Skip to content
Merged
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
131 changes: 111 additions & 20 deletions app/client/src/pages/Settings/AddModelProviderButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { PlusCircleOutlined } from '@ant-design/icons';
import { Alert, Button, Form, Input, Modal, notification, Radio, Select } from 'antd';
import { Alert, AutoComplete, Button, Form, Input, Modal, notification, Radio, Select } from 'antd';
import type { CheckboxGroupProps } from 'antd/es/checkbox';
import get from 'lodash/get';
import isEqual from 'lodash/isEqual';
Expand All @@ -10,15 +10,19 @@ import Loading from '../Evaluator/Loading';

export enum ModelProviderType {
OPENAI = 'openai',
OPENAI_COMPATIBLE = 'openai_compatible',
GEMINI = 'gemini',
CAII = 'caii'
CAII = 'caii',
AWS_BEDROCK = 'aws_bedrock'
}


const modelProviderTypeOptions: CheckboxGroupProps<string>['options'] = [
export const modelProviderTypeOptions: CheckboxGroupProps<string>['options'] = [
{ label: 'OpenAI', value: 'openai' },
// { label: 'CAII', value: 'caii' },
{ label: 'OpenAI Compatible', value: 'openai_compatible' },
{ label: 'Gemini', value: 'gemini' },
{ label: 'AWS Bedrock', value: 'aws_bedrock' },
{ label: 'CAII', value: 'caii' },
];

const OPENAI_MODELS = [
Expand All @@ -27,7 +31,7 @@ const OPENAI_MODELS = [
"gpt-4.1-nano"
];

const OPENAI_MODELS_OPTIONS = OPENAI_MODELS.map((model: string) => ({
export const OPENAI_MODELS_OPTIONS = OPENAI_MODELS.map((model: string) => ({
label: model,
value: model
}));
Expand All @@ -38,7 +42,42 @@ const GEMINI_MODELS = [
"gemini-2.5-flash-lite" // June 2025 - cost-efficient
];

const GEMINI_MODELS_OPTIONS = GEMINI_MODELS.map((model: string) => ({
export const AWS_BEDROCK_MODELS = [
"us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"us.anthropic.claude-sonnet-4-5-20250929-v1:0",
"us.anthropic.claude-opus-4-1-20250805-v1:0",
"us.anthropic.claude-opus-4-20250514-v1:0",
"global.anthropic.claude-sonnet-4-20250514-v1:0",
"us.anthropic.claude-3-7-sonnet-20250219-v1:0",
"us.anthropic.claude-3-5-haiku-20241022-v1:0",
"anthropic.claude-3-5-sonnet-20240620-v1:0",
"anthropic.claude-3-haiku-20240307-v1:0",
"anthropic.claude-3-sonnet-20240229-v1:0",
"us.anthropic.claude-3-opus-20240229-v1:0",
"meta.llama3-8b-instruct-v1:0",
"meta.llama3-70b-instruct-v1:0",
"mistral.mistral-large-2402-v1:0",
"mistral.mistral-small-2402-v1:0",
"us.meta.llama3-2-11b-instruct-v1:0",
"us.meta.llama3-2-3b-instruct-v1:0",
"us.meta.llama3-2-90b-instruct-v1:0",
"us.meta.llama3-2-1b-instruct-v1:0",
"us.meta.llama3-1-8b-instruct-v1:0",
"us.meta.llama3-1-70b-instruct-v1:0",
"us.meta.llama3-3-70b-instruct-v1:0",
"us.mistral.pixtral-large-2502-v1:0",
"us.meta.llama4-scout-17b-instruct-v1:0",
"us.meta.llama4-maverick-17b-instruct-v1:0",
"mistral.mistral-7b-instruct-v0:2",
"mistral.mixtral-8x7b-instruct-v0:1"
];

export const AWS_BEDROCK_MODELS_OPTIONS = AWS_BEDROCK_MODELS.map((model: string) => ({
label: model,
value: model
}));

export const GEMINI_MODELS_OPTIONS = GEMINI_MODELS.map((model: string) => ({
label: model,
value: model
}));
Expand All @@ -50,6 +89,7 @@ interface Props {
const AddModelProviderButton: React.FC<Props> = ({ refetch }) => {
const [form] = Form.useForm();
const [showModal, setShowModal] = useState(false);
const [modelProviderType, setModelProviderType] = useState<ModelProviderType>(ModelProviderType.OPENAI);
const [models, setModels] = useState(OPENAI_MODELS_OPTIONS);
const mutation = useMutation({
mutationFn: addModelProvider
Expand Down Expand Up @@ -106,10 +146,13 @@ const AddModelProviderButton: React.FC<Props> = ({ refetch }) => {

const onChange = (e: any) => {
const value = get(e, 'target.value');
setModelProviderType(value as ModelProviderType);
if (value === 'openai' && !isEqual(OPENAI_MODELS_OPTIONS, models)) {
setModels(OPENAI_MODELS_OPTIONS);
} else if (value === 'gemini' && !isEqual(GEMINI_MODELS_OPTIONS, models)) {
setModels(GEMINI_MODELS_OPTIONS);
} else if (value === 'aws_bedrock' && !isEqual(GEMINI_MODELS_OPTIONS, models)) {
setModels(AWS_BEDROCK_MODELS_OPTIONS);
}
}

Expand Down Expand Up @@ -146,7 +189,7 @@ const AddModelProviderButton: React.FC<Props> = ({ refetch }) => {
defaultValue="openai"
optionType="button"
buttonStyle="solid"
style={{ width: '40%' }}
style={{ width: '100%', whiteSpace: 'nowrap' }}
onChange={onChange}
/>
</Form.Item>
Expand All @@ -162,49 +205,97 @@ const AddModelProviderButton: React.FC<Props> = ({ refetch }) => {
<Input />
</Form.Item>
<Form.Item
name="endpoint_id"
label="Endpoint ID"
name="model_id"
label="Model"
rules={[
{
required: true,
message: 'This field is required.'
}
]}>
<Input />
<AutoComplete
autoFocus
showSearch
allowClear
options={[
{ label: <strong>{'Enter Model Name '}</strong>, value: '' }
].concat(
models
)}
placeholder={'Select Model'}
/>
</Form.Item>
<Form.Item
name="model_id"
label="Model"

{modelProviderType !== ModelProviderType.OPENAI && modelProviderType !== ModelProviderType.GEMINI && <Form.Item
name="endpoint_url"
label="Endpoint URL"
rules={[
{
required: true,
message: 'This field is required.'
}
]}>
<Input />
</Form.Item>}
{modelProviderType !== ModelProviderType.AWS_BEDROCK && modelProviderType !== ModelProviderType.CAII && <Form.Item
name="api_key"
label="API Key"
rules={[
{
required: true,
message: 'This field is required.'
}
]}>
<Select options={models} />
<Input.Password />
</Form.Item>}
{modelProviderType === ModelProviderType.CAII && <Form.Item
name="cdp_token"
label="CDP Token"
rules={[
{
required: true,
message: 'This field is required.'
}
]}>
<Input.Password />
</Form.Item>}
{modelProviderType === ModelProviderType.AWS_BEDROCK &&
<>
<Form.Item
name="aws_access_key_id:"
label="Access Key"
rules={[
{
required: true,
message: 'This field is required.'
}
]}>
<Input.Password />
</Form.Item>
<Form.Item
name="endpoint_url"
label="Endpoint URL"
name="aws_secret_access_key:"
label="Secret Key"
rules={[
{
required: true,
message: 'This field is required.'
}
]}>
<Input />
<Input.Password />
</Form.Item>
<Form.Item
name="api_key"
label="API Key"
name="region:"
label="Region"
rules={[
{
required: true,
message: 'This field is required.'
}
]}>
<Input.Password />
<Input />
</Form.Item>
</>
}
</Form>
</Modal>}
</>
Expand Down
Loading