Skip to content

Commit

Permalink
Merge pull request #48 from ThinkThinkAI/readme_release
Browse files Browse the repository at this point in the history
Readme release
  • Loading branch information
rootedbox authored Sep 19, 2024
2 parents d8b3223 + 1aac176 commit 36820ed
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 35 deletions.
222 changes: 201 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
# ThinkDB
<div align="right">
<a href="https://discord.com/invite/your-discord-server-id" style="float: right;"><img src="https://img.shields.io/discord/1245952504341200957?style=flat&label=Discord"></a>
</div>
<h1 align="center">
ThinkDB 🤔
</h1>

ThinkDB empowers you to effortlessly navigate and manage your databases, eliminating the need for deep SQL expertise. 🧙‍♂️✨ Leveraging advanced AI capabilities, ThinkDB intuitively understands your objectives and translates them into precise SQL queries. Whether you are a seasoned database professional or a newcomer to the world of data management, ThinkDB provides an intuitive and natural interface to help you explore, query, and manage your data with unparalleled ease.
<h3 align="center">
ThinkDB is a powerful SQL client that transforms the way you interact with your databases.
</h3>

**In essence, ThinkDB is a sophisticated web-based database client designed for both simplicity and power.**
---

**Smart Query Interface:** Write SQL queries effortlessly with our query interface enhanced by smart code completion, helping you code faster and with fewer errors.

<div align="center">
<img src="docs/query_complete.gif" alt="ThinkDB Interface" style="width:100%;">
</div>

---
## ⚠️ Alpha Software Warning ⚠️

**Important Notice:** ThinkDB is currently in the alpha stage of development. This means that the software is still undergoing changes and may contain bugs or incomplete features. We recommend using ThinkDB in a test environment and not in a production setting until a stable release is available. Your feedback is valuable to us and can help shape the final product.
**QChat:** Engage in a conversational dialogue with our AI assistant. Simply ask questions in natural language, and QChat responds with precise SQL queries and real-time data results.

<div align="center">
<img src="docs/qchat.gif" alt="QChat Interface" style="width:100%;">
</div>

---

**Virtual DBA Chat:** Consult with an AI-powered virtual Database Administrator capable of performing tasks that a seasoned DBA would handle. Need to optimize queries, set up database backups, configure security settings, or get performance tuning advice? The virtual DBA is here to assist you.

<div align="center">
<img src="docs/chat.gif" alt="Chat Interface" style="width:100%;">
</div>

---

Whether you’re an experienced database professional or just starting out, ThinkDB provides an intuitive and natural interface to explore, query, and manage your data with unparalleled ease.


