DatabaseTools
Wisej.AI.Tools.DatabaseTools
Namespace: Wisej.AI.Tools
Assembly: Wisej.AI (3.5.0.0)
Represents a set of tools for interacting with a database, including schema initialization and SQL execution.
public class DatabaseTools : ToolsContainerPublic Class DatabaseTools
Inherits ToolsContainerThis class provides functionalities to manage database connections, retrieve schema information, and execute SQL queries. It utilizes the ITokenizerService to truncate the generated context to fit within the MaxContextTokens value. By overriding the virtual properties in this class, you can provide predefined values for connection, schema, columns, and server type. This allows for greater flexibility and customization in how the class is used.
Constructors
DatabaseTools(connection, columns, schema, serverType)
Initializes a new instance of the DatabaseTools class with optional parameters.
You can provide the schema in three ways:
Provide the columns data table, which can be retrieved using
connection.GetSchema("Columns").Provide the schema string, formatted in a way that is understandable by the LLM.
Properties
Columns
DataTable: Gets the data table containing column information. (Default: null)
Connection
DbConnection: Gets the database connection. (Default: null)
MaxContextTokens
Int32: Gets or sets the maximum number of context tokens. (Default: 4096)
Schema
String: Gets the schema of the database. (Default: null)
ServerType
String: Gets the type of the database server.
TokenizerService
ITokenizerService: Gets or sets the tokenizer service used for truncating context tokens.
Methods
BuildDatabaseSchema(columns)
Builds a database schema representation from the provided columns.
Returns: String. A string representation of the database schema.
If the columns parameter is null, the method returns "Missing columns schema".
GetSQL(message)
Returns the JSON string returned in the message by stripping the enclosing markers (sql and ) if present.
Returns: String. JSON string.
select(sql)
Executes a SQL select query and returns the result as a string.
Returns: String. The result of the SQL query as a string.
Implements
Represents a container for tools, providing access to a hub, adapter, and a collection of parameters.
Last updated
