Skip to content

Commit 5209ff9

Browse files
authored
allow parallel map operations to be loaded in the UI (#434)
1 parent b1146e4 commit 5209ff9

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

website/src/components/PipelineGui.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,8 @@ const PipelineGUI: React.FC = () => {
278278

279279
if (result.should_optimize) {
280280
toast({
281-
title: `Hey! Consider decomposing ${
282-
operations[operations.length - 1].name
283-
}`,
281+
title: `Hey! Consider decomposing ${operations[operations.length - 1].name
282+
}`,
284283
description: (
285284
<span
286285
className="cursor-pointer text-blue-500 hover:text-blue-700"
@@ -364,21 +363,21 @@ const PipelineGUI: React.FC = () => {
364363
id: id || uuidv4(),
365364
llmType:
366365
type === "map" ||
367-
type === "reduce" ||
368-
type === "resolve" ||
369-
type === "filter" ||
370-
type === "parallel_map" ||
371-
type === "rank" ||
372-
type === "extract"
366+
type === "reduce" ||
367+
type === "resolve" ||
368+
type === "filter" ||
369+
type === "parallel_map" ||
370+
type === "rank" ||
371+
type === "extract"
373372
? "LLM"
374373
: "non-LLM",
375374
type: type,
376375
name: name || "Untitled Operation",
377376
prompt: prompt,
378377
output: output
379378
? {
380-
schema: schemaDictToItemSet(output.schema),
381-
}
379+
schema: schemaDictToItemSet(output.schema),
380+
}
382381
: undefined,
383382
validate: validate,
384383
gleaning: gleaning,
@@ -502,7 +501,9 @@ const PipelineGUI: React.FC = () => {
502501
};
503502
await restoreFromYAML(fileToUpload);
504503
} catch (error) {
504+
const errorMessage = error instanceof Error ? error.message : String(error);
505505
console.error("Error handling file upload:", error);
506+
console.error("Upload error details:", errorMessage);
506507
}
507508
}
508509
};
@@ -813,9 +814,8 @@ const PipelineGUI: React.FC = () => {
813814
</div>
814815

815816
<div
816-
className={`flex items-center gap-2 transition-transform duration-200 origin-left ${
817-
isLeftSideCollapsed ? "scale-x-0 w-0" : "scale-x-100"
818-
}`}
817+
className={`flex items-center gap-2 transition-transform duration-200 origin-left ${isLeftSideCollapsed ? "scale-x-0 w-0" : "scale-x-100"
818+
}`}
819819
>
820820
<div className="flex items-center gap-2 flex-shrink-0">
821821
<Popover>

website/src/hooks/useRestorePipeline.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ interface YAMLOperation {
1515
type: string;
1616
name?: string;
1717
prompt?: string;
18+
prompts?: Array<{
19+
name?: string;
20+
prompt: string;
21+
output_keys: string[];
22+
model?: string;
23+
gleaning?: {
24+
num_rounds: number;
25+
validation_prompt: string;
26+
model?: string;
27+
};
28+
}>;
1829
output?: {
1930
schema: Record<string, unknown>;
2031
};
@@ -84,6 +95,7 @@ export const useRestorePipeline = ({
8495
type,
8596
name,
8697
prompt,
98+
prompts, // For parallel_map operations
8799
output,
88100
validate,
89101
sample,
@@ -130,25 +142,41 @@ export const useRestorePipeline = ({
130142
: [op.document_keys];
131143
}
132144

145+
// If the operation type is 'parallel_map', preserve the prompts array
146+
if (type === "parallel_map") {
147+
if (prompts) {
148+
stringifiedKwargs.prompts = prompts;
149+
} else if (stringifiedKwargs.prompts) {
150+
// Handle case where prompts might have been stringified
151+
try {
152+
if (typeof stringifiedKwargs.prompts === "string") {
153+
stringifiedKwargs.prompts = JSON.parse(stringifiedKwargs.prompts);
154+
}
155+
} catch (e) {
156+
console.error("Error parsing stringified prompts:", e);
157+
}
158+
}
159+
}
160+
133161
return {
134162
id: id || uuidv4(),
135163
llmType:
136164
type === "map" ||
137-
type === "reduce" ||
138-
type === "resolve" ||
139-
type === "filter" ||
140-
type === "parallel_map"
165+
type === "reduce" ||
166+
type === "resolve" ||
167+
type === "filter" ||
168+
type === "parallel_map"
141169
? "LLM"
142170
: "non-LLM",
143171
type: type as Operation["type"],
144172
name: name || "Untitled Operation",
145173
prompt,
146174
output: output
147175
? {
148-
schema: schemaDictToItemSet(
149-
output.schema as Record<string, string>
150-
),
151-
}
176+
schema: schemaDictToItemSet(
177+
output.schema as Record<string, string>
178+
),
179+
}
152180
: undefined,
153181
validate,
154182
sample,
@@ -205,10 +233,12 @@ export const useRestorePipeline = ({
205233

206234
resolve();
207235
} catch (error) {
236+
const errorMessage = error instanceof Error ? error.message : String(error);
208237
console.error("Error parsing YAML:", error);
238+
console.error("Error details:", errorMessage);
209239
toast({
210240
title: "Error",
211-
description: "Failed to parse the uploaded YAML file.",
241+
description: `Failed to parse the uploaded YAML file: ${errorMessage}`,
212242
variant: "destructive",
213243
});
214244
reject(error);

0 commit comments

Comments
 (0)