---
Looking for CLI version? Checkout our powerful range of AI powered CLI Tools 👉 [CommandAI](https://github.com/ThinkThinkAI/CommandAI)

---

## Current Features

Expand All @@ -18,7 +50,7 @@ ThinkDB empowers you to effortlessly navigate and manage your databases, elimina
- **AI-Driven SQL Generation:** Generate complex SQL queries from simple natural language inputs, allowing you to articulate your needs without getting bogged down in syntax.
- **Query Management:** Save and organize your frequently used queries, enabling quick access and reuse for future sessions.
- **Table Browser:** Explore your database structures with a robust table browser that offers insights into table schemas and relationships.
- **AI-Powered Database Optimization:** Soon, you will be able to consult our AI for guidance on optimizing your database schema and structure, making your database more efficient and scalable.
- **AI-Powered Database Optimization:** You are able to consult our AI for guidance on optimizing your database schema and structure, making your database more efficient and scalable.

## Upcoming Features

Expand All @@ -31,28 +63,176 @@ ThinkDB empowers you to effortlessly navigate and manage your databases, elimina
- **Principled Approach:** We believe that offering database clients as a service poses significant security risks; therefore, ThinkDB is designed to operate securely on your own infrastructure.
- **Encrypted Communication:** All connection information is securely encrypted, safeguarding your credentials and ensuring that your data remains protected at all times.
- **Database Security:** We believe database security should be managed on the database itself, reinforcing access controls and preventing unauthorized access.
- **Custom AI Provider:** Select the AI provider that best suits your needs or host your own AI system, giving you complete control over the AI integration and ensuring it complies with your security policies.

## ⚠️ Alpha Version Warning

Please note that ThinkDB is currently in its alpha stage. While we are continuously working to improve and stabilize the application, you may encounter bugs. We appreciate your understanding and welcome any feedback to help us enhance the product.

## Getting Started

### Using Docker (The Simplest Method)

To get ThinkDB up and running quickly, you can utilize Docker:
To get ThinkDB up and running quickly using DockerHub:

```bash
git clone [email protected]:ThinkThinkAI/ThinkDB.git
cd ThinkDB
docker-compose up --build
```
### Running the Application

1. Pull the latest Docker image:

```sh
docker pull thinkthinkai/think_db:latest
```

2. Run the container while ensuring SQLite database persistence and setting the `SECRET_KEY_BASE` environment variable. Remember to replace `directory_on_your_machine_for_think_db_storage` and `your_secret_key_base_here` with your actual directory path and secret key base:

```sh
# change directory_on_your_machine_for_think_db_storage & your_secret_key_base_here
docker run -d -p 3000:3000 -v directory_on_your_machine_for_think_db_storage:/app/storage -e SECRET_KEY_BASE=your_secret_key_base_here thinkthinkai/think_db:latest
```

### Security Note

It's outside the scope of this README to walk you through securing your Docker container and any web application you host within it. However, we strongly recommend that:
1. **SECRET_KEY_BASE**: This should be managed securely—preferably through Docker secrets if using Docker Swarm or Kubernetes, or via a trusted secret management solution—to ensure it’s not exposed in plaintext within your environment variables.
2. **TLS/SSL**: Always serve your web application over HTTPS using a valid TLS certificate to encrypt data transmitted over the network.
### Using Rails Outside a Container (The Harder Method)
To run ThinkDB locally using Rails:
### Prerequisites
Before you start, ensure you have the following installed:
- Ruby (version 3.2.2 or higher)
- Rails (version 7.1 or higher)
- Bundler
- Redis (for Action Cable / Sidekick)
### Steps to Run ThinkDB Outside a Container
1. Clone the repository:
```bash
git clone https://github.com/ThinkThinkAI/ThinkDB.git
cd ThinkDB
```
2. Install the necessary gems:
```bash
bundle install
```
3. Set up the database:
### Running on Ruby on Rails
```bash
bin/rails db:setup
```
If you prefer to run ThinkDB locally within the Ruby on Rails environment.
4. Start the application with the `SECRET_KEY_BASE` environment variable set:
```bash
SECRET_KEY_BASE=$(bundle exec rake secret) foreman start
```
## Configuration
ThinkDB is highly configurable to suit your needs. Below are the steps to configure it properly:
### AI Configuration
You can configure the AI services ThinkDB uses to generate and optimize SQL by setting the AI URL, model, and API key. This can be done via the Settings interface in the application.
#### Steps:
1. **Navigate to the Settings Page**
2. **Fill in AI Service Information**:
- **AI URL**: URL to connect to the AI service.
- **AI Model**: Specify the model name.
- **AI API Key**: Enter your API key for the AI service.
<div align="center">
<img src="docs/settings.gif" alt="Settings Interface" style="width:100%;">
</div>
Here's an example of how you can configure for various AI services:

- **ChatGPT**:
- **URL**: `https://api.openai.com/v1`
- **Model**: [OpenAI Models](https://beta.openai.com/docs/models)
- **API Key**: [Generate API Key](https://beta.openai.com/account/api-keys)

- **Mistral**:
- **URL**: `https://api.mistral.ai/v1/completions`
- **Model**: [Mistral Models](https://mnt9s.ai/models)
- **API Key**: [Generate API Key](https://mistral.ai/account/api-keys)

- **Ollama**:
- **URL**: `http://127.0.0.1:11434` (if running locally)
- **Model**: Depends on installed models.
- **API Key**: Any valid key.

- **OpenAI Compatible**:
- ThinkDB can connect to any AI service that implements OpenAI's API, including Azure OpenAI, Anthropic, Cohere, and others. Check their documentation for proper URL, model, and API key.
### Data Source Configuration
Proper configuration ensures that ThinkDB can interact with your databases efficiently:
#### Steps:
1. **Navigate to New Data Source**:
2. **Fill in Data Source Information**:
- **Data Source Name**: Provide a friendly name for the data source.
- **Database Type**: Select from SQLite, MySQL, PostgreSQL, etc.
- **Connection Details**: Provide necessary credentials and connection string.
<div align="center">
<img src="docs/datasource.gif" alt="Datasource Interface" style="width:100%;">
</div>
- You can create multiple data sources.
- Only one data source can be active at a time.
- Change active data source at any time from the left navigation bar.
### Reporting Issues
If you encounter any bugs or have suggestions for improvements, please open an issue on the GitHub repository. To help us understand and address the issue, please include the following information:
1. **Description**: Provide a clear and concise description of the bug or feature request.
2. **Steps to Reproduce**: List the steps needed to reproduce the bug. This is crucial for us to identify and fix the problem.
3. **Expected Behavior**: Explain what you expected to happen.
4. **Actual Behavior**: Describe what actually happened. Include any error messages or logs if applicable.
5. **Environment**: Provide details about your environment, such as the operating system, browser, and versions of any relevant libraries and tools.
Example:
```markdown
**Description**:
The application crashes when I try to add a new data source.
**Steps to Reproduce**:
1. Navigate to the 'New Data Source' page.
2. Fill in the details and click 'Save'.
3. Application crashes.
**Expected Behavior**:
The new data source should be saved without any issues.
**Actual Behavior**:
The application crashes with an 'Internal Server Error'.
**Environment**:
- OS: Windows 10
- Browser: Google Chrome Version 93.0.4577.63
- ThinkDB Version: 1.2.3
```
```bash
git clone [email protected]:ThinkThinkAI/ThinkDB.git
cd ThinkDB
bundle install
rails db:migrate
rails s
```
Including these details will help us resolve issues more quickly. Thank you for helping us improve ThinkDB!
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.12-alpha
1.0.14-alpha
11 changes: 7 additions & 4 deletions app/javascript/channels/chat_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ document.addEventListener("turbo:load", () => {
const chatChannel = consumer.subscriptions.create(
{ channel: "ChatChannel", user_id: currentUserId },
{
connected() { console.log('connected');},
connected() {
console.log("connected");
},
disconnected() {},
received(data) {
if (data.ai_response) {
Expand All @@ -20,7 +22,7 @@ document.addEventListener("turbo:load", () => {
`message-${data.message_id}`
);
if (existingMessageDiv) {
return;
return;
}

if (loadingMessagesDiv) {
Expand All @@ -32,14 +34,15 @@ document.addEventListener("turbo:load", () => {
newMessageDiv.id = `message-${data.message_id}`;
newMessageDiv.innerHTML = data.ai_response;
messagesDiv.appendChild(newMessageDiv);
scrollboxDiv.scrollTop = messagesDiv.scrollHeight;

scrollboxDiv.scrollTop = newMessageDiv.offsetTop;

initializeGrid(
data.message_id,
data.message_sql.replace(/;/g, "")
);

scrollboxDiv.scrollTop = messagesDiv.scrollHeight;
scrollboxDiv.scrollTop = newMessageDiv.offsetTop;
} else {
console.error(
'Element with ID "messages" not found on the page.'
Expand Down
9 changes: 8 additions & 1 deletion app/services/adapters/postgresql_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ def schemas

def run_query(query, limit = 10, offset = 0, sort = nil)
wrapped_query = "(#{query})"
init_wrapped_query = wrapped_query

wrapped_query = add_sorting(wrapped_query, sort)
wrapped_query = add_offset(wrapped_query, limit, offset)

result = @connection.exec(wrapped_query)
result = if wrapped_query != init_wrapped_query
@connection.exec(wrapped_query)
else
@connection.exec(query)
end

fields = result.fields
values = result.values
[fields] + values
Expand Down
16 changes: 10 additions & 6 deletions app/services/adapters/sqlite_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def schemas
end

def run_query(query, limit = 10, offset = 0, sort = nil)
unless query.strip.upcase.start_with?('PRAGMA')
query = "select * from (#{query})"
query = add_sorting(query, sort)
query = add_offset(query, limit, offset)
wrapped_query = "select * from (#{query})"
init_wrapped_query = wrapped_query

wrapped_query = add_sorting(wrapped_query, sort)
wrapped_query = add_offset(wrapped_query, limit, offset)

if wrapped_query != init_wrapped_query
@connection.execute2(wrapped_query)
else
@connection.execute2(query)
end

@connection.execute2(query)
end

def run_raw_query(query)
Expand Down
2 changes: 1 addition & 1 deletion app/views/chats/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<% else %>
<div class="card p-4 m-4 rounded-4 col-6">
<h3>Welcome to your Virtual DBA!</h3>
<h5>I am your AI-powered Database Administrator, here to assist you with all your data needs. Ask me anything!<br><br>Need to understand the structure of your database?<br>Have missing keys or foreign key issues?<br>Looking to optimize your queries, code, or frameworks?<br>Want advice on database security or performance tuning?<br><br>I'm here to help with all that and more!</h5>
<h4 style="line-height: 1.7;" >I am your AI-powered Database Administrator, here to assist you with all your data needs. Ask me anything!<br><br>Need to understand the structure of your database?<br>Have missing keys or foreign key issues?<br>Looking to optimize your queries, code, or frameworks?<br>Want advice on database security or performance tuning?<br><br>I'm here to help with all that and more!</h5>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/q_chats/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<% else %>
<div class="card p-4 m-4 rounded-4 col-6">
<h3>Welcome to Query Chat!</h3>
<h5>I'm your AI assistant, here to help you interact with your database effortlessly. Just tell me what you're looking for, and I'll generate the SQL queries and provide the data you need. Whether you have specific questions, need to explore your data, or want insights, I'm here to assist you. Ask me anything, and let's get started!</h5>
<h4 style="line-height: 1.7;" >I'm your AI assistant, here to help you interact with your database effortlessly. Just tell me what you're looking for, and I'll generate the SQL queries and provide the data you need. Whether you have specific questions, need to explore your data, or want insights, I'm here to assist you. Ask me anything, and let's get started!</h5>
</div>
<% end %>
</div>
Expand Down
Binary file added docs/chat.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/datasource.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/qchat.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/query_complete.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/settings.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 36820ed

Please sign in to comment.