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

Merged
merged 26 commits into from
Dec 7, 2024
Merged

Imperative API #2378

merged 26 commits into from
Dec 7, 2024

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

    @entrypoint(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 force-pushed the nc/8nov/send-future branch from 3e0395b to bd255c2 Compare November 14, 2024 22:59
@nfcampos nfcampos changed the title Add call function to call a node and get a future & Imperative API Imperative API Nov 20, 2024
@nfcampos nfcampos force-pushed the nc/8nov/send-future branch from d1a8b53 to 3d5df68 Compare November 20, 2024 01:04
@nfcampos nfcampos force-pushed the nc/8nov/send-future branch from 2f396ac to 5fdba64 Compare November 26, 2024 00:13
@nfcampos nfcampos force-pushed the nc/8nov/send-future branch 2 times, most recently from c9839f1 to a4a8c54 Compare December 4, 2024 23:18
- 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
@nfcampos nfcampos force-pushed the nc/8nov/send-future branch from a4a8c54 to 2fa2469 Compare December 4, 2024 23:39
@nfcampos nfcampos marked this pull request as ready for review December 7, 2024 19:48
@nfcampos nfcampos merged commit 1af1911 into main Dec 7, 2024
59 checks passed
@nfcampos nfcampos deleted the nc/8nov/send-future branch December 7, 2024 19:48
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