Non-streaming logprobs for Aphrodite

This commit is contained in:
Cohee 2024-02-24 20:53:23 +02:00
parent d140b8d5be
commit d5bf9fc28c
2 changed files with 8 additions and 3 deletions

View File

@ -4489,6 +4489,7 @@ function parseAndSaveLogprobs(data, continueFrom) {
case textgen_types.LLAMACPP: {
logprobs = data?.completion_probabilities?.map(x => parseTextgenLogprobs(x.content, [x])) || null;
} break;
case textgen_types.APHRODITE:
case textgen_types.TABBY: {
logprobs = parseTabbyLogprobs(data) || null;
} break;

View File

@ -153,8 +153,9 @@ function renderTopLogprobs() {
let matched = false;
for (const [token, probability, log] of candidates) {
const container = $('<button class="flex-container flexFlowColumn logprobs_top_candidate"></button>');
const tokenNormalized = String(token).replace(/^▁/g, ' ');
if (token === selectedToken) {
if (token === selectedToken || tokenNormalized === selectedToken) {
matched = true;
container.addClass('selected');
}
@ -222,7 +223,7 @@ function onAlternativeClicked(tokenLogprobs, alternative) {
const replaceIndex = messageLogprobs.findIndex(x => x === tokenLogprobs);
const tokens = messageLogprobs.slice(0, replaceIndex + 1).map(({ token }) => token);
tokens[replaceIndex] = alternative;
tokens[replaceIndex] = String(alternative).replace(/^▁/g, ' ');
const prefix = continueFrom || '';
const prompt = prefix + tokens.join('');
@ -335,7 +336,7 @@ function createSwipe(messageId, prompt) {
* @returns {string}
*/
function toVisibleWhitespace(input) {
return input.replace(/ /g, '·').replace(/\n/g, '↵');
return input.replace(/ /g, '·').replace(/▁/g, '·').replace(/\n/g, '↵');
}
/**
@ -354,6 +355,9 @@ function withVirtualWhitespace(text, span) {
if (text.match(/\s$/)) {
result.push($(document.createTextNode('\u200b')));
}
if (text.match(/^▁/)) {
result.unshift(document.createTextNode('\u200b'));
}
// line breaks are trickier. we don't currently handle consecutive line
// breaks or line breaks occuring in between non-whitespace characters, but
// tokenizers generally don't produce those anyway.