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

Imperative API #2378

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

Imperative API #2378

wants to merge 15 commits into from

Conversation

nfcampos
Copy link
Contributor

@nfcampos nfcampos commented Nov 8, 2024

  • Whereas Send is for fire-and-forget type of calls, new call and acall functions are for flows where you want to wait for the node to finish before doing something else
  • Because we return regular python future objects (concurrent.futures.Future or asyncio.Future) all the python primitives for working with futures work, eg. wait, gather, etc
    @task()
    def mapper(input: str) -> str:
        print(f"mapper {input}")
        return input * 2

    @imp(checkpointer=checkpointer)
    def graph(input: list[str]) -> list[str]:
        futures = [mapper(i) for i in input]
        mapped = [f.result() for f in futures]
        return mapped

    thread1 = {"configurable": {"thread_id": "1"}}
    assert graph.invoke(["0", "1"], thread1) == ["00", "11"]

@nfcampos nfcampos marked this pull request as draft November 8, 2024 21:06
@nfcampos nfcampos force-pushed the nc/8nov/send-future branch 2 times, most recently from 6fdbbc6 to 3e0395b Compare November 11, 2024 22:18
@nfcampos nfcampos changed the title Add call function to call a node and get a future Add call function to call a node and get a future & Imperative API Nov 12, 2024
Base automatically changed from nc/4nov/send-eager to main November 13, 2024 21:39
@nfcampos nfcampos changed the title Add call function to call a node and get a future & Imperative API Imperative API Nov 20, 2024
- Whereas Send is for fire-and-forget type of calls, new `call` and `acall` functions are for flows where you want to wait for the node to finish before doing something else
- Because we return regular python future objects (concurrent.futures.Future or asyncio.Future) all the python primitives for working with futures work, eg. wait, gather, etc
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.

1 participant