Compare commits
No commits in common. "f228f7891548c1fe35700c9983dbfe387d722c5a" and "f25621daef6ec99c06880e425edb9d19338782df" have entirely different histories.
f228f78915
...
f25621daef
|
|
@ -161,12 +161,6 @@ export namespace Connection {
|
|||
if (extraSettings.max_length && extraSettings.max_length < maxLength) {
|
||||
maxLength = extraSettings.max_length;
|
||||
}
|
||||
const baseTemperature = extraSettings.temperature ?? DEFAULT_GENERATION_SETTINGS.temperature;
|
||||
let currentTemperature = baseTemperature;
|
||||
const MAX_TEMPERATURE = 2.0;
|
||||
const TEMP_INCREMENT = 0.15;
|
||||
const RECOVERY_LENGTH = 16;
|
||||
|
||||
const requestData = {
|
||||
prompt,
|
||||
params: {
|
||||
|
|
@ -176,13 +170,11 @@ export namespace Connection {
|
|||
max_context_length: model.maxContext,
|
||||
max_length: maxLength,
|
||||
rep_pen_range: Math.min(model.maxContext, 4096),
|
||||
temperature: currentTemperature,
|
||||
},
|
||||
models: model.hordeNames,
|
||||
workers: model.workers,
|
||||
};
|
||||
const bannedTokens = requestData.params.banned_tokens ?? [];
|
||||
let recoveryMode = false;
|
||||
|
||||
const { signal } = abortController;
|
||||
|
||||
|
|
@ -229,54 +221,34 @@ export namespace Connection {
|
|||
|
||||
if (response?.text) {
|
||||
text = response.text;
|
||||
let minStopIdx = text.length;
|
||||
for (const sequence of requestData.params.stop_sequence) {
|
||||
const stopIdx = text.indexOf(sequence);
|
||||
if (stopIdx >= 0 && stopIdx < minStopIdx) {
|
||||
minStopIdx = stopIdx;
|
||||
if (stopIdx >= 0) {
|
||||
text = text.slice(0, stopIdx);
|
||||
}
|
||||
}
|
||||
if (minStopIdx < text.length) {
|
||||
text = text.slice(0, minStopIdx);
|
||||
}
|
||||
|
||||
const locaseText = text.toLowerCase();
|
||||
let unsloppedText = text;
|
||||
let slopDetected = false;
|
||||
let minSlopIdx = text.length;
|
||||
let detectedBan = '';
|
||||
for (const ban of bannedTokens) {
|
||||
const slopIdx = locaseText.indexOf(ban.toLowerCase());
|
||||
if (slopIdx >= 0 && slopIdx < minSlopIdx) {
|
||||
minSlopIdx = slopIdx;
|
||||
detectedBan = ban;
|
||||
slopDetected = true;
|
||||
if (slopIdx >= 0) {
|
||||
console.log(`[horde] slop '${ban}' detected at ${slopIdx}`);
|
||||
unsloppedText = unsloppedText.slice(0, slopIdx).trimEnd();
|
||||
}
|
||||
}
|
||||
if (slopDetected) {
|
||||
console.log(`[horde] slop '${detectedBan}' detected at ${minSlopIdx}`);
|
||||
unsloppedText = unsloppedText.slice(0, minSlopIdx).trimEnd();
|
||||
}
|
||||
|
||||
yield { text: unsloppedText, cost: response.cost };
|
||||
|
||||
requestData.prompt += unsloppedText;
|
||||
|
||||
if (slopDetected) {
|
||||
recoveryMode = true;
|
||||
requestData.params.max_length = RECOVERY_LENGTH;
|
||||
currentTemperature = Math.min(MAX_TEMPERATURE, currentTemperature + TEMP_INCREMENT);
|
||||
requestData.params.temperature = currentTemperature;
|
||||
requestData.params.top_p = Math.min(0.98, 0.92 + (currentTemperature - baseTemperature) * 0.02);
|
||||
} else if (recoveryMode) {
|
||||
recoveryMode = false;
|
||||
requestData.params.max_length = maxLength;
|
||||
requestData.params.temperature = baseTemperature;
|
||||
requestData.params.top_p = 0.92;
|
||||
currentTemperature = baseTemperature;
|
||||
} else {
|
||||
if (unsloppedText === text) {
|
||||
return; // we are finished
|
||||
}
|
||||
|
||||
if (unsloppedText.length === 0) {
|
||||
requestData.params.temperature += 0.05;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (!signal.aborted) {
|
||||
|
|
|
|||
|
|
@ -423,7 +423,6 @@ export namespace Huggingface {
|
|||
applyTemplate(templateString, {
|
||||
messages,
|
||||
add_generation_prompt: true,
|
||||
enable_thinking: false,
|
||||
tools: functions?.map(convertFunctionToTool),
|
||||
})
|
||||
);
|
||||
|
|
|
|||
|
|
@ -25,48 +25,50 @@ export namespace MessageTools {
|
|||
}
|
||||
|
||||
export const format = (message: string): string => {
|
||||
const replaceRegex = /(\*\*?|")/ig;
|
||||
const replaceRegex = /([*"]\*?)/ig;
|
||||
const splitToken = '___SPLIT_AWOORWA___';
|
||||
|
||||
const preparedMessage = message.replace(replaceRegex, `${splitToken}$1${splitToken}`);
|
||||
const parts = preparedMessage.split(splitToken);
|
||||
|
||||
const stack: string[] = [];
|
||||
let isText = true;
|
||||
let keepPart = true;
|
||||
|
||||
let resultHTML = '';
|
||||
|
||||
for (const part of parts) {
|
||||
const isClose = stack.at(-1) === part;
|
||||
if (isClose) {
|
||||
stack.pop();
|
||||
if (part === '*' || part === '**') {
|
||||
resultHTML += `</span>`;
|
||||
} else if (part === '"') {
|
||||
resultHTML += `"</span>`;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (isText) {
|
||||
if (part === '*') {
|
||||
stack.push(part);
|
||||
isText = false;
|
||||
keepPart = false;
|
||||
resultHTML += `<span class="italic">`;
|
||||
} else if (part === '**') {
|
||||
stack.push(part);
|
||||
isText = false;
|
||||
keepPart = false;
|
||||
resultHTML += `<span class="bold">`;
|
||||
} else if (part === '"') {
|
||||
stack.push(part);
|
||||
isText = false;
|
||||
keepPart = true;
|
||||
resultHTML += `<span class="quote">"`;
|
||||
} else {
|
||||
resultHTML += part;
|
||||
}
|
||||
} else {
|
||||
if (part === '*' || part === '**') {
|
||||
resultHTML += `</span>`;
|
||||
isText = true;
|
||||
} else if (part === '"') {
|
||||
resultHTML += `"</span>`;
|
||||
isText = true;
|
||||
} else {
|
||||
resultHTML += part;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (stack.length) {
|
||||
const part = stack.pop();
|
||||
if (part === '*' || part === '**') {
|
||||
if (!isText) {
|
||||
resultHTML += `</span>`;
|
||||
} else if (part === '"') {
|
||||
resultHTML += `"</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
return resultHTML;
|
||||
|
|
|
|||
Loading…
Reference in New Issue