compass.extraction.tree.AsyncDecisionTree#
- class AsyncDecisionTree(graph)[source]#
Bases:
DecisionTree
Async class to traverse a directed graph of LLM prompts
Nodes of this tree are prompts, and edges are transitions between prompts based on conditions being met in the LLM response
- Purpose:
Represent a series of prompts that can be used in sequence to extract values of interest from text.
- Responsibilities:
Store all prompts used to extract a particular ordinance value from text.
Track relationships between the prompts (i.e. which prompts is used first, which prompt is used next depending on the output of the previous prompt, etc.) using a directed acyclic graph.
- Key Relationships:
Inherits from
DecisionTree
to addasync
capabilities. Uses aChatLLMCaller
for LLm queries.
- Parameters:
graph (
nx.DiGraph
) – Directed acyclic graph where nodes are LLM prompts and edges are logical transitions based on the response. Must have high-level graph attribute “chat_llm_caller” which is a ChatLLMCaller instance. Nodes should have attribute “prompt” which can have {format} named arguments that will be filled from the high-level graph attributes. Edges can have attribute “condition” that is a callable to be executed on the LLM response text. An edge from a node without a condition acts as an “else” statement if no other edge conditions are satisfied. A single edge from node to node does not need a condition.
Methods
async_call_node
(node0)Call the LLM
async_run
([node0])Traverse the decision tree starting at the input node
call_node
(node_name)Call the LLM with the prompt from the input node and search the successor edges for a valid transition condition
run
([node0])Traverse the decision tree starting at the input node.
Attributes
Get a printout of the full conversation with the LLM
Get the ApiBase object.
ChatLLMCaller instance for this tree
Get the networkx graph object
Get a record of the nodes traversed in the tree
Get a list of the conversation messages with the LLM
- property chat_llm_caller#
ChatLLMCaller instance for this tree
- Type:
- async async_call_node(node0)[source]#
Call the LLM
The chat will start with the prompt from the input node and will search the successor edges for a valid transition condition.
- async async_run(node0='init')[source]#
Traverse the decision tree starting at the input node
- Parameters:
node0 (
str
) – Name of starting node in the graph. This is typically called “init”.- Returns:
out (
str | None
) – Final response from LLM at the leaf node orNone
if anAttributeError
was raised during execution.
- property api#
Get the ApiBase object.
- Returns:
ApiBase
- call_node(node_name)#
Call the LLM with the prompt from the input node and search the successor edges for a valid transition condition
- property graph#
Get the networkx graph object
- Returns:
nx.DiGraph