Compare commits

...

3 Commits

Author SHA1 Message Date
Alex Yang 35a9638014 docs: update 2024-11-13 18:08:33 -08:00
Alex Yang ea92b6986d chore: update changeset 2024-11-13 01:15:28 -08:00
Alex Yang 17f9022d22 fix: output event check (#1475) 2024-11-13 00:46:35 -08:00
4 changed files with 31 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/workflow": patch
---
fix: output event check
+6
View File
@@ -62,6 +62,12 @@ const config = {
({
// Replace with your project's social card
image: "img/favicon.png", // TODO change this
announcementBar: {
id: "migrate_to_next",
content:
'We are migrating to Next.js based documentation. Check it out <a href="https://ts.llamaindex.ai">here</a>!',
isCloseable: false,
},
navbar: {
title: "LlamaIndex.TS",
logo: {
+5 -4
View File
@@ -397,10 +397,11 @@ export class WorkflowContext<Start = string, Stop = string, Data = unknown>
);
}
const outputs = outputsMap.get(step) ?? [];
const outputEvents = flattenEvents(outputs, [
nextEvent,
]);
if (outputEvents.length !== outputs.length) {
if (
!outputs.some(
(output) => nextEvent.constructor === output,
)
) {
if (this.#strict) {
const error = Error(
`Step ${step.name} returned an unexpected output event ${nextEvent}`,
+15
View File
@@ -794,6 +794,21 @@ describe("workflow event loop", () => {
}
`);
});
test("workflow multiple output", async () => {
const myFlow = new Workflow<unknown, string, string>({ verbose: true });
myFlow.addStep(
{
inputs: [StartEvent<string>],
outputs: [StopEvent<string>, StopEvent<string>],
},
async (_context, ev) => {
return new StopEvent(`Hello ${ev.data}!`);
},
);
const result = await myFlow.run("world").strict();
expect(result.data).toBe("Hello world!");
});
});
describe("snapshot", async () => {