Skip to main content

🐼 GenerateAnswerNodeCSV Module

The GenerateAnswerCSVNode module implements a node responsible for generating an answer using a language model (LLM) based on the user's input and the content extracted from a webpage. It constructs a prompt from the user's input and the scraped content, feeds it to the LLM, and parses the LLM's response to produce an answer.

Classes​

GenerateAnswerCSVNode​

GenerateAnswerCSVNode is a node responsible for generating an answer using a language model (LLM) based on the user's input and the content extracted from a webpage.

Attributes​

  • llm_model: An instance of a language model client, configured for generating answers.
  • node_name (str): The unique identifier name for the node, defaulting to "GenerateAnswerNodeCsv".
  • node_type (str): The type of the node, set to "node" indicating a standard operational node.

Methods​

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

    • Initializes the GenerateAnswerNodeCsv 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 (Optional[dict], optional): Additional configuration for the node.
      • node_name (str, optional): The unique identifier name for the node. Defaults to "GenerateAnswerNodeCsv".
  • execute(self, state)

    • Generates an answer by constructing a prompt from the user's input and the scraped content, querying the language model, and parsing its response.
    • Args:
      • state (dict): The current state of the graph, expected to contain 'user_input' and optionally 'parsed_document' or 'relevant_chunks' within 'keys'.
    • Returns:
      • dict: The updated state with the 'answer' key containing the generated answer.
    • Raises:
      • KeyError: If 'user_input' or 'document' is not found in the state, indicating that the necessary information for generating an answer is missing.

Example Usage​

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

from generate_answer_csv_node import GenerateAnswerCSVNode

# Define a generate answer node
generate_answer_node = GenerateAnswerCSVNode(
input="user_input & document",
output=["answer"]
)

# Define the state
state = {"user_input": "What are the attractions in Chioggia?", "document": [document1, document2]}

# Execute the generate answer node
state = generate_answer_node.execute(state)

# Retrieve the generated answer from the state
answer = state["answer"]

print(f"Generated Answer: {answer}")