comfyui_LLM_party

1625

Available Nodes

sql_tool

Documentation for sql_tool Node

Overview

The sql_tool node is a component of the ComfyUI LLM Party project, designed to facilitate interactions between a natural language model and a SQL database. This node allows you to perform natural language queries on a database, with the underlying logic translating the query into SQL commands that fetch the requested data. It leverages OpenAI's LLMs to process and understand the natural language queries.

Functionality

The main functionality of the sql_tool node is to enable queries on a SQL database using natural language. It integrates with OpenAI's models to interpret the natural language input and interact with the database accordingly.

Inputs

The sql_tool node accepts the following inputs:

  1. db_connection_string (Required)

    • Type: STRING
    • Description: Connection string for the database in the format postgresql://user:password@host:port/dbname.
  2. query_str (Required)

    • Type: STRING
    • Description: The natural language query string that describes what data to retrieve from the database. This should be phrased in plain English or the preferred natural language.
  3. is_enable (Optional)

    • Type: BOOLEAN
    • Default: True
    • Description: A toggle to enable or disable the node's operation.
  4. model_name (Required)

    • Type: STRING
    • Default: "gpt-4o-mini"
    • Description: The identifier for the model to be used in processing the natural language query.
  5. base_url (Optional)

    • Type: STRING
    • Description: The base URL for the API, specifically needed if the API environment requires a custom URL.
  6. api_key (Optional)

    • Type: STRING
    • Description: The API key for authenticating requests made to the OpenAI models.

Outputs

The sql_tool node produces the following output:

  • tool
    • Type: STRING
    • Description: A JSON-encoded string containing the function call details used to perform the natural language query on the SQL database. This includes the query parameters and other metadata.

How to Use in ComfyUI Workflows

In a typical ComfyUI workflow:

  1. Set Up the Node: First, include the sql_tool node in your workflow. Ensure that the database connection string (db_connection_string) is correctly set to point to your target database.

  2. Define the Query: Input your desired query in the query_str input field. This query should be in natural language, detailing what information you wish to obtain.

  3. Configure API Credentials: Provide the API key and base URL (if necessary) for OpenAI to ensure that the node can process the query with the selected LLM.

  4. Enable the Node: Make sure the is_enable toggle is set to true to ensure the node is active within the workflow.

  5. Connect and Execute: Integrate the node with other nodes to form a complete workflow, allowing your ComfyUI setup to fetch and visualize data as required.

Special Features and Considerations

  • Natural Language Processing: This node utilizes state-of-the-art natural language models to translate user-friendly queries into precise SQL commands, enhancing usability for non-technical users.

  • Database Agnostic: While the default connection string format provided is for PostgreSQL, the node can theoretically be adapted to other SQL databases by adjusting the connection string format.

  • Ease of Integration: The node is designed to be easily dropped into existing ComfyUI workflows, providing powerful data querying capabilities with minimal setup.

  • API Configuration Flexibility: Users can set up API keys and endpoint URLs either in the node itself or through a configuration file, allowing for flexibility depending on deployment needs.

Always ensure that your database credentials and API keys are kept secure, as they provide access to potentially sensitive information.