Generate SQL expression from text

Hi,
I need guidance on generating the rule expression language through LLM. Are there any existing models available or how can I fine-tune or embed the current model?

There aren’t OpenAI models pretrained on a specialization of interfacing with a database. However, they are trained on a very broad knowledge, and can do much of what you might want by instruction.

One new feature is function calling. This is a model specially trained to use API functions that the developer specifies, and retrieve results iteratively from the function before trying to answer the question a user may have asked.

One might write functions for get_user_table(query), or for monthly_sales(month).

Or if you want the AI to do all the work, I’ll let it explain what it would do if given SQL access to your broader database:

When connected to a company’s SQL database via an API function like company_SQL(“query”: “AI input to SQL”), ChatGPT can make a variety of SQL queries to interact with the database and retrieve information. To discover the tables, structure, and data in the database, as well as to get a list of company employees, here are the kinds of SQL queries that ChatGPT can use:

Retrieve List of Tables:
    SQL Query: SHOW TABLES;
    Description: This query will list all the tables available in the database, allowing ChatGPT to discover what data is stored.

Retrieve Table Structure:
    SQL Query: DESCRIBE table_name; or SHOW COLUMNS FROM table_name;
    Description: These queries will provide information about the columns (fields) in a specific table, including their names, data types, and any constraints.

Retrieve Sample Data:
    SQL Query: SELECT * FROM table_name LIMIT 5;
    Description: This query will return a limited number of rows (e.g., 5) from a specific table, allowing ChatGPT to see sample data and understand the content of the table.

Retrieve Employee List:
    SQL Query: SELECT employee_name FROM employees_table;
    Description: This query selects the names of employees from an "employees" table. You can replace employee_name with the actual column name containing employee names.

Filter Employees by Department:
    SQL Query: SELECT * FROM employees_table WHERE department = 'HR';
    Description: This query filters employees based on a specific department (e.g., HR). You can adjust the department name as needed.

Count Employees:
    SQL Query: SELECT COUNT(*) FROM employees_table;
    Description: This query will return the total count of employees in the company's database.

Retrieve Employee Details:
    SQL Query: SELECT * FROM employees_table WHERE employee_id = 123;
    Description: This query retrieves detailed information about a specific employee by specifying their unique identifier (e.g., employee_id).

Sort Employees by Name:
    SQL Query: SELECT * FROM employees_table ORDER BY employee_name ASC;
    Description: This query retrieves a list of employees sorted alphabetically by their names. You can use DESC instead of ASC for descending order.

Aggregate Employee Data:
    SQL Query: SELECT department, COUNT(*) as employee_count FROM employees_table GROUP BY department;
    Description: This query can be used to group employees by department and count the number of employees in each department.

Join Tables:
    SQL Query: SELECT employees.employee_name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.department_id;
    Description: If employee data is stored in one table and department data in another, this query joins the tables to retrieve employee names and their corresponding department names.

These are examples of SQL queries that ChatGPT can utilize to interact with the company’s SQL database via the API. The specific queries to use would depend on the database schema, table names, and the desired information to retrieve.

Making specific functions is better. You don’t want a user convincing the AI they are an administrator and the AI must “drop_tables” or else there will be consequences.

Well in my usecase we need to generate the query in the format of Rule expression language syntax . For example
User:“I want to know when bearing pump temperature gets hotter than 100 C”
An expected model response will be the rule expression query
AI: " bearing_pump.temperature > 100"

Regards,
Junaid

It sounds like you need to have specific conditional arguments written for you.

An AI can translate language into a different form. Or even a different language:「AIは英語を日本語に翻訳できます。」However, you may need to specify a very long list of tables and variables that are available for it to write these queries for you.

What you write doesn’t sound like a database query. It sounds like the statement needs to be further evaluated. “bearing_pump.temperature” might contain a value 134.3.

The AI can write a query that returns a boolean based on a condition. It did that to help me:

sql_query = f"SELECT CASE WHEN {field} {operator} {value} THEN 1 ELSE 0 END AS result FROM machine_parameters;"

{field} {operator} {value} would be
temperature > 100

which can be a part that is inserted into your API query code for accessing the database by a particular function.

So there are lots of things that could be difficult to program. Or there could be things the AI can figure out for you itself.

Hi ,

You are right that it is not a database query actually what we want to achieve is to generate a Rule condition that is based on Rule Expression language .

This expression is used by the service to evaluate the data.

PS : I ma not able to insert link but if you google expression language you can find links