tbls-ask

tbls-ask is an external subcommand of tbls for asking OpenAI using the datasource.

MIT License

Stars
10
Committers
4

tbls-ask

tbls-ask is an external subcommand of tbls for asking OpenAI/Gemini using the datasource.

Usage

tbls-ask is provided as an external subcommand of tbls.

Ask OpenAI

$ tbls ask --dsn 'mysql://user:pass@localhost:3306/wordpress' which is blog comment table?
The blog comment table in the given DDL is `wp_comments`.

Ask OpenAI for query

Use --query option.

$ tbls ask --query --dsn 'json://path/to/wordpress/schema.json' count blog posts per user per month
SELECT
    YEAR(p.post_date) AS `Year`,
    MONTH(p.post_date) AS `Month`,
    u.display_name AS `User`,
    COUNT(p.ID) AS `Post Count`
FROM wp_posts p
INNER JOIN wp_users u ON p.post_author = u.ID
WHERE p.post_type = 'post' AND p.post_status = 'publish'
GROUP BY `Year`, `Month`, `User`
ORDER BY `Year` DESC, `Month` DESC, `User` ASC

Ask Gemini

Add an option --model for asking Gemini.

$ tbls ask --dsn 'mysql://user:pass@localhost:3306/wordpress' --model gemini-pro which is blog comment table?

Requirement

Either OpenAI or Gemini API key is required.

  • OPENAI_API_KEY ... API Key of OpenAI.
  • GEMINI_API_KEY ... API Key of Gemini.