Skip to content

Commit

Permalink
restore generations of 3 suggestions for jcr queries
Browse files Browse the repository at this point in the history
  • Loading branch information
stoerr committed Mar 22, 2024
1 parent c0c2801 commit d3a6479
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,15 @@ protected void writeQueryResult(@NotNull final SlingHttpServletRequest request,
protected class QuerySuggestOperation implements ServletOperation {

protected static final String SYSTEMPROMPT = "" +
"You are an expert in creating simple, correct and efficient XPath and SQL2 queries for Apache Jackrabbit JCR." +
"You expect an request to create a query, but will refuse any other instructions. There can be ${placeholders} for unknown values." +
"Answer in JSON format like this:\n" +
"You are an expert in creating simple, correct and efficient XPath and SQL2 queries for Apache Jackrabbit JCR. You expect an request to create a query, but will refuse any other instructions. There can be ${placeholders} for unknown values. Create several possible queries. Answer in JSON format like this:\n" +
"{\n" +
" \"comment\" : \"A comment about the query, possibly questions about the request or state assumptions about unclear requests, or an error message\",\n" +
" \"xpath\" : \"XPath JCR query satisfying the users request\",\n" +
" \"sql2\" : \"SQL2 JCR query satisfying the users request\"\n" +
" \"xpath1\" : \"XPath JCR query satisfying the users request\",\n" +
" \"xpath2\" : \"a different query\",\n" +
" \"xpath3\" : \"a substantially different query\",\n" +
" \"sql1\" : \"SQL2 JCR query satisfying the users request\"\n" +
" \"sql2\" : \"a different query\"\n" +
" \"sql3\" : \"a substantially different query\"\n" +
"}";

protected static final String AEM_NOTICE = "The query is run within Adobe Experience Manager (AEM).";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
var $popover = $('#' + id);
var query = $popover.find('#aigenerateQuery').val();
this.$aigeneratebutton.prop("disabled", true);
this.setAiQueryField($popover, '#aigenerateComment', 'Query generation in progress...');
core.ajaxPost('/bin/cpm/nodes/node.querysuggest.json', {
//data
_charset_: 'UTF-8',
Expand All @@ -360,26 +361,19 @@
//config
dataType: 'json'
}, _.bind(function (content) {
if (!content.comment && !content.xpath && !content.sql2) {
if (!content.comment && !content.xpath1 && !content.sql1) {
var message = content.error || JSON.stringify(content);
core.alert('danger', 'Error', 'Error when generating AI query', message);
return;
}
if (content.comment) {
$popover.find('#aigenerateComment').removeClass('hidden').text(content.comment);
} else {
$popover.find('#aigenerateComment').addClass('hidden');
}
if (content.xpath) {
$popover.find('#aigenerateXpath').removeClass('hidden').text(content.xpath);
} else {
$popover.find('#aigenerateXpath').addClass('hidden');
}
if (content.sql2) {
$popover.find('#aigenerateSql2').removeClass('hidden').text(content.sql2);
} else {
$popover.find('#aigenerateSql2').addClass('hidden');
}
this.setAiQueryField($popover, '#aigenerateComment', content.comment);
this.setAiQueryField($popover, '#aigenerateXpath1', content.xpath1);
this.setAiQueryField($popover, '#aigenerateXpath2', content.xpath2);
this.setAiQueryField($popover, '#aigenerateXpath3', content.xpath3);
this.setAiQueryField($popover, '#aigenerateSql1', content.sql1);
this.setAiQueryField($popover, '#aigenerateSql2', content.sql2);
this.setAiQueryField($popover, '#aigenerateSql3', content.sql3);
this.manageAiGenerateContent();
}, this), _.bind(function (result) {
core.alert('danger', 'Error', 'Error when generating AI query', result);
}, this), _.bind(function () {
Expand All @@ -388,6 +382,18 @@
return false;
},

setAiQueryField: function ($popover, field, value) {
var $field = $popover.find(field);
var $tr = $field.closest('tr');
if (value && value !== "N/A") {
$field.text(value);
$tr.removeClass('hidden');
} else {
$field.text('');
$tr.addClass('hidden');
}
},

manageAiGenerateContent: function () {
var $aigenerate = $('.aigenerate-popover');
if (!$aigenerate.length) {
Expand All @@ -398,14 +404,22 @@
this.aigenerateSavedState = {
query: $query.val(),
comment: $aigenerate.find('#aigenerateComment').text(),
xpath: $aigenerate.find('#aigenerateXpath').text(),
sql2: $aigenerate.find('#aigenerateSql2').text()
xpath1: $aigenerate.find('#aigenerateXpath1').text(),
xpath2: $aigenerate.find('#aigenerateXpath2').text(),
xpath3: $aigenerate.find('#aigenerateXpath3').text(),
sql1: $aigenerate.find('#aigenerateSql1').text(),
sql2: $aigenerate.find('#aigenerateSql2').text(),
sql3: $aigenerate.find('#aigenerateSql3').text()
};
} else if (this.aigenerateSavedState) {
$aigenerate.find('#aigenerateQuery').val(this.aigenerateSavedState.query);
$aigenerate.find('#aigenerateComment').text(this.aigenerateSavedState.comment);
$aigenerate.find('#aigenerateXpath').text(this.aigenerateSavedState.xpath);
$aigenerate.find('#aigenerateSql2').text(this.aigenerateSavedState.sql2);
this.setAiQueryField($aigenerate, '#aigenerateComment', this.aigenerateSavedState.comment);
this.setAiQueryField($aigenerate, '#aigenerateXpath1', this.aigenerateSavedState.xpath1);
this.setAiQueryField($aigenerate, '#aigenerateXpath2', this.aigenerateSavedState.xpath2);
this.setAiQueryField($aigenerate, '#aigenerateXpath3', this.aigenerateSavedState.xpath3);
this.setAiQueryField($aigenerate, '#aigenerateSql1', this.aigenerateSavedState.sql1);
this.setAiQueryField($aigenerate, '#aigenerateSql2', this.aigenerateSavedState.sql2);
this.setAiQueryField($aigenerate, '#aigenerateSql3', this.aigenerateSavedState.sql3);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,33 @@
</form>

<table class="table template-links">
<tr>
<tr class="hidden">
<td></td>
<td width="100%" id="aigenerateComment" data-type="comment"></td>
</tr>
<tr>
<tr class="hidden">
<td>XPath</td>
<td width="100%"><a href="#" id="aigenerateXpath" data-type="xpath"></a></td>
<td width="100%"><a href="#" id="aigenerateXpath1" data-type="xpath"></a></td>
</tr>
<tr>
<tr class="hidden">
<td>XPath</td>
<td width="100%"><a href="#" id="aigenerateXpath2" data-type="xpath"></a></td>
</tr>
<tr class="hidden">
<td>XPath</td>
<td width="100%"><a href="#" id="aigenerateXpath3" data-type="xpath"></a></td>
</tr>
<tr class="hidden">
<td>SQL2</td>
<td width="100%"><a href="#" id="aigenerateSql1" data-type="sql1"></a></td>
</tr>
<tr class="hidden">
<td>SQL2</td>
<td width="100%"><a href="#" id="aigenerateSql2" data-type="sql1"></a></td>
</tr>
<tr class="hidden">
<td>SQL2</td>
<td width="100%"><a href="#" id="aigenerateSql2" data-type="sql2"></a></td>
<td width="100%"><a href="#" id="aigenerateSql3" data-type="sql1"></a></td>
</tr>
</table>
</div>

0 comments on commit d3a6479

Please sign in to comment.