AI / Apache Burr Interview questions
What is MapActionsAndStates used for?
MapActionsAndStates runs the full cartesian product of a generator of actions and a generator of states — every action combined with every state — and it is actually the base class that both MapStates and MapActions are built on top of.
class TestModelsOverPrompts(MapActionsAndStates): def actions(self, state, context, inputs): for a in [query_llm.bind(model="gpt-4").with_name("gpt_4_answer"), query_llm.bind(model="o1").with_name("o1_answer")]: yield a def states(self, state, context, inputs): for prompt in ["...", "..."]: yield state.update(prompt=prompt) def reduce(self, state, states): return state.update(all_llm_outputs=[ {"output": s["llm_output"], "model": s["model"], "prompt": s["prompt"]} for s in states ])
Use it when you want to try, say, three prompts against three different models — nine sub-applications in total — rather than varying just one axis at a time. Because every combination becomes its own sub-application, it’s recommended you track which state/action produced each result using values you stash in state itself (like model and prompt above), since they don’t come back automatically labeled.
More Related questions...