Skip to content

Commit

Permalink
Issue #1029: added possibility to delete models
Browse files Browse the repository at this point in the history
  • Loading branch information
lorev101 authored and danielecalda committed Aug 7, 2024
1 parent cf2c503 commit 89d374c
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 21 deletions.
41 changes: 24 additions & 17 deletions js-packages/admin-ui/src/components/EmbeddingModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { gql } from "@apollo/client";
import { formatName, Table } from "./Table";
import { useToast } from "./ToastProvider";
import { useEmbeddingModelsQuery, useEnableEmbeddingModelMutation } from "../graphql-generated";
import { useDeleteEmbeddingModelMutation, useEmbeddingModelsQuery, useEnableEmbeddingModelMutation } from "../graphql-generated";
import { ClayToggle } from "@clayui/form";
import { StyleToggle } from "./Form";

Expand Down Expand Up @@ -30,26 +30,32 @@ gql`
}
`;

gql`
mutation DeleteEmbeddingModel($id: ID!) {
deleteEmbeddingModel(embeddingModelId: $id) {
id
name
}
}
`;

export function EmbeddingModels() {
const showToast = useToast();
const embeddingModelsQuery = useEmbeddingModelsQuery();
const [updateEnableModel] = useEnableEmbeddingModelMutation({
refetchQueries: [EmbeddingModelsQuery],
});
// const [updateBucketsMutate] = useEnableBucketMutation({
// refetchQueries: [EmbeddingModelsQuery],
// });
// const [deleteBucketMutate] = useDeleteBucketMutation({
// refetchQueries: [EmbeddingModelsQuery],
// onCompleted(data) {
// if (data.deleteBucket?.id) {
// showToast({ displayType: "success", title: "Bucket deleted", content: data.deleteBucket.name ?? "" });
// }
// },
// onError(error) {
// showToast({ displayType: "danger", title: "Buckets error", content: error.message ?? "" });
// },
// });
const [deleteModelsMutate] = useDeleteEmbeddingModelMutation({
refetchQueries: [EmbeddingModelsQuery],
onCompleted(data) {
if (data.deleteEmbeddingModel?.id) {
showToast({ displayType: "success", title: "Models deleted", content: data.deleteEmbeddingModel.name ?? "" });
}
},
onError(error) {
showToast({ displayType: "danger", title: "embedding models error", content: error.message ?? "" });
},
});

return (
<Table
Expand All @@ -59,8 +65,9 @@ export function EmbeddingModels() {
}}
viewAdd={true}
onCreatePath="create/new/"
haveActions={false}
onDelete={(tenant) => {}}
onDelete={(model) => {
if (model?.id) deleteModelsMutate({ variables: { id: model.id } });
}}
columns={[
{ header: "Name", content: (enabledModel) => formatName(enabledModel) },
{ header: "Description", content: (enabledModel) => enabledModel?.description },
Expand Down
32 changes: 29 additions & 3 deletions js-packages/admin-ui/src/components/LargeLanguageModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React from "react";
import { gql } from "@apollo/client";
import { formatName, Table } from "./Table";
import { useToast } from "./ToastProvider";
import { useEnableLargeLanguageModelMutation, useLargeLanguageModelsQuery } from "../graphql-generated";
import {
useDeleteLargeLanguageModelMutation,
useEnableLargeLanguageModelMutation,
useLargeLanguageModelsQuery,
} from "../graphql-generated";
import { ClayToggle } from "@clayui/form";
import { StyleToggle } from "./Form";

Expand Down Expand Up @@ -34,22 +38,44 @@ gql`
}
`;

gql`
mutation DeleteLargeLanguageModel($id: ID!) {
deleteLargeLanguageModel(largeLanguageModelId: $id) {
id
name
}
}
`;

export function LargeLanguageModels() {
const showToast = useToast();
const largeLanguageModels = useLargeLanguageModelsQuery();
const [updateEnableLargeLaguageModel] = useEnableLargeLanguageModelMutation({
refetchQueries: [LargeLanguageModelsQuery],
});

const [deleteModelsMutate] = useDeleteLargeLanguageModelMutation({
refetchQueries: [LargeLanguageModelsQuery],
onCompleted(data) {
if (data.deleteLargeLanguageModel?.id) {
showToast({ displayType: "success", title: "Models deleted", content: data.deleteLargeLanguageModel.name ?? "" });
}
},
onError(error) {
showToast({ displayType: "danger", title: "largeLanguage error", content: error.message ?? "" });
},
});

return (
<Table
data={{
queryResult: largeLanguageModels,
field: (data) => data?.largeLanguageModels,
}}
onCreatePath="create/new/"
onDelete={(tenant) => {}}
haveActions={false}
onDelete={(model) => {
if (model?.id) deleteModelsMutate({ variables: { id: model.id } });
}}
columns={[
{ header: "Name", content: (tenant) => formatName(tenant) },
{ header: "Description", content: (tenant) => tenant?.description },
Expand Down
84 changes: 83 additions & 1 deletion js-packages/admin-ui/src/graphql-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5007,6 +5007,13 @@ export type EnableEmbeddingModelMutationVariables = Exact<{

export type EnableEmbeddingModelMutation = { __typename?: 'Mutation', enableEmbeddingModel?: { __typename?: 'EmbeddingModel', id?: string | null, name?: string | null } | null };

export type DeleteEmbeddingModelMutationVariables = Exact<{
id: Scalars['ID'];
}>;


export type DeleteEmbeddingModelMutation = { __typename?: 'Mutation', deleteEmbeddingModel?: { __typename?: 'EmbeddingModel', id?: string | null, name?: string | null } | null };

export type EnrichItemQueryVariables = Exact<{
id: Scalars['ID'];
}>;
Expand Down Expand Up @@ -5194,6 +5201,13 @@ export type EnableLargeLanguageModelMutationVariables = Exact<{

export type EnableLargeLanguageModelMutation = { __typename?: 'Mutation', enableLargeLanguageModel?: { __typename?: 'LargeLanguageModel', id?: string | null, name?: string | null } | null };

export type DeleteLargeLanguageModelMutationVariables = Exact<{
id: Scalars['ID'];
}>;


export type DeleteLargeLanguageModelMutation = { __typename?: 'Mutation', deleteLargeLanguageModel?: { __typename?: 'LargeLanguageModel', id?: string | null, name?: string | null } | null };

export type MonitoringEventsQueryVariables = Exact<{
field?: InputMaybe<EventSortable>;
ordering?: InputMaybe<Scalars['String']>;
Expand Down Expand Up @@ -10022,6 +10036,40 @@ export function useEnableEmbeddingModelMutation(baseOptions?: Apollo.MutationHoo
export type EnableEmbeddingModelMutationHookResult = ReturnType<typeof useEnableEmbeddingModelMutation>;
export type EnableEmbeddingModelMutationResult = Apollo.MutationResult<EnableEmbeddingModelMutation>;
export type EnableEmbeddingModelMutationOptions = Apollo.BaseMutationOptions<EnableEmbeddingModelMutation, EnableEmbeddingModelMutationVariables>;
export const DeleteEmbeddingModelDocument = gql`
mutation DeleteEmbeddingModel($id: ID!) {
deleteEmbeddingModel(embeddingModelId: $id) {
id
name
}
}
`;
export type DeleteEmbeddingModelMutationFn = Apollo.MutationFunction<DeleteEmbeddingModelMutation, DeleteEmbeddingModelMutationVariables>;

/**
* __useDeleteEmbeddingModelMutation__
*
* To run a mutation, you first call `useDeleteEmbeddingModelMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useDeleteEmbeddingModelMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [deleteEmbeddingModelMutation, { data, loading, error }] = useDeleteEmbeddingModelMutation({
* variables: {
* id: // value for 'id'
* },
* });
*/
export function useDeleteEmbeddingModelMutation(baseOptions?: Apollo.MutationHookOptions<DeleteEmbeddingModelMutation, DeleteEmbeddingModelMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<DeleteEmbeddingModelMutation, DeleteEmbeddingModelMutationVariables>(DeleteEmbeddingModelDocument, options);
}
export type DeleteEmbeddingModelMutationHookResult = ReturnType<typeof useDeleteEmbeddingModelMutation>;
export type DeleteEmbeddingModelMutationResult = Apollo.MutationResult<DeleteEmbeddingModelMutation>;
export type DeleteEmbeddingModelMutationOptions = Apollo.BaseMutationOptions<DeleteEmbeddingModelMutation, DeleteEmbeddingModelMutationVariables>;
export const EnrichItemDocument = gql`
query EnrichItem($id: ID!) {
enrichItem(id: $id) {
Expand Down Expand Up @@ -11020,6 +11068,40 @@ export function useEnableLargeLanguageModelMutation(baseOptions?: Apollo.Mutatio
export type EnableLargeLanguageModelMutationHookResult = ReturnType<typeof useEnableLargeLanguageModelMutation>;
export type EnableLargeLanguageModelMutationResult = Apollo.MutationResult<EnableLargeLanguageModelMutation>;
export type EnableLargeLanguageModelMutationOptions = Apollo.BaseMutationOptions<EnableLargeLanguageModelMutation, EnableLargeLanguageModelMutationVariables>;
export const DeleteLargeLanguageModelDocument = gql`
mutation DeleteLargeLanguageModel($id: ID!) {
deleteLargeLanguageModel(largeLanguageModelId: $id) {
id
name
}
}
`;
export type DeleteLargeLanguageModelMutationFn = Apollo.MutationFunction<DeleteLargeLanguageModelMutation, DeleteLargeLanguageModelMutationVariables>;

/**
* __useDeleteLargeLanguageModelMutation__
*
* To run a mutation, you first call `useDeleteLargeLanguageModelMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useDeleteLargeLanguageModelMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [deleteLargeLanguageModelMutation, { data, loading, error }] = useDeleteLargeLanguageModelMutation({
* variables: {
* id: // value for 'id'
* },
* });
*/
export function useDeleteLargeLanguageModelMutation(baseOptions?: Apollo.MutationHookOptions<DeleteLargeLanguageModelMutation, DeleteLargeLanguageModelMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<DeleteLargeLanguageModelMutation, DeleteLargeLanguageModelMutationVariables>(DeleteLargeLanguageModelDocument, options);
}
export type DeleteLargeLanguageModelMutationHookResult = ReturnType<typeof useDeleteLargeLanguageModelMutation>;
export type DeleteLargeLanguageModelMutationResult = Apollo.MutationResult<DeleteLargeLanguageModelMutation>;
export type DeleteLargeLanguageModelMutationOptions = Apollo.BaseMutationOptions<DeleteLargeLanguageModelMutation, DeleteLargeLanguageModelMutationVariables>;
export const MonitoringEventsDocument = gql`
query MonitoringEvents($field: EventSortable, $ordering: String) {
event(sortBy: $field, sortType: $ordering, from: 0, size: 10) {
Expand Down Expand Up @@ -14222,4 +14304,4 @@ export function useCreateYouTubeDataSourceMutation(baseOptions?: Apollo.Mutation
export type CreateYouTubeDataSourceMutationHookResult = ReturnType<typeof useCreateYouTubeDataSourceMutation>;
export type CreateYouTubeDataSourceMutationResult = Apollo.MutationResult<CreateYouTubeDataSourceMutation>;
export type CreateYouTubeDataSourceMutationOptions = Apollo.BaseMutationOptions<CreateYouTubeDataSourceMutation, CreateYouTubeDataSourceMutationVariables>;
// Generated on 2024-08-07T14:43:22+02:00
// Generated on 2024-08-07T15:32:59+02:00

0 comments on commit 89d374c

Please sign in to comment.