Skip to content

Commit

Permalink
chore: remove ModelProviderContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ivyjeong13 committed Dec 5, 2024
1 parent a1d4416 commit 27c9ded
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 91 deletions.
82 changes: 0 additions & 82 deletions ui/admin/app/components/model-providers/ModelProviderContext.tsx

This file was deleted.

16 changes: 13 additions & 3 deletions ui/admin/app/components/model-providers/ModelProviderForm.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useFieldArray, useForm } from "react-hook-form";
import { mutate } from "swr";
import { z } from "zod";

import { ModelProviderConfig } from "~/lib/model/modelProviders";
import { ModelProviderApiService } from "~/lib/service/api/modelProviderApiService";

import { TypographyH4 } from "~/components/Typography";
import {
NameDescriptionForm,
ParamFormValues,
} from "~/components/composed/NameDescriptionForm";
import { ControlledInput } from "~/components/form/controlledInputs";
import { useModelProviders } from "~/components/model-providers/ModelProviderContext";
import { Button } from "~/components/ui/button";
import { Form } from "~/components/ui/form";
import { Separator } from "~/components/ui/separator";
Expand Down Expand Up @@ -75,7 +76,13 @@ export function ModelProviderForm({
parameters: ModelProviderConfig;
requiredParameters: string[];
}) {
const { configureModelProvider } = useModelProviders();
const configureModelProvider = useAsync(
ModelProviderApiService.configureModelProviderById,
{
onSuccess: () =>
mutate(ModelProviderApiService.getModelProviders.key()),
}
);

const form = useForm<ModelProviderFormValues>({
resolver: zodResolver(formSchema),
Expand Down Expand Up @@ -111,7 +118,10 @@ export function ModelProviderForm({
}
);

await configureModelProvider(modelProviderId, allConfigParams);
await configureModelProvider.execute(
modelProviderId,
allConfigParams
);
onSuccess(allConfigParams);
}
);
Expand Down
10 changes: 8 additions & 2 deletions ui/admin/app/components/model-providers/ModelProviderLists.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { BoxesIcon, CircleCheckIcon, CircleSlashIcon } from "lucide-react";
import useSWR from "swr";

import { ModelProviderApiService } from "~/lib/service/api/modelProviderApiService";

import { ModelProviderConfigure } from "~/components/model-providers/ModelProviderConfigure";
import { useModelProviders } from "~/components/model-providers/ModelProviderContext";
import { Card, CardContent, CardHeader } from "~/components/ui/card";

export function ModelProviderList() {
const { modelProviders } = useModelProviders();
const { data: modelProviders } = useSWR(
ModelProviderApiService.getModelProviders.key(),
() => ModelProviderApiService.getModelProviders(),
{ fallbackData: [] }
);

return (
<div className="space-y-4">
Expand Down
6 changes: 2 additions & 4 deletions ui/admin/app/routes/_auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { UserService } from "~/lib/service/api/userService";
import { useAuth } from "~/components/auth/AuthContext";
import { Error, RouteError, Unauthorized } from "~/components/errors";
import { HeaderNav } from "~/components/header/HeaderNav";
import { ModelProviderProvider } from "~/components/model-providers/ModelProviderContext";
import { Sidebar } from "~/components/sidebar";
import { SignIn } from "~/components/signin/SignIn";

export async function clientLoader() {
const me = await preload(UserService.getMe.key(), () =>
UserService.getMe()
);

return { me };
}

Expand All @@ -25,9 +25,7 @@ export default function AuthLayout() {
<div className="flex flex-col flex-grow overflow-hidden">
<HeaderNav />
<main className="flex-grow overflow-auto">
<ModelProviderProvider>
<Outlet />
</ModelProviderProvider>
<Outlet />
</main>
</div>
</div>
Expand Down

0 comments on commit 27c9ded

Please sign in to comment.