Skip to content

Commit

Permalink
support complex types
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashankar committed Oct 28, 2024
1 parent 1ec7831 commit aa9a8a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 43 deletions.
22 changes: 11 additions & 11 deletions website/src/app/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function generatePipelineConfig(
operation_id: string,
name: string,
sample_size: number | null,
optimize: boolean = false,
optimize: boolean = false
) {
const homeDir = os.homedir();

Expand Down Expand Up @@ -53,7 +53,7 @@ export function generatePipelineConfig(
if (item.type === "list") {
if (!item.subType) {
throw new Error(
`List type must specify its elements for field: ${item.key}`,
`List type must specify its elements for field: ${item.key}`
);
}
const subType =
Expand All @@ -65,17 +65,17 @@ export function generatePipelineConfig(
console.log(item);
if (!item.subType) {
throw new Error(
`Dict/Object type must specify its structure for field: ${item.key}`,
`Dict/Object type must specify its structure for field: ${item.key}`
);
}
const subSchema = Object.entries(item.subType).reduce(
(acc, [_, value]) => {
acc[value.key] = processSchemaItem(value as SchemaItem);
return acc;
},
{} as Record<string, string>,
{} as Record<string, string>
);
return `dict{${Object.entries(subSchema)
return `{${Object.entries(subSchema)
.map(([k, v]) => `${k}: ${v}`)
.join(", ")}}`;
} else {
Expand All @@ -89,7 +89,7 @@ export function generatePipelineConfig(
newOp.samples = JSON.parse(op.otherKwargs.samples);
} catch (e) {
console.warn(
"Failed to parse custom samples as JSON, using raw value",
"Failed to parse custom samples as JSON, using raw value"
);
}
}
Expand All @@ -102,17 +102,17 @@ export function generatePipelineConfig(
acc[item.key] = processSchemaItem(item);
return acc;
},
{},
{}
),
},
};
},
}
);

// Fetch all operations up until and including the operation_id
const operationsToRun = operations.slice(
0,
operations.findIndex((op: Operation) => op.id === operation_id) + 1,
operations.findIndex((op: Operation) => op.id === operation_id) + 1
);

const pipelineConfig = {
Expand All @@ -134,14 +134,14 @@ export function generatePipelineConfig(
".docetl",
"pipelines",
"outputs",
`${name}.json`,
`${name}.json`
),
intermediate_dir: path.join(
homeDir,
".docetl",
"pipelines",
name,
"intermediates",
"intermediates"
),
},
},
Expand Down
32 changes: 0 additions & 32 deletions website/src/components/PipelineGui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,38 +426,6 @@ const PipelineGUI: React.FC = () => {
]
);

useEffect(() => {
if (lastMessage) {
if (lastMessage.type === "output") {
setTerminalOutput(lastMessage.data);
} else if (lastMessage.type === "result") {
const runCost = lastMessage.data.cost || 0;
setCost((prevCost) => prevCost + runCost);
toast({
title: "Pipeline Run Complete",
description: `The pipeline run cost $${runCost.toFixed(4)}`,
duration: 3000,
});

// Close the WebSocket connection
disconnect();

setIsLoadingOutputs(false);
} else if (lastMessage.type === "error") {
toast({
title: "Error",
description: lastMessage.data,
variant: "destructive",
});

// Close the WebSocket connection
disconnect();

setIsLoadingOutputs(false);
}
}
}, [lastMessage, setCost, setIsLoadingOutputs, setTerminalOutput]);

const handleAddOperation = (
llmType: "LLM" | "non-LLM",
type: string,
Expand Down

0 comments on commit aa9a8a9

Please sign in to comment.