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

[OPIK-740]: handle adding provider #1031

Merged
merged 2 commits into from
Jan 13, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@ const PlaygroundPrompt = ({
[updatePrompt, promptId],
);

const handleAddProvider = useCallback(
(provider: PROVIDER_TYPE) => {
const modelProvider = model ? getModelProvider(model) : "";
const noCurrentModel = !modelProvider;

if (noCurrentModel) {
const newModel = PROVIDERS[provider].defaultModel;

const newDefaultConfigs = provider
? getDefaultConfigByProvider(provider)
: {};

updatePrompt(promptId, {
model: newModel,
configs: newDefaultConfigs,
});
}
},
[model, promptId, updatePrompt],
);

useEffect(() => {
// on init, to check if a prompt has a model from valid providers: (f.e., remove a provider after setting a model)
if (!checkedIfModelIsValidRef.current && !isPendingProviderKeys) {
Expand Down Expand Up @@ -175,6 +196,7 @@ const PlaygroundPrompt = ({
onChange={handleUpdateModel}
provider={provider}
workspaceName={workspaceName}
onAddProvider={handleAddProvider}
/>
</div>
<PromptModelConfigs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface PromptModelSelectProps {
workspaceName: string;
onChange: (value: PROVIDER_MODEL_TYPE) => void;
provider: PROVIDER_TYPE | "";
onAddProvider?: (provider: PROVIDER_TYPE) => void;
}

const STALE_TIME = 1000;
Expand All @@ -44,6 +45,7 @@ const PromptModelSelect = ({
workspaceName,
onChange,
provider,
onAddProvider,
}: PromptModelSelectProps) => {
const resetDialogKeyRef = useRef(0);
const inputRef = useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -290,6 +292,7 @@ const PromptModelSelect = ({
key={resetDialogKeyRef.current}
open={openConfigDialog}
setOpen={setOpenConfigDialog}
onAddProvider={onAddProvider}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ import { PROVIDERS, PROVIDERS_OPTIONS } from "@/constants/providers";
import { SelectItem } from "@/components/ui/select";
import { DropdownOption } from "@/types/shared";
import EyeInput from "@/components/shared/EyeInput/EyeInput";
import isFunction from "lodash/isFunction";

type AddEditAIProviderDialogProps = {
providerKey?: ProviderKey;
open: boolean;
setOpen: (open: boolean) => void;
onAddProvider?: (provider: PROVIDER_TYPE) => void;
};

const AddEditAIProviderDialog: React.FC<AddEditAIProviderDialogProps> = ({
providerKey,
open,
setOpen,
onAddProvider,
}) => {
const { mutate: createMutate } = useProviderKeysCreateMutation();
const { mutate: updateMutate } = useProviderKeysUpdateMutation();
Expand Down Expand Up @@ -58,14 +61,26 @@ const AddEditAIProviderDialog: React.FC<AddEditAIProviderDialogProps> = ({
},
});
} else if (provider) {
if (isFunction(onAddProvider)) {
onAddProvider(provider);
}

createMutate({
providerKey: {
apiKey,
provider,
},
});
}
}, [createMutate, isEdit, apiKey, updateMutate, provider, providerKey]);
}, [
createMutate,
isEdit,
apiKey,
updateMutate,
provider,
providerKey,
onAddProvider,
]);

const renderOption = (option: DropdownOption<string>) => {
const Icon = PROVIDERS[option.value as PROVIDER_TYPE].icon;
Expand Down
Loading