Skip to content

Commit

Permalink
cleanup markup, fix relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisclark committed Apr 22, 2024
1 parent 86bc056 commit 105a6dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
14 changes: 3 additions & 11 deletions explorer/src/js/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import * as bootstrap from 'bootstrap';
import $ from "jquery";
import List from "list.js";

const spinner = "<div class=\"spinner-border text-primary\" role=\"status\"><span class=\"visually-hidden\">Loading...</span></div>";

function getErrorMessage() {
const errorElement = document.querySelector('.alert-danger.db-error');
return errorElement ? errorElement.textContent.trim() : null;
Expand All @@ -23,12 +21,7 @@ export function setUpAssistant(expand = false) {
});
bsCollapse.show();
if(error) {
const textarea = document.getElementById('id_assistant_input');
textarea.value = "Please help me fix the error(s) in this query.";
const newDiv = document.createElement('div');
newDiv.textContent = 'Error messages are automatically included in the prompt. Just hit "Ask Assistant" and all relevant context will be injected to the LLM request.'; // Add any text or HTML content
newDiv.className = 'text-secondary small';
textarea.parentNode.insertBefore(newDiv, textarea.nextSibling);
document.getElementById('id_error_help_message').classList.remove('d-none');
}
}

Expand Down Expand Up @@ -108,8 +101,8 @@ export function setUpAssistant(expand = false) {
db_error: getErrorMessage()
};

document.getElementById("response_block").style.display = "block";
document.getElementById("assistant_response").innerHTML = spinner;
document.getElementById("response_block").classList.remove('d-none');
document.getElementById("assistant_spinner").classList.remove('d-none');

fetch('../assistant/', {
method: 'POST',
Expand All @@ -127,7 +120,6 @@ export function setUpAssistant(expand = false) {
})
.then(data => {
const output = DOMPurify.sanitize(marked.parse(data.message));
document.getElementById("response_block").style.display = "block";
document.getElementById("assistant_response").innerHTML = output;
setUpCopyButtons();
})
Expand Down
1 change: 0 additions & 1 deletion explorer/src/js/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class ExplorerEditor {
}

this.queryId = queryId;
this.$table = $("#preview");
this.$rows = $("#rows");
this.$form = $("form");
this.$snapshotField = $("#id_snapshot");
Expand Down
17 changes: 12 additions & 5 deletions explorer/templates/explorer/assistant.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
<div class="row assistant_input_parent">
<div class="mt-3 col-12" id="assistant_input_wrapper">
<textarea
class="form-control" id="id_assistant_input"
class="form-control mb-4" id="id_assistant_input"
name="sql_assistant" rows="3" placeholder="What do you need help with?"></textarea>
<label for="id_assistant_input" class="form-label" id="id_assistant_input_label"></label>
<label for="id_assistant_input" class="form-label d-none" id="id_assistant_input_label">Assistant prompt</label>
<div id="id_error_help_message" class="d-none text-secondary small">
Hit "Ask Assistant" to try and fix the issue. The assistant is automatically aware of error messages & context.
</div>
</div>
<div id="additional_table_container" class="d-none col-3">
<input id="search_assistant_tables" class="search" placeholder="{% trans "Search Tables" %}" />
Expand All @@ -29,7 +32,7 @@
<input type="checkbox" class="form-check-input" name="assistant-include-other-tables" id="include_other_tables" autocomplete="off">
<label class="form-check-label" for="include_other_tables">Include Other Tables (<a class="small text-secondary" style="cursor: pointer;"
data-bs-toggle="tooltip" data-bs-placement="top"
data-bs-title="SQL Assistant builds a prompt with your query, your request, relevant schema (tables referenced in your query) and sample data from those tables. You can optionally include other tables (schema + data sample) that you'd like SQL Assistant to know about.">What is this?</a>)</label>
data-bs-title="SQL Assistant builds a prompt with your query, your request, relevant schema (tables referenced in your query) and sample data from those tables. You can optionally include other tables (schema + data sample) that you'd like SQL Assistant to know about.">?</a>)</label>
</div>
</div>
<div class="col-6 text-end">
Expand All @@ -40,8 +43,12 @@
</div>


<div id="response_block" style="display: none" class="position-relative">
<div class="mt-3 p-2 pt-3 rounded-2 border bg-light" id="assistant_response"></div>
<div id="response_block" class="position-relative d-none">
<div class="mt-3 p-2 pt-4 rounded-2 border bg-light" id="assistant_response">
<p class="spinner-border text-primary d-none" id="assistant_spinner" role="status">
<span class="visually-hidden">Loading...</span>
</p>
</div>
</div>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion explorer/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from django.db.migrations.recorder import MigrationRecorder
from django.conf import settings

import explorer

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -84,7 +86,7 @@ def _send(data):
data=data,
headers={"Content-Type": "application/json"})
except Exception as e:
logger.exception("Failed to send stats: %s" % e)
logger.warning("Failed to send stats: %s" % e)


def gather_summary_stats():
Expand Down Expand Up @@ -117,6 +119,7 @@ def gather_summary_stats():
"unsafe_rendering": app_settings.UNSAFE_RENDERING,
"transform_count": len(app_settings.EXPLORER_TRANSFORMS),
"assistant_enabled": app_settings.EXPLORER_AI_API_KEY is not None,
"version": explorer.get_version()
}
except Exception as e:
return {"error": "error gathering stats: %s" % e}

0 comments on commit 105a6dd

Please sign in to comment.