Skip to main content

🦌MergeAnswersNode Module

The MergeAnswersNode module implements a node responsible for merging the answers from multiple graph instances into a single answer.

Classes

MergeAnswersNode

MergeAnswersNode is a node responsible for merging the answers from multiple graph instances into a single answer.

Attributes

  • llm_model: An instance of a language model client, configured for generating answers.
  • verbose (bool): A flag indicating whether to show print statements during execution.

Methods

  • __init__(self, input: str, output: List[str], node_config: Optional[dict] = None, node_name: str = "MergeAnswers")

    • Initializes the MergeAnswersNode with a language model client and a node name.
    • Args:
      • input (str): Boolean expression defining the input keys needed from the state.
      • output (List[str]): List of output keys to be updated in the state.
      • node_config (dict, optional): Additional configuration for the node. Defaults to None.
      • node_name (str, optional): The unique identifier name for the node. Defaults to "MergeAnswers".
  • execute(self, state: dict) -> dict

    • Executes the node's logic to merge the answers from multiple graph instances into a single answer.
    • Args:
      • state (dict): The current state of the graph. The input keys will be used to fetch the correct data from the state.
    • Returns:
      • dict: The updated state with the output key containing the generated answer.

Example Usage

Here is an example of how to use the MergeAnswersNode class:

from merge_answers_node import MergeAnswersNode

# Define a MergeAnswersNode
merge_answers_node = MergeAnswersNode(
input="user_prompt, website_contents",
output=["merged_answer"],
node_config={"llm_model": llm_model},
node_name="MergeAnswers"
)

# Define the state
state = {
"user_prompt": "What are the advantages of renewable energy?",
"website_contents": ["Advantages of renewable energy: ...", "Renewable energy is beneficial because ..."],
}

# Execute the MergeAnswersNode
state = merge_answers_node.execute(state)

# Retrieve the merged answer from the state
merged_answer = state["merged_answer"]

print(f"Merged Answer: {merged_answer}")