Skip to content

Commit

Permalink
Add information on SchemaCrawler AI chat
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed Dec 16, 2024
1 parent 2441b09 commit a7d3029
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions schemacrawler-website/src/site/header.include
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<a class="dropdown-item" href="diagramming.html">Diagramming</a>
<a class="dropdown-item" href="scripting.html">Scripting</a>
<a class="dropdown-item" href="lint.html">Lint</a>
<a class="dropdown-item" href="aichat.html">AI Chat with ChatGPT</a>
<a class="dropdown-item" href="serialize.html">Serialization</a>
<a class="dropdown-item" href="weak-associations.html">Weak Associations</a>
<a class="dropdown-item" href="offline.html">Offline Snapshots</a>
Expand Down
44 changes: 44 additions & 0 deletions schemacrawler-website/src/site/markdown/aichat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Interactive Shell with ChatGPT

SchemaCrawler is integrated with ChatGPT to provide an interactive way to interrogate your database schema metadata. No information about your database schema is shared with OpenAI. To start using this integration, you will need to create your own [OpenAI API key](https://www.howtogeek.com/885918/how-to-get-an-openai-api-key/). Once you have that, use SchemaCrawler from the command-line as you normally would, and connect to your database. Provide `aichat` as the SchemaCrawler command, and provide your OpenAI API key in an environmetal variable called `OPENAI_API_KEY`. Otherwise, you can use an additional command-line argument, `--api-key` to provide your API key. If you do not want to provide this API key in the clear, you can use `--api-key:env` instead, and give the name of an environmental variable that contains the key, if it is different than `OPENAI_API_KEY`.

Once you have this running, you will have an interactive chat shell with ChatGPT, enhanced with information about your database metadata. You can try prompts such as the following ones:

- List all tables
- Describe the AUTHORS table
- What are the indexes on the AUTHORS table?
- What are the AUTHORS columns?
- What is the AUTHORS primary key?
- Describe the AuthorsList view
- Show me the triggers on AUTHORS
- Find the parents of BOOKAUTHORS
- What are the children of BOOKS?

To quit the console, you can type something like:

- I think I have everything I need
- or simply, "done", "exit" or "quit"

You can use any language that ChatGPT supports, for example, try something like:

- Combien de tables y a-til dans cette base de données?
- Décris-moi la table Books
- Y'a t-il une clé primaire?
- Décris-moi la table NoName


## Get SQL and Other Help on Your Schema

If you are willing to share your database metadata with OpenAI, you can get additional help from ChatGPT. For example, you can get help with writing SQL queries, or with writing good comments on your database schema. To share data, pass an additional command-line argument to SchemaCrawler, `--use-metadata`. SchemaCrawler uses Retrieval Augmented Generation (RAG) techniques to select the tables in your schema that will be used to assist with your ChatGPT prompt.

Try out prompts like (even though they may not return completely accurate information):

- Based on my schema, write a SQL query for book names and author names
- Based on my schema, write a SQL query to find all books that have previous editions
- Suggest remarks for columns in the Books table
- Summarize the database in one paragraph


## Extensions

SchemaCrawler allows you to extend the functionality with your own functions that work against the database catalog. Your functions should implement `schemacrawler.tools.command.aichat.FunctionDefinition<P extends FunctionParameters>`. Package your functions in a jar, with a service provider file called `META-INF/services/schemacrawler.tools.command.aichat.FunctionDefinition`. Put this jar on the SchemaCrawler classpath, and your functions will be provided to the AI for processing.
2 changes: 1 addition & 1 deletion schemacrawler-website/src/site/markdown/downloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you need to use SchemaCrawler locally, you have a number of options. You can

If you want to use SchemaCrawler as a library, and in your build, all jars are in the [Central Repository](https://central.sonatype.com/search?q=us.fatehi.schemacrawler&sort=name). They can be used as dependencies in [Gradle](https://gradle.org/) or [Apache Maven](https://maven.apache.org/) projects, or with any other build system that supports the Central Repository. SchemaCrawler reports can be incorporated into Apache Maven builds with the [SchemaCrawler Report Maven Plugin](https://github.com/schemacrawler/SchemaCrawler-Report-Maven-Plugin) and into the GitHub Actions workflow with the [SchemaCrawler Action](https://github.com/schemacrawler/SchemaCrawler-Action) or in [GitLab pipelines](https://gitlab.com/sualeh/schemacrawler-action-usage-example/-/pipelines). If you would like to extend SchemaCrawler with plugins for a certain database, create new database lints, or create a new command, use the [starter projects to create new SchemaCrawler plugins](https://github.com/schemacrawler/SchemaCrawler-Plugins-Starter) on GitHub.

[Pre-packaged SchemaCrawler Docker images](https://hub.docker.com/r/schemacrawler/schemacrawler/) are available on Docker Hub.
[Pre-packaged SchemaCrawler Docker images](https://hub.docker.com/r/schemacrawler/schemacrawler/) are available on Docker Hub. Use the "extra-latest" tag for getting additional commands like [AI Chat with ChatGPT](aichat.html).

Additional SchemaCrawler database plugins are available from the [schemacrawler/SchemaCrawler-Database-Plugins](https://github.com/schemacrawler/SchemaCrawler-Database-Plugins) project.

Expand Down

0 comments on commit a7d3029

Please # to comment.