Skip to content

Commit

Permalink
assistant history
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisclark committed Aug 29, 2024
1 parent 20b5424 commit 81f15fb
Show file tree
Hide file tree
Showing 12 changed files with 539 additions and 46 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ vNext
- Relevant tables are added client-side visually, in real time, based on what's in the SQL editor and/or any tables
mentioned in the assistant request. The dependency on sql_metadata is therefore removed, as server-side SQL parsing
is no longer necessary.
- Ability to view Assistant request/response history.
- Improved system prompt that emphasizes the particular SQL dialect being used.
- Addresses issue #657.

Expand Down
2 changes: 1 addition & 1 deletion explorer/assistant/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs):

f = forms.ChoiceField(
choices=choices,
widget=forms.Select(attrs={"class": "form-select"})
widget=forms.Select(attrs={"class": "form-select", "data-placeholder": "Select table"})
)

# We don't actually care about validating the 'choices' that the ChoiceField does by default.
Expand Down
14 changes: 6 additions & 8 deletions explorer/src/js/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ function setupTableList() {
removeItemButton: true,
searchEnabled: true,
shouldSort: false,
placeholder: true,
placeholderValue: 'Relevant tables',
position: 'bottom'
});

Expand Down Expand Up @@ -132,8 +130,10 @@ export function setUpAssistant(expand = false) {

function getAssistantHistory() {

const historyModalId = 'historyModal';

// Remove any existing modal with the same ID
const existingModal = document.getElementById('historyModal');
const existingModal = document.getElementById(historyModalId);
if (existingModal) {
existingModal.remove()
}
Expand Down Expand Up @@ -186,7 +186,7 @@ function getAssistantHistory() {

// Insert the table into a new Bootstrap modal
const modalHtml = `
<div class="modal fade" id="historyModal" tabindex="-1" aria-labelledby="historyModalLabel" aria-hidden="true">
<div class="modal fade" id="${historyModalId}" tabindex="-1" aria-labelledby="historyModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -204,12 +204,10 @@ function getAssistantHistory() {
</div>
`;

// Append the modal to the body
document.body.insertAdjacentHTML('beforeend', modalHtml);

// Show the modal
const historyModal = new bootstrap.Modal(document.getElementById('historyModal'));
const historyModal = new bootstrap.Modal(document.getElementById(historyModalId));
historyModal.show();

})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
Expand Down
2 changes: 1 addition & 1 deletion explorer/src/js/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function updateSchema() {
});
});

$("#schema_frame").attr("src", `../schema/${getConnElement().value}`);
$("#schema_frame").attr("src", `${window.baseUrlPath}schema/${getConnElement().value}`);

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
}


Expand Down
7 changes: 7 additions & 0 deletions explorer/src/js/tableDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ function populateTableList() {
});
}

function updateSchema() {
document.getElementById("schema_frame").src = `${window.baseUrlPath}schema/${getConnElement().value}`;

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
}

export function setupTableDescription() {
getConnElement().addEventListener('change', populateTableList);
populateTableList();

getConnElement().addEventListener('change', updateSchema);
updateSchema();
}
12 changes: 12 additions & 0 deletions explorer/src/scss/assistant.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@
max-height: 120px;
overflow: hidden;
}

.assistant-icons {
width: 1rem;
position: absolute;
right: .75rem;
}

#table-list {
.choices__inner {
min-height: 7rem !important;
}
}
Loading

0 comments on commit 81f15fb

Please sign in to comment.