Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: workflow API #1264

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

himself65
Copy link
Member

@himself65 himself65 commented Sep 26, 2024

See discussion: #1261

checklist for Oct 1 - 5

  • validation API
  • more example
    • websocket
    • http
    • database persistence
  • update document

Copy link

changeset-bot bot commented Sep 26, 2024

🦋 Changeset detected

Latest commit: c021076

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@llamaindex/core Minor
@llamaindex/cloud Major
@llamaindex/community Patch
llamaindex Patch
@llamaindex/ollama Patch
@llamaindex/openai Patch
@llamaindex/llama-parse-browser-test Patch
docs Patch
@llamaindex/autotool Patch
@llamaindex/experimental Patch
@llamaindex/cloudflare-worker-agent-test Patch
@llamaindex/nextjs-edge-runtime-test Patch
@llamaindex/next-node-runtime-test Patch
@llamaindex/next-agent-test Patch
@llamaindex/autotool-01-node-example Patch
@llamaindex/autotool-02-next-example Patch
@llamaindex/groq Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Sep 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
llama-index-ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 2, 2024 11:32pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
llamaindexts-doc-experimental ⬜️ Ignored (Inspect) Visit Preview Oct 2, 2024 11:32pm

);
});
// fixme: design a better API for validation
// test("workflow validation", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is seems like a helper function for in/out Event relationship.

But should we check this in runtime, instead of top of the calling run

@himself65 himself65 changed the title refactor: reimplement Workflow API fix: workflow handling parallel/async event Sep 26, 2024
Copy link

pkg-pr-new bot commented Sep 26, 2024

Open in Stackblitz

@llamaindex/autotool

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/autotool@1264

@llamaindex/community

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/community@1264

@llamaindex/cloud

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/cloud@1264

@llamaindex/core

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/core@1264

@llamaindex/env

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/env@1264

@llamaindex/experimental

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/experimental@1264

llamaindex

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/llamaindex@1264

@llamaindex/wasm-tools

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/wasm-tools@1264

commit: 5d5a170

}

set(key: string, value: any): void {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the globals here. because I think it's not really used in the code. Im thinking wheter to support this by adding extend syntax

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see globals removed? But in any case, the get/set api (which stores stuff into globals) is a pretty useful api for sharing data between steps

@himself65 himself65 changed the title fix: workflow handling parallel/async event refactor: workflow API Sep 28, 2024
msg: `Writing app using this specification: ${truncate(spec)}`,
}),
);
console.log(`Writing app using this specification: ${truncate(spec)}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himself65 how would you do context.writeEventToStream now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can expose sendEvent to context api, but I'm not sure if it's oky for seriazlize

return new StopEvent({ result: code });
}

return new ReviewEvent({ review, code });
};

const codeAgent = new Workflow({ validate: true });
const codeAgent = new Workflow().with(kvContext);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

storing a map seems to be the default use case for me using workflow, how about using SimpleKVStore per default as Context? Then it would more behave like the old code

return new StopEvent({ result: code });
}

return new ReviewEvent({ review, code });
};

const codeAgent = new Workflow({ validate: true });
const codeAgent = new Workflow().with(kvContext);
codeAgent.addStep(StartEvent, architect, { outputs: CodeEvent });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logan-markewich @himself65 if we change the API, we might also allow this instead:

Suggested change
codeAgent.addStep(StartEvent, architect, { outputs: CodeEvent });
codeAgent.addStep(architect, { inputs: StartEvent, outputs: CodeEvent });

context: Context,
ev: AnalysisEvent | CritiqueEvent,
_: unknown,
...events: [AnalysisEvent, CritiqueEvent]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this always awaits now the events in the order given in the events array?
@logan-markewich @himself65 is this something we want?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. how do we trigger to the user now that we haven't received all events yet? we might want to do that

@@ -15,32 +14,28 @@ export class JokeEvent extends WorkflowEvent<{ joke: string }> {}
export class CritiqueEvent extends WorkflowEvent<{ critique: string }> {}
export class AnalysisEvent extends WorkflowEvent<{ analysis: string }> {}

const generateJoke = async (_context: Context, ev: StartEvent) => {
const generateJoke = async (_: unknown, ev: StartEvent) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't like this unknown a lot, i would prefer having a Context even if it's not used (see above that we might want to use a kv store as default)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we do this example?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we do now the validation?

yield* context.streamEvents();
// This method is used to create a new instance of Workflow with the same steps
// though this API we follow functional programming principles
private static from<Start, Stop, ContextData extends object, Checked>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

* if you want stop immediately once reach a StopEvent, you should handle it in the other side.
* @private
*/
#createStreamEvents(): AsyncIterableIterator<WorkflowEvent> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. can we reduce the complexity of this function?
  2. how can we implement to limit the number of promises per step - in python, that's: @step(num_workers=4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants