-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Adding Docs for resources #18980
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
Adding Docs for resources #18980
Conversation
This reverts commit 726012e.
|
Oops, pushed also ElevenLabs to this branch, I reverted it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a first pass
| A simple example can be: | ||
|
|
||
| ```python | ||
| from llama_index.core.workflows.resource import Resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| from llama_index.core.workflows.resource import Resource | |
| from llama_index.core.workflow.resource import Resource |
| return Memory.from_defaults("user_id_123", token_limit=60000) | ||
|
|
||
|
|
||
| class CustomStartEvent(StartEvent): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a standard StartEvent to reduce the size of the example?
| ``` | ||
| ## Resources | ||
|
|
||
| Resources are external dependencies that you can equip the steps of your workflows with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use something like "Resources are external dependencies you can inject into steps of a workflow" to convey the "dependency injection" concept.
| return StopEvent(result="Messages put into memory") | ||
| ``` | ||
|
|
||
| `Resource` here acts like an executor for the function: once you run the steps, if they have resources declared with them, the factory function declared within `Resource` gets executed and turned into the component that it is supposed to represent as specified in the type annotation (in the example above, a Memory object). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simplify, something along these lines:
The type of a resource must be declared with Annotated, and Resource is responsible for providing the actual instance at runtime by invoking the factory function get_memory. The return type of get_memory must be consistent with the one declared in the annotation, a Memory object in the example above.
|
|
||
| `Resource` here acts like an executor for the function: once you run the steps, if they have resources declared with them, the factory function declared within `Resource` gets executed and turned into the component that it is supposed to represent as specified in the type annotation (in the example above, a Memory object). | ||
|
|
||
| If you run the workflow, you will also notice that the resource is shared among steps: this behavior can be changed by passing `Resource(..., cache=False)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be more direct:
"Resources are shared among steps of a workflow, and Resource will invoke the factory function only once. In case this is not the desired behaviour, passing cache=False to Resource will inject different resource objects in different steps, inoking the factory function as many times.
Description
Adding docs for Workflow resources.