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-347]: FE prompts list #546

Merged
merged 46 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9604c30
[OPIK-347]: add a prompts list page with fake data;
Nov 4, 2024
196b264
[OPIK-347]: removed unused vars;
Nov 4, 2024
fc13e09
[OPIK-347]: update the prompt page name;
Nov 4, 2024
8899bbe
[OPIK-347]: update the prompt page name;
Nov 4, 2024
f9eaca1
[OPIK-347]: eslint error fixes;
Nov 4, 2024
c01f49c
[OPIK-347]: eslint error fixes;
Nov 4, 2024
94d58cf
[OPIK-347]: remove not needed dependencies from the usecallback;
Nov 4, 2024
c4e9f02
[OPIK-347]: remove navigate;
Nov 4, 2024
afd0302
[OPIK-349]: add a prompt tab;
Nov 5, 2024
0270b30
[OPIK-349]: eslint issues;
Nov 5, 2024
9ec7d03
[OPIK-351]: finished commits tab;
Nov 5, 2024
307d652
[OPIK-351]: add a pending state to commits;
Nov 6, 2024
56295c0
[OPIK-347]: add a prompts list page with fake data;
Nov 4, 2024
4ca0b89
[OPIK-347]: removed unused vars;
Nov 4, 2024
fddbf7e
[OPIK-347]: update the prompt page name;
Nov 4, 2024
c37a7b6
[OPIK-347]: update the prompt page name;
Nov 4, 2024
eb3c866
[OPIK-347]: eslint error fixes;
Nov 4, 2024
f78a1bc
[OPIK-347]: eslint error fixes;
Nov 4, 2024
b1d3f81
[OPIK-347]: remove not needed dependencies from the usecallback;
Nov 4, 2024
e11300c
[OPIK-347]: remove navigate;
Nov 4, 2024
affdc8f
[OPIK-349]: add a prompt tab;
Nov 5, 2024
6cb04b4
[OPIK-349]: eslint issues;
Nov 5, 2024
2055579
[OPIK-351]: finished commits tab;
Nov 5, 2024
863db6b
[OPIK-351]: add a pending state to commits;
Nov 6, 2024
c5a4c4d
Merge remote-tracking branch 'origin/sasha/OPIK-347/prompts-list' int…
Nov 6, 2024
ce0943d
[OPIK-351]: fix the type;
Nov 6, 2024
1038c33
[OPIK-319]: finish the integration with the BE;
Nov 6, 2024
e78f442
[OPIK-319]: remove a comment;
Nov 6, 2024
528b63d
[OPIK-349]: add switching the commit after creation;
Nov 6, 2024
513161e
[OPIK-348]: add edit to the prompt table;
Nov 6, 2024
912756d
[OPIK-348]: remove workspace name;
Nov 6, 2024
7c6319b
[OPIK-348]: fix the comments;
Nov 6, 2024
d5c367b
[OPIK-319]: remove tag name cell;
Nov 6, 2024
d6239d1
[OPIK-319]: fix the eslint issues;
Nov 6, 2024
75f5e4c
[OPIK-319]: fix tailwind order;
Nov 6, 2024
cff5df4
[OPIK-319]: hide use this prompt button;
Nov 6, 2024
286c068
[OPIK-319]: hide the experiments tab;
Nov 6, 2024
c3a6bb2
[OPIK-319]: PR comments;
Nov 6, 2024
0753819
[OPIK-319]: update queries init logic;
Nov 6, 2024
db73595
[OPIK-319]: update the order of tailwand;
Nov 6, 2024
df064dc
[OPIK-319]: fix the tailwind issues;
Nov 6, 2024
87c7111
[OPIK-319]: remove workspace name;
Nov 6, 2024
86ad293
[OPIK-319]: fix the style;
Nov 6, 2024
8fcf155
[OPIK-319]: fix the break logic;
Nov 6, 2024
5a6a0ea
[OPIK-319]: add workspace name;
Nov 7, 2024
beb0be6
[OPIK-319]: set adding a key to the modal;
Nov 7, 2024
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
1 change: 1 addition & 0 deletions apps/opik-frontend/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const FEEDBACK_DEFINITIONS_REST_ENDPOINT =
"/v1/private/feedback-definitions/";
export const TRACES_REST_ENDPOINT = "/v1/private/traces/";
export const SPANS_REST_ENDPOINT = "/v1/private/spans/";
export const PROMPTS_REST_ENDPOINT = "/v1/private/prompts/";

export type QueryConfig<TQueryFnData, TData = TQueryFnData> = Omit<
UseQueryOptions<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AxiosError } from "axios";
import get from "lodash/get";

import api, { PROMPTS_REST_ENDPOINT } from "@/api/api";
import { useToast } from "@/components/ui/use-toast";
import { PromptVersion } from "@/types/prompts";

type UseCreatePromptVersionMutationParams = {
name: string;
template: string;
onSetActiveVersionId: (versionId: string) => void;
};

const useCreatePromptVersionMutation = () => {
const queryClient = useQueryClient();
const { toast } = useToast();

return useMutation({
mutationFn: async ({
name,
template,
}: UseCreatePromptVersionMutationParams) => {
const { data } = await api.post(`${PROMPTS_REST_ENDPOINT}versions`, {
name,
version: {
template,
},
});

return data;
},
onError: (error: AxiosError) => {
const message = get(
error,
["response", "data", "message"],
error.message,
);

toast({
title: "Error",
description: message,
variant: "destructive",
});
},
onSuccess: async (data: PromptVersion, { onSetActiveVersionId }) => {
onSetActiveVersionId(data.id);
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["prompt-versions"] });
queryClient.invalidateQueries({ queryKey: ["prompt"] });
},
});
};

export default useCreatePromptVersionMutation;
29 changes: 29 additions & 0 deletions apps/opik-frontend/src/api/prompts/usePromptById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { QueryFunctionContext, useQuery } from "@tanstack/react-query";
import api, { PROMPTS_REST_ENDPOINT, QueryConfig } from "@/api/api";
import { PromptWithLatestVersion } from "@/types/prompts";

const getPromptById = async (
{ signal }: QueryFunctionContext,
{ promptId }: UsePromptByIdParams,
) => {
const { data } = await api.get(`${PROMPTS_REST_ENDPOINT}${promptId}`, {
signal,
});

return data;
};

type UsePromptByIdParams = {
promptId: string;
};

export default function usePromptById(
params: UsePromptByIdParams,
options?: QueryConfig<PromptWithLatestVersion>,
) {
return useQuery({
queryKey: ["prompt", params],
queryFn: (context) => getPromptById(context, params),
...options,
});
}
49 changes: 49 additions & 0 deletions apps/opik-frontend/src/api/prompts/usePromptCreateMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AxiosError } from "axios";
import get from "lodash/get";

import api, { PROMPTS_REST_ENDPOINT } from "@/api/api";
import { useToast } from "@/components/ui/use-toast";
import { Prompt } from "@/types/prompts";

interface CreatePromptTemplate {
template: string;
}

type UsePromptCreateMutationParams = {
prompt: Partial<Prompt> & CreatePromptTemplate;
};

const usePromptCreateMutation = () => {
const queryClient = useQueryClient();
const { toast } = useToast();

return useMutation({
mutationFn: async ({ prompt }: UsePromptCreateMutationParams) => {
const { data } = await api.post(PROMPTS_REST_ENDPOINT, {
...prompt,
});

return data;
},

onError: (error: AxiosError) => {
const message = get(
error,
["response", "data", "message"],
error.message,
);

toast({
title: "Error",
description: message,
variant: "destructive",
});
},
onSettled: () => {
return queryClient.invalidateQueries({ queryKey: ["prompts"] });
},
});
};

export default usePromptCreateMutation;
38 changes: 38 additions & 0 deletions apps/opik-frontend/src/api/prompts/usePromptDeleteMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import get from "lodash/get";
import { useToast } from "@/components/ui/use-toast";
import api, { PROMPTS_REST_ENDPOINT } from "@/api/api";

type UsePromptDeleteMutationParams = {
promptId: string;
};

const usePromptDeleteMutation = () => {
const queryClient = useQueryClient();
const { toast } = useToast();

return useMutation({
mutationFn: async ({ promptId }: UsePromptDeleteMutationParams) => {
const { data } = await api.delete(PROMPTS_REST_ENDPOINT + promptId);
return data;
},
onError: (error) => {
const message = get(
error,
["response", "data", "message"],
error.message,
);

toast({
title: "Error",
description: message,
variant: "destructive",
});
},
onSettled: () => {
return queryClient.invalidateQueries({ queryKey: ["prompts"] });
},
});
};

