Browse Source

Add RequestVerificationToken logic fo ajax prefilter, Tidy up js cancel logic

tags/v0.4.2-preview
sa_ddam213 3 years ago
parent
commit
ef8cf0b283
3 changed files with 38 additions and 23 deletions
  1. +6
    -19
      LLama.Web/Pages/Interactive.cshtml
  2. +1
    -1
      LLama.Web/Pages/Interactive.cshtml.cs
  3. +31
    -3
      LLama.Web/wwwroot/js/site.js

+ 6
- 19
LLama.Web/Pages/Interactive.cshtml View File

@@ -227,35 +227,22 @@
}


const sendPrompt = () => {
const sendPrompt = async () => {
const text = chatInput.val();
if (text) {
disableControls();
outputContainer.append(Mustache.render(outputUserTemplate, { text: text, date: getDateTime() }));
connection.invoke('SendPrompt', text);
await connection.invoke('SendPrompt', text);
chatInput.val(null);
scrollToBottom(true);
}
}

const cancelPrompt = () => {
//TODO: Need to cancel inference via http as signalr will synchronize requests
// waiting on ModelSessionService so we can locate an cancel ModelSessions outside the Hub
//connection.invoke('CancelPrompt');

$.ajax({
url: '?handler=Cancel',
type: 'POST',
contentType: "application/json; charset=utf-8",
headers: {
RequestVerificationToken:
$('input:hidden[name="__RequestVerificationToken"]').val()
},
data: JSON.stringify({ connectionId: connectionId })
})
const cancelPrompt = async () => {
await ajaxPostJsonAsync('?handler=Cancel', { connectionId: connectionId });
}

const loadModel = () => {
const loadModel = async () => {
const modelName = getSelectedModel();
const promptName = getSelectedPrompt();
const parameterName = getSelectedParameter();
@@ -265,7 +252,7 @@
}

disableControls();
connection.invoke('LoadModel', modelName, promptName, parameterName);
await connection.invoke('LoadModel', modelName, promptName, parameterName);
}




+ 1
- 1
LLama.Web/Pages/Interactive.cshtml.cs View File

@@ -24,7 +24,7 @@ namespace LLama.Web.Pages
{
}

public async Task<IActionResult> OnPostCancel([FromBody]CancelModel model)
public async Task<IActionResult> OnPostCancel(CancelModel model)
{
await _modelSessionService.CancelAsync(model.ConnectionId);
return new JsonResult(default);


+ 31
- 3
LLama.Web/wwwroot/js/site.js View File

@@ -1,4 +1,32 @@
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.
let _requestVerificationToken = $('input[name="__RequestVerificationToken"]').val();
$.ajaxPrefilter(function (options, originalOptions) {
options.async = true;
if (options.type.toUpperCase() == "POST") {
options.data = $.param($.extend(originalOptions.data, { __RequestVerificationToken: _requestVerificationToken }));
}
});
$.ajaxSetup({ cache: false });

// Write your JavaScript code.

const ajaxPostJsonAsync = (url, data) => {
return $.ajax({
url: url,
cache: false,
async: true,
type: "POST",
dataType: 'json',
data: data
});
}


const ajaxGetJsonAsync = (url, data) => {
return $.ajax({
url: url,
cache: false,
async: true,
type: "GET",
dataType: 'json',
data: data
});
}

Loading…
Cancel
Save