Pass useful state from step to step
You make dependencies visible by passing state between sequential nodes. Use map() for ordinary transformations that do not need another model call.
Unit example (nearest native match)
See the idea in context
mermaid = '''flowchart TD
%%ax classify: request:string -> route:class "support, sales"
classify{route}
'''
program = flow(mermaid)
print(program) # canonical portable MermaidRun itIn your own project
pip install axllm
import os
from axllm import ai, ax
llm = ai('openai', api_key=os.environ['OPENAI_API_KEY'])
classify = ax('review:string -> sentiment:class "positive, negative, neutral"')
result = classify.forward(llm, {
'review': 'Useful and boring in the best way.',
})
print('sentiment:', result['sentiment'])Set OPENAI_APIKEY in your environment before running provider-backed code.
From a clone of the ax repo:
npm run example -- python src/examples/python/flows/branch-flow.pyActive practice
Answer 2 in a row to learn this · attempt 1