export default usePromptDeleteMutation;
48 changes: 48 additions & 0 deletions apps/opik-frontend/src/api/prompts/usePromptUpdateMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AxiosError } from "axios";
import get from "lodash/get";

import api, { PROMPTS_REST_ENDPOINT } from "@/api/api";
import { useToast } from "@/components/ui/use-toast";
import { Prompt } from "@/types/prompts";

type UsePromptUpdateMutationParams = {
prompt: Partial<Prompt>;
};

const usePromptUpdateMutation = () => {
const queryClient = useQueryClient();
const { toast } = useToast();

return useMutation({
mutationFn: async ({ prompt }: UsePromptUpdateMutationParams) => {
const { id: promptId, ...restPrompt } = prompt;

const { data } = await api.put(
`${PROMPTS_REST_ENDPOINT}${promptId}`,
restPrompt,
);

return data;
},

onError: (error: AxiosError) => {
const message = get(
error,
["response", "data", "message"],
error.message,
);

toast({
title: "Error",
description: message,
variant: "destructive",
});
},
onSettled: () => {
return queryClient.invalidateQueries({ queryKey: ["prompts"] });
},
});
};

export default usePromptUpdateMutation;
32 changes: 32 additions & 0 deletions apps/opik-frontend/src/api/prompts/usePromptVersionById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { QueryFunctionContext, useQuery } from "@tanstack/react-query";
import api, { PROMPTS_REST_ENDPOINT, QueryConfig } from "@/api/api";
import { PromptVersion } from "@/types/prompts";

type UsePromptVersionByIdParams = {
versionId: string;
};

const getPromptVersionById = async (
{ signal }: QueryFunctionContext,
{ versionId }: UsePromptVersionByIdParams,
) => {
const { data } = await api.get(
`${PROMPTS_REST_ENDPOINT}versions/${versionId}`,
{
signal,
},
);

return data;
};

export default function usePromptVersionById(
params: UsePromptVersionByIdParams,
options?: QueryConfig<PromptVersion>,
) {
return useQuery({
queryKey: ["prompt-version", params],
queryFn: (context) => getPromptVersionById(context, params),
...options,
});
}
45 changes: 45 additions & 0 deletions apps/opik-frontend/src/api/prompts/usePromptVersionsById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { QueryFunctionContext, useQuery } from "@tanstack/react-query";
import api, { PROMPTS_REST_ENDPOINT, QueryConfig } from "@/api/api";
import { PromptVersion } from "@/types/prompts";

type UsePromptVersionsByIdParams = {
promptId: string;
search?: string;
page: number;
size: number;
};

type UsePromptsVersionsByIdResponse = {
content: PromptVersion[];
total: number;
};

const getPromptVersionsById = async (
{ signal }: QueryFunctionContext,
{ promptId, size, page, search }: UsePromptVersionsByIdParams,
) => {
const { data } = await api.get(
`${PROMPTS_REST_ENDPOINT}${promptId}/versions`,
{
signal,
params: {
...(search && { name: search }),
size,
page,
},
},
);

return data;
};

export default function usePromptVersionsById(
params: UsePromptVersionsByIdParams,
options?: QueryConfig<UsePromptsVersionsByIdResponse>,
) {
return useQuery({
queryKey: ["prompt-versions", params],
queryFn: (context) => getPromptVersionsById(context, params),
...options,
});
}
42 changes: 42 additions & 0 deletions apps/opik-frontend/src/api/prompts/usePromptsList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { QueryFunctionContext, useQuery } from "@tanstack/react-query";
import api, { PROMPTS_REST_ENDPOINT, QueryConfig } from "@/api/api";
import { Prompt } from "@/types/prompts";

type UsePromptsListParams = {
workspaceName: string;
search?: string;
page: number;
size: number;
};

type UsePromptsListResponse = {
content: Prompt[];
total: number;
};

const getPromptsList = async (
{ signal }: QueryFunctionContext,
{ search, size, page }: UsePromptsListParams,
) => {
const { data } = await api.get(PROMPTS_REST_ENDPOINT, {
signal,
params: {
...(search && { name: search }),
size,
page,
},
});

return data;
};

export default function usePromptsList(
params: UsePromptsListParams,
options?: QueryConfig<UsePromptsListResponse>,
) {
return useQuery({
queryKey: ["prompts", params],
queryFn: (context) => getPromptsList(context, params),
...options,
});
}
Loading
Loading