{"id":15882653,"url":"https://github.com/plmercereau/chat-dbt","last_synced_at":"2025-03-17T13:31:26.568Z","repository":{"id":154076491,"uuid":"622264850","full_name":"plmercereau/chat-dbt","owner":"plmercereau","description":"Interact with your database using human queries through OpenAI GPT.","archived":false,"fork":false,"pushed_at":"2023-05-01T21:34:33.000Z","size":453,"stargazers_count":55,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-28T00:15:34.933Z","etag":null,"topics":["chatgpt","cli","clickhouse","database","db","natural-language","nextjs","nodejs","openai","postgresql","sql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/plmercereau.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-01T15:48:42.000Z","updated_at":"2024-12-15T01:01:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"1d870ae1-2cde-4096-8f42-13c1d5175d4f","html_url":"https://github.com/plmercereau/chat-dbt","commit_stats":{"total_commits":101,"total_committers":2,"mean_commits":50.5,"dds":0.1188118811881188,"last_synced_commit":"a9130858251f0a7d878e35dc8cbd05a4bab3d961"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plmercereau%2Fchat-dbt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plmercereau%2Fchat-dbt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plmercereau%2Fchat-dbt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plmercereau%2Fchat-dbt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plmercereau","download_url":"https://codeload.github.com/plmercereau/chat-dbt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243864808,"owners_count":20360357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","cli","clickhouse","database","db","natural-language","nextjs","nodejs","openai","postgresql","sql"],"created_at":"2024-10-06T04:06:02.260Z","updated_at":"2025-03-17T13:31:26.082Z","avatar_url":"https://github.com/plmercereau.png","language":"TypeScript","readme":"# Chat-DBT\n\nInteract with your database using human queries through OpenAI GPT.\n\nhttps://user-images.githubusercontent.com/24897252/233864066-2110a65e-3337-40c2-a1e5-3756e21d6ed6.mp4\n\n## Features\n\n-   Supported databases: PostgreSQL, ClickHouse\n-   Both Command line and Web interfaces\n-   Pipe from/to standard input/output\n-   Keeps the history between queries (unless specified otherwise)\n-   Use OpenAI to auto-correct SQL errors\n-   Multiple result formats (table, JSON, CSV)\n\n## Getting started\n\n```sh\nnpm i -g chat-dbt\nchat-dbt --database postgres://username:password@localhost:5432/postgres --key openai-key\n```\n\n## Usage\n\nAll the available options can be shown using `chat-dbt --help`\n\n### Command-line interface\n\n```sh\nchat-dbt --database postgres://username:password@localhost:5432/postgres --key openai-key\n```\n\n### Web interface\n\n```sh\nchat-dbt web --database postgres://username:password@localhost:5432/postgres --key openai-key\n```\n\nhttps://user-images.githubusercontent.com/24897252/233865764-2a8c4716-f052-47f5-9e48-0ec3a4cc818f.mp4\n\n### Database connection string\n\n#### ClickHouse\n\n```sh\nchat-dbt --database clickhouse://username:password@server.clickhouse.cloud?secure=true\n```\n\nThe `secure` option will translate into an `https` entrypoint. Its default is `false`, which corresponds to `http`.\nNo other ClickHouse option is supported, please file an issue or create a pull request if you need some of them.\n\n### Adapting context between queries\n\nBy default, Chat-DBT keeps a history of previous exchanges with OpenAI. Although this feature provides more context to OpenAI and enables queries using previous results, it uses more tokens and is therefore more costly. If you plan to extract a significant amount of data to send back to OpenAI, you may reach the token limit quickly. Here's an example of how context can be reused between queries:\n\nhttps://user-images.githubusercontent.com/24897252/235167307-8d5fe81e-567a-43be-8300-852930ce9238.mp4\n\nYou can either disable the history with the `--history-mode=none` option, or only keep the previous queries without sending their database result with the `--history-mode=queries` option. Please note that the previous query will however always be sent when you asked to retry a query that failed.\n\n```sh\nchat-dbt --history-mode=[all|none|queries]\n```\n\n\u003c!-- TODO explain a bit further why this feature is powerful, but why it costs an arm --\u003e\n\n### Handling of errors\n\nSometimes OpenAI's response may include an incorrect SQL query that fails. In such cases, you have the following options:\n\n-   Retry: In this case, the error will be sent back to OpenAI, and it will be asked to correct its response.\n-   Edit prompt: You can reformulate the request to OpenAI for it to adjust its response.\n-   Edit SQL: You can manually change the SQL query generated by OpenAI to correct its error and then execute it.\n\nIt is possible to automatically request corrections from OpenAI while sending errors back to it. This feature is deactivated by default, but you can enable it by using the `--auto-correct nb-attempts` flag, where `nb-attempts` is the number of attempts OpenAI will have to solve the error.\n\nEach attempt is iterative and builds upon the previous ones, so OpenAI is supposed to take the context into account to reach a successful query eventually.\n\n```sh\nchat-dbt --auto-correct 3\n```\n\n### Working with input and output files\n\nYou can use a file as a source of a batch of instructions, that you can pipe through chat-dbt, for instance, given the following `instructions.txt` file:\n\n```sh\nlist authors\nadd a famous author from the 20th century\nlist authors\n```\n\nYou can then execute the instructions with:\n\n```sh\ncat instructions.txt | chat-dbt\n```\n\nIt is also possible to define which part of the output should be redirected to stderr, stdout, or nowhere, with the `--output-sql`, `--output-result` and `--output-info` options. For instance, the following instruction will output the SQL query to `stderr`, and the SQL result into `authors.csv`:\n\n```sh\necho \"list authors\" | chat-dbt \\\n    --output-sql stderr \\\n    --output-result stdout \\\n    --output-info none \\\n    --format csv \u003e authors.csv\n```\n\n### Environment variables\n\n```sh\nexport DB_CONNECTION_STRING=postgres://username:password@localhost:5432/postgres\nexport OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nexport OPENAI_ORGANIZATION=org-xxxxxxxxxxxxxxxxxxxxxxxx\nchat-dbt\n```\n\nChat-DBT will also read the secrets mentioned above from a `.env` file, if it exists:\n\n```\nDB_CONNECTION_STRING=postgres://username:password@localhost:5432/postgres\nOPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nOPENAI_ORGANIZATION=org-xxxxxxxxxxxxxxxxxxxxxxxx\n```\n\nYou can also pass a different `.env` file name as an option:\n\n```sh\nchat-dbt --env .env.custom\n```\n\n### Choose another OpenAI model\n\nThe OpenAI model is set to `gpt-4` by default. You can choose another chat model with the `--model` option, for instance:\n\n```sh\nchat-dbt --model gpt-3.5-turbo\n```\n\nYou can have a look at the [list of compatible chat completion models in the OpenAI documentation](https://platform.openai.com/docs/models/model-endpoint-compatibility).\n\n### Ask for confirmation before executing the SQL query\n\nYou may not feel comfortable executing a query before previewing it. To preview the SQL query and confirm before running it, use the `--confirm` option. This option prompts you for confirmation and allows you to modify the SQL query if needed before its execution.\n\n```sh\nchat-dbt --confirm\n```\n\n### Change the format of the result\n\nBy default, Chat-DBT renders the results as a table. You can however output the result in CSV or JSON, in passing the `--format` option:\n\n```sh\nchat-dbt --format json\nchat-dbt --format csv\n```\n\n\u003c!-- ## How it works\n\n## FAQ\n\n### Is it safe?\n\n### How can I process the data back ? (reformulate)\n\n### Can I use Chat-DBT with another DBMS e.g. MySQL?\n\n### There's a bug or a missing feature, what can I do? --\u003e\n\n## Development\n\n```sh\n# Clone the repository\ngit clone https://github.com/plmercereau/chat-dbt\ncd chat-dbt\n\n# Install Node dependencies\npnpm i\n\n# Create a .env.local file\ncp .env.local.example .env.local\n\n# Then, edit the .env.local file to fill your OpenAI API key and organisation\n\n# Start the demo database\ndocker-compose up -d\n```\n\n### Develop the CLI\n\n```sh\npnpm run dev:cli\n```\n\n### Develop the Web interface\n\n```sh\npnpm run dev:web\n```\n","funding_links":[],"categories":["UIs"],"sub_categories":["CHUI(Chat-based User Interface) or CHUBACA(Chat-Based Client:)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplmercereau%2Fchat-dbt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplmercereau%2Fchat-dbt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplmercereau%2Fchat-dbt/lists"}