-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from michaelthwan/ajax
ajax call and avoid full page refresh / config change
- Loading branch information
Showing
7 changed files
with
119 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
$(document).ready(function () { | ||
$('form').submit(function(event) { | ||
event.preventDefault(); | ||
let search_text = $('#form1').val(); | ||
$('#search-btn')[0].disabled = true; | ||
$('#search-result-spinner').addClass('d-flex'); | ||
$('#search-results').hide(); | ||
$.ajax({ | ||
url: '/search', | ||
type: 'POST', | ||
data: { | ||
q: search_text, | ||
bing_search_subscription_key: $('#bing_search_subscription_key').val(), | ||
openai_api_key: $('#openai_api_key').val(), | ||
is_use_source: $('input[name="is_use_source"]')[0].checked, | ||
llm_service_provider: $('#llm_service_provider').val(), | ||
llm_model: $('#llm_model').val(), | ||
semantic_search_provider: $('#semantic_search_provider').val() | ||
}, | ||
success: function (response) { | ||
$('#' + response.id).html(response.html) | ||
$('#search-btn')[0].disabled = false; | ||
$('#search-result-spinner').removeClass('d-flex'); | ||
$('#search-results').show(); | ||
}, | ||
error: function (error) { | ||
console.log(error) | ||
$('#search-btn')[0].disabled = false; | ||
$('#search-result-spinner').removeClass('d-flex'); | ||
$('#search-results').show(); | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% if error %} | ||
<div class="alert alert-danger alert-dismissible fade show" role="alert"> | ||
<strong>Encountered error</strong> {{ error }} | ||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
</div> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="row"> | ||
<div class="col-md-6"> | ||
<h2>{{search_text}}</h2> | ||
<p> | ||
{% for item in response_json %} | ||
{% if item['type'] == 'footnote' %} | ||
<span style="font-weight: bold; font-size: 0.8rem; background-color: #88effc;">{{ item['text'] }}</span> | ||
{% else %} | ||
{{ item['text'] }} | ||
{% endif %} | ||
{% endfor %} | ||
</p> | ||
</div> | ||
<div class="col-md-6"> | ||
<ul class="list-group"> | ||
{% for item in source_json %} | ||
<li class="list-group-item"> | ||
<h5 class="mb-1"> | ||
<img src="https://www.google.com/s2/favicons?domain={{item['domain']}}" alt="Favicon"> | ||
<a href="{{item['url']}}">{{item['footnote']}} {{item['domain']}}</a> | ||
</h5> | ||
<h4 class="mb-1" style="font-family: 'Playfair Display', Georgia">{{item['title']}}</h4> | ||
<p class="mb-1">{{item['text']}}</p> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters