-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deconfigure model provider option
- Loading branch information
1 parent
db96799
commit e199bad
Showing
7 changed files
with
190 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
ui/admin/app/components/model-providers/ModelProviderDeconfigure.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { useState } from "react"; | ||
import { toast } from "sonner"; | ||
import { mutate } from "swr"; | ||
|
||
import { ModelProvider } from "~/lib/model/modelProviders"; | ||
import { ModelApiService } from "~/lib/service/api/modelApiService"; | ||
import { ModelProviderApiService } from "~/lib/service/api/modelProviderApiService"; | ||
|
||
import { TypographyP } from "~/components/Typography"; | ||
import { Button } from "~/components/ui/button"; | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from "~/components/ui/dialog"; | ||
import { DropdownMenuItem } from "~/components/ui/dropdown-menu"; | ||
import { useAsync } from "~/hooks/useAsync"; | ||
|
||
export function ModelProviderDeconfigure({ | ||
modelProvider, | ||
}: { | ||
modelProvider: ModelProvider; | ||
}) { | ||
const [open, setOpen] = useState(false); | ||
const handleDeconfigure = async () => { | ||
deconfigure.execute(modelProvider.id); | ||
}; | ||
|
||
const deconfigure = useAsync( | ||
ModelProviderApiService.deconfigureModelProviderById, | ||
{ | ||
onSuccess: () => { | ||
toast.success(`${modelProvider.name} deconfigured.`); | ||
mutate(ModelProviderApiService.getModelProviders.key()); | ||
mutate(ModelApiService.getModels.key()); | ||
}, | ||
onError: () => | ||
toast.error(`Failed to deconfigure ${modelProvider.name}`), | ||
} | ||
); | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogTrigger> | ||
<DropdownMenuItem | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
setOpen(true); | ||
}} | ||
className="text-destructive" | ||
> | ||
Deconfigure Model Provider | ||
</DropdownMenuItem> | ||
</DialogTrigger> | ||
|
||
<DialogDescription hidden> | ||
Configure Model Provider | ||
</DialogDescription> | ||
|
||
<DialogContent hideCloseButton> | ||
<DialogHeader> | ||
<DialogTitle>Deconfigure {modelProvider.name}</DialogTitle> | ||
</DialogHeader> | ||
<TypographyP> | ||
Deconfiguring this model provider will remove all models | ||
associated with it and reset it to its unconfigured state. | ||
You will need to set up the model provider once again to use | ||
it. | ||
</TypographyP> | ||
|
||
<TypographyP> | ||
Are you sure you want to deconfigure{" "} | ||
<b>{modelProvider.name}</b>? | ||
</TypographyP> | ||
|
||
<DialogFooter> | ||
<div className="w-full flex justify-center items-center gap-10 pt-4"> | ||
<DialogClose asChild> | ||
<Button className="w-1/2" variant="outline"> | ||
Cancel | ||
</Button> | ||
</DialogClose> | ||
<DialogClose asChild> | ||
<Button | ||
className="w-1/2" | ||
onClick={handleDeconfigure} | ||
variant="destructive" | ||
> | ||
Confirm | ||
</Button> | ||
</DialogClose> | ||
</div> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
37 changes: 37 additions & 0 deletions
37
ui/admin/app/components/model-providers/ModelProviderDropdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { EllipsisVerticalIcon } from "lucide-react"; | ||
|
||
import { ModelProvider } from "~/lib/model/modelProviders"; | ||
|
||
import { ModelProviderDeconfigure } from "~/components/model-providers/ModelProviderDeconfigure"; | ||
import { Button } from "~/components/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuGroup, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from "~/components/ui/dropdown-menu"; | ||
|
||
export function ModelProviderMenu({ | ||
modelProvider, | ||
}: { | ||
modelProvider: ModelProvider; | ||
}) { | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="ghost" size="icon"> | ||
<EllipsisVerticalIcon /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="w-56" side="bottom" align="start"> | ||
<DropdownMenuGroup> | ||
<DropdownMenuLabel>{modelProvider.name}</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<ModelProviderDeconfigure modelProvider={modelProvider} /> | ||
</DropdownMenuGroup> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters