Skip to content

Commit

Permalink
Merge STOP_STREAMING event into RUN_PROMPT_SUCCESS (lastmile-ai#928)
Browse files Browse the repository at this point in the history
Merge STOP_STREAMING event into RUN_PROMPT_SUCCESS

I just feel it makes a bit of sense to merge these two events together.
I think this will be the final refacotring change I do

I also:

1. Changed the `id` fields to `promptId` to be more explicit
2. Centralized logic for setting the ClientAIConfig into a
`setRunningPromptId` function
3. Re-arranged the action cases in the aiconfigReducer switch to have
the run actions together, as well as save success at the end

## Test Plan
Everything still works as usual for streaming and non-streaming. Same
video as the PRs earlier in this stack

---
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with
[ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/928).
* __->__ lastmile-ai#928
* lastmile-ai#926
* lastmile-ai#925
* lastmile-ai#924
* lastmile-ai#922
* lastmile-ai#921
* lastmile-ai#920
* lastmile-ai#919
* lastmile-ai#918
* lastmile-ai#917
  • Loading branch information
rossdanlm authored Jan 15, 2024
2 parents 3383c6b + 799385a commit a6e810b
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,14 @@ export default function EditorContainer({
dispatch({
// This sets the isRunning and runningPromptId flags
type: "RUN_PROMPT_START",
id: promptId,
promptId,
cancellationToken,
});

const onPromptError = (message: string | null) => {
dispatch({
type: "RUN_PROMPT_ERROR",
id: promptId,
promptId,
message: message ?? undefined,
});

Expand Down Expand Up @@ -642,22 +642,21 @@ export default function EditorContainer({
if (event.type === "output_chunk") {
dispatch({
type: "STREAM_OUTPUT_CHUNK",
id: promptId,
promptId,
output: event.data,
});
} else if (event.type === "aiconfig_chunk") {
dispatch({
type: "STREAM_AICONFIG_CHUNK",
config: event.data,
cancellationToken,
});
} else if (event.type === "stop_streaming") {
// Pass this event at the end of streaming to signal
// that the prompt is done running and we're ready
// to reset the ClientAIConfig to a non-running state
dispatch({
type: "STOP_STREAMING",
id: promptId,
type: "RUN_PROMPT_SUCCESS",
promptId,
});
}
},
Expand All @@ -671,8 +670,7 @@ export default function EditorContainer({
// Reset the aiconfig to the state before we started running the prompt
dispatch({
type: "RUN_PROMPT_CANCEL",
id: promptId,
cancellationToken,
promptId,
// Returned config output is reset to before running RUN_PROMPT
config: event.data.data,
});
Expand Down Expand Up @@ -700,7 +698,7 @@ export default function EditorContainer({
if (serverConfigResponse?.aiconfig) {
dispatch({
type: "RUN_PROMPT_SUCCESS",
id: promptId,
promptId,
config: serverConfigResponse.aiconfig,
});
}
Expand Down
28 changes: 10 additions & 18 deletions python/src/aiconfig/editor/client/src/reducers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ export type MutateAIConfigAction =
// Action that can occur when user runs a prompt
export type RunPromptAction =
| RunPromptStartAction
| RunPromptCancelAction
| RunPromptErrorAction
| RunPromptSuccessAction
| StreamAIConfigChunkAction
| StreamOutputChunkAction
| StopStreamingAction;
| RunPromptCancelAction
| RunPromptErrorAction
| RunPromptSuccessAction;

// Actions that appear when called via ConsolidateAIConfigAction
export type ConsolidateAIConfigSubAction =
Expand Down Expand Up @@ -106,47 +105,40 @@ export type UpdateGlobalParametersAction = {
// Run Prompt Actions
export type RunPromptStartAction = {
type: "RUN_PROMPT_START";
id: string;
cancellationToken?: string;
promptId: string;
isRunning?: boolean;
cancellationToken?: string;
};

export type RunPromptCancelAction = {
type: "RUN_PROMPT_CANCEL";
id: string;
promptId: string;
config: AIConfig;
cancellationToken?: string;
};

export type RunPromptErrorAction = {
type: "RUN_PROMPT_ERROR";
id: string;
promptId: string;
message?: string;
};

export type RunPromptSuccessAction = {
type: "RUN_PROMPT_SUCCESS";
id: string;
config: AIConfig;
promptId: string;
config?: AIConfig;
};

export type StreamAIConfigChunkAction = {
type: "STREAM_AICONFIG_CHUNK";
config: AIConfig;
cancellationToken?: string;
};

export type StreamOutputChunkAction = {
type: "STREAM_OUTPUT_CHUNK";
id: string;
promptId: string;
output: Output;
};

export type StopStreamingAction = {
type: "STOP_STREAMING";
id: string;
};

// Save Action --> In future, probably group this with other non-mutate
// actions like setting logging preferences, share button action etc
export type SaveConfigSuccessAction = {
Expand Down
Loading

0 comments on commit a6e810b

Please sign in to comment.