Skip to content

Commit 53fbb69

Browse files
[edtior][client] 2/n clear outputs functionality (#791)
[edtior][client] 2/n clear outputs functionality added a button that clears all outputs. - added an action - call to server api ## Testplan - Run prompt - validate config has an output - clear outputs - validate config cleared outputs. https://github.com/lastmile-ai/aiconfig/assets/141073967/f1622528-5a77-49cd-80a3-581520229a7f
2 parents e533c7a + c017b08 commit 53fbb69

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

python/src/aiconfig/editor/client/src/Editor.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export default function Editor() {
6868
});
6969
}, []);
7070

71+
const clearOutputs = useCallback(async () => {
72+
return await ufetch.post(ROUTE_TABLE.CLEAR_OUTPUTS, {
73+
});
74+
}, []);
75+
7176
const runPrompt = useCallback(
7277
async (
7378
promptName: string,
@@ -153,6 +158,7 @@ export default function Editor() {
153158
const callbacks: AIConfigCallbacks = useMemo(
154159
() => ({
155160
addPrompt,
161+
clearOutputs,
156162
deletePrompt,
157163
getModels,
158164
getServerStatus,
@@ -166,6 +172,7 @@ export default function Editor() {
166172
}),
167173
[
168174
addPrompt,
175+
clearOutputs,
169176
deletePrompt,
170177
getModels,
171178
getServerStatus,

python/src/aiconfig/editor/client/src/components/EditorContainer.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Text,
99
Tooltip,
1010
Alert,
11+
Group,
1112
} from "@mantine/core";
1213
import { Notifications, showNotification } from "@mantine/notifications";
1314
import {
@@ -71,11 +72,8 @@ type RunPromptStreamEvent =
7172
export type RunPromptStreamCallback = (event: RunPromptStreamEvent) => void;
7273

7374
export type AIConfigCallbacks = {
74-
addPrompt: (
75-
promptName: string,
76-
prompt: Prompt,
77-
index: number
78-
) => Promise<{ aiconfig: AIConfig }>;
75+
addPrompt: (promptName: string, prompt: Prompt, index: number) => Promise<{ aiconfig: AIConfig }>;
76+
clearOutputs: () => Promise<{ aiconfig: AIConfig }>;
7977
deletePrompt: (promptName: string) => Promise<void>;
8078
getModels: (search: string) => Promise<string[]>;
8179
getServerStatus?: () => Promise<{ status: "OK" | "ERROR" }>;
@@ -543,6 +541,26 @@ export default function EditorContainer({
543541
[deletePromptCallback, dispatch]
544542
);
545543

544+
const clearOutputsCallback = callbacks.clearOutputs;
545+
const onClearOutputs = useCallback(
546+
async () => {
547+
dispatch({
548+
type: "CLEAR_OUTPUTS",
549+
});
550+
try {
551+
await clearOutputsCallback();
552+
} catch (err: unknown) {
553+
const message = (err as RequestCallbackError).message ?? null;
554+
showNotification({
555+
title: "Error clearing outputs",
556+
message,
557+
color: "red",
558+
});
559+
}
560+
},
561+
[clearOutputsCallback, dispatch]
562+
);
563+
546564
const runPromptCallback = callbacks.runPrompt;
547565

548566
const onRunPrompt = useCallback(
@@ -775,6 +793,11 @@ export default function EditorContainer({
775793
)}
776794
<Container maw="80rem">
777795
<Flex justify="flex-end" mt="md" mb="xs">
796+
<Group>
797+
<Button loading={undefined} onClick={onClearOutputs} size="xs" variant="gradient">
798+
Clear Outputs
799+
</Button>
800+
778801
<Tooltip
779802
label={isDirty ? "Save changes to config" : "No unsaved changes"}
780803
>
@@ -789,6 +812,7 @@ export default function EditorContainer({
789812
Save
790813
</Button>
791814
</Tooltip>
815+
</Group>
792816
</Flex>
793817
<ConfigNameDescription
794818
name={aiconfigState.name}

python/src/aiconfig/editor/client/src/components/aiconfigReducer.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type AIConfigReducerAction =
1010

1111
export type MutateAIConfigAction =
1212
| AddPromptAction
13+
| ClearOutputsAction
1314
| DeletePromptAction
1415
| RunPromptAction
1516
| SetDescriptionAction
@@ -34,6 +35,10 @@ export type AddPromptAction = {
3435
prompt: ClientPrompt;
3536
};
3637

38+
export type ClearOutputsAction = {
39+
type: "CLEAR_OUTPUTS";
40+
};
41+
3742
export type DeletePromptAction = {
3843
type: "DELETE_PROMPT";
3944
id: string;
@@ -215,6 +220,29 @@ export default function aiconfigReducer(
215220
case "ADD_PROMPT_AT_INDEX": {
216221
return reduceInsertPromptAtIndex(dirtyState, action.index, action.prompt);
217222
}
223+
case "CLEAR_OUTPUTS": {
224+
const prompts = state.prompts.map((prompt) => {
225+
if (prompt.outputs) {
226+
return {
227+
...prompt,
228+
outputs: undefined
229+
}
230+
} else {
231+
return prompt;
232+
}
233+
});
234+
235+
236+
for (const prompt of prompts) {
237+
if (prompt.outputs) {
238+
delete prompt.outputs;
239+
}}
240+
241+
return {
242+
...dirtyState,
243+
prompts,
244+
};
245+
}
218246
case "DELETE_PROMPT": {
219247
return {
220248
...dirtyState,

python/src/aiconfig/editor/client/src/utils/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const API_ENDPOINT = `${HOST_ENDPOINT}/api`;
1010

1111
export const ROUTE_TABLE = {
1212
ADD_PROMPT: urlJoin(API_ENDPOINT, "/add_prompt"),
13+
CLEAR_OUTPUTS: urlJoin(API_ENDPOINT, "/clear_outputs"),
1314
DELETE_PROMPT: urlJoin(API_ENDPOINT, "/delete_prompt"),
1415
SAVE: urlJoin(API_ENDPOINT, "/save"),
1516
SET_DESCRIPTION: urlJoin(API_ENDPOINT, "/set_description"),

0 commit comments

Comments
 (0)