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.