Skip to content

Commit

Permalink
fix: waiting for modelProvider models to load before showing default …
Browse files Browse the repository at this point in the history
…model selection (#796)

* fix: waiting for modelProvider models to load before showing default models selection

chore: name instead of id

Update ModelProviderModels.tsx

* chore: minor fixes
  • Loading branch information
ivyjeong13 authored Dec 6, 2024
1 parent 2f14103 commit d5109bf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
44 changes: 40 additions & 4 deletions ui/admin/app/components/model-providers/ModelProviderConfigure.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import useSWR from "swr";

import { ModelProvider, ModelProviderConfig } from "~/lib/model/modelProviders";
Expand Down Expand Up @@ -29,6 +29,32 @@ export function ModelProviderConfigure({
const [showDefaultModelAliasForm, setShowDefaultModelAliasForm] =
useState(false);

const [loadingModelProviderId, setLoadingModelProviderId] = useState("");

const getLoadingModelProviderModels = useSWR(
ModelProviderApiService.getModelProviderById.key(
loadingModelProviderId
),
({ modelProviderId }) =>
ModelProviderApiService.getModelProviderById(modelProviderId),
{
revalidateOnFocus: false,
refreshInterval: 2000,
}
);

useEffect(() => {
if (!loadingModelProviderId) return;

const { isLoading, data } = getLoadingModelProviderModels;
if (isLoading) return;

if (data?.modelsBackPopulated) {
setShowDefaultModelAliasForm(true);
setLoadingModelProviderId("");
}
}, [getLoadingModelProviderModels, loadingModelProviderId]);

const handleDone = () => {
setDialogIsOpen(false);
setShowDefaultModelAliasForm(false);
Expand All @@ -49,8 +75,16 @@ export function ModelProviderConfigure({
Configure Model Provider
</DialogDescription>

<DialogContent className="p-0 gap-0">
{showDefaultModelAliasForm ? (
<DialogContent
className="p-0 gap-0"
hideCloseButton={loadingModelProviderId !== ""}
>
{loadingModelProviderId ? (
<div className="flex items-center justify-center gap-1 p-2">
<LoadingSpinner /> Loading {modelProvider.name}{" "}
Models...
</div>
) : showDefaultModelAliasForm ? (
<div className="p-6">
<DialogHeader>
<DialogTitle className="flex items-center gap-2 pb-4">
Expand All @@ -62,7 +96,9 @@ export function ModelProviderConfigure({
) : (
<ModelProviderConfigureContent
modelProvider={modelProvider}
onSuccess={() => setShowDefaultModelAliasForm(true)}
onSuccess={() =>
setLoadingModelProviderId(modelProvider.id)
}
/>
)}
</DialogContent>
Expand Down
26 changes: 14 additions & 12 deletions ui/admin/app/components/model-providers/ModelProviderModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function ModelProvidersModels({ modelProvider }: ModelsConfigureProps) {
<DataTable
columns={getColumns()}
data={models}
sort={[{ id: "id", desc: true }]}
sort={[{ id: "usage", desc: true }]}
/>
</ScrollArea>
</DialogContent>
Expand All @@ -84,19 +84,21 @@ export function ModelProvidersModels({ modelProvider }: ModelsConfigureProps) {

function getColumns(): ColumnDef<Model, string>[] {
return [
columnHelper.accessor((model) => model.id, {
id: "id",
columnHelper.accessor((model) => model.name, {
id: "name",
header: "Model",
}),
columnHelper.display({
id: "usage",
header: "Usage",
cell: ({ row }) => (
<Badge variant="outline">
{getModelUsageLabel(row.original.usage)}
</Badge>
),
}),
columnHelper.accessor(
(model) => getModelUsageLabel(model.usage) || "",
{
id: "usage",
header: "Usage",
cell: ({ getValue }) =>
getValue() ? (
<Badge variant="outline">{getValue()}</Badge>
) : null,
}
),
columnHelper.display({
id: "actions",
cell: ({ row }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { DefaultModelAliasApiService } from "~/lib/service/api/defaultModelAliasApiService";
import { ModelApiService } from "~/lib/service/api/modelApiService";

import { TypographyP } from "~/components/Typography";
import { Button } from "~/components/ui/button";
import {
Dialog,
Expand Down Expand Up @@ -206,7 +207,12 @@ export function DefaultModelAliasForm({
defaultModel: string
) {
if (!modelOptions) {
if (!defaultModel) return null;
if (!defaultModel)
return (
<TypographyP className="p-2 text-muted-foreground">
No Models Available.
</TypographyP>
);
return <SelectItem value={defaultModel}>{defaultModel}</SelectItem>;
}

Expand Down

0 comments on commit d5109bf

Please sign in to comment.