Merge branch 'staging' into small-bookmark-updates

This commit is contained in:
Cohee
2024-09-13 21:10:12 +03:00
10 changed files with 95 additions and 84 deletions

View File

@@ -1797,7 +1797,7 @@ async function sendOpenAIRequest(type, messages, signal) {
const isQuiet = type === 'quiet';
const isImpersonate = type === 'impersonate';
const isContinue = type === 'continue';
const stream = oai_settings.stream_openai && !isQuiet && !isScale && !(isGoogle && oai_settings.google_model.includes('bison'));
const stream = oai_settings.stream_openai && !isQuiet && !isScale && !(isGoogle && oai_settings.google_model.includes('bison')) && !(isOAI && oai_settings.openai_model.startsWith('o1-'));
const useLogprobs = !!power_user.request_token_probabilities;
const canMultiSwipe = oai_settings.n > 1 && !isContinue && !isImpersonate && !isQuiet && (isOAI || isCustom);
@@ -1960,12 +1960,35 @@ async function sendOpenAIRequest(type, messages, signal) {
generate_data['seed'] = oai_settings.seed;
}
await eventSource.emit(event_types.CHAT_COMPLETION_SETTINGS_READY, generate_data);
if (isFunctionCallingSupported() && !stream) {
await registerFunctionTools(type, generate_data);
}
if (isOAI && oai_settings.openai_model.startsWith('o1-')) {
generate_data.messages.forEach((msg) => {
if (msg.role === 'system') {
msg.role = 'user';
}
});
generate_data.max_completion_tokens = generate_data.max_tokens;
delete generate_data.max_tokens;
delete generate_data.stream;
delete generate_data.logprobs;
delete generate_data.top_logprobs;
delete generate_data.n;
delete generate_data.temperature;
delete generate_data.top_p;
delete generate_data.frequency_penalty;
delete generate_data.presence_penalty;
delete generate_data.tools;
delete generate_data.tool_choice;
delete generate_data.stop;
// It does support logit_bias, but the tokenizer used and its effect is yet unknown.
// delete generate_data.logit_bias;
}
await eventSource.emit(event_types.CHAT_COMPLETION_SETTINGS_READY, generate_data);
const generate_url = '/api/backends/chat-completions/generate';
const response = await fetch(generate_url, {
method: 'POST',
@@ -2111,7 +2134,6 @@ async function checkFunctionToolCalls(data) {
const args = toolCall.function;
console.log('Function tool call:', toolCall);
await eventSource.emit(event_types.LLM_FUNCTION_TOOL_CALL, args);
data.allowEmptyResponse = true;
}
}
@@ -2125,7 +2147,6 @@ async function checkFunctionToolCalls(data) {
/** @type {FunctionToolCall} */
const args = { name: content.name, arguments: JSON.stringify(content.input) };
await eventSource.emit(event_types.LLM_FUNCTION_TOOL_CALL, args);
data.allowEmptyResponse = true;
}
}
}
@@ -2140,7 +2161,6 @@ async function checkFunctionToolCalls(data) {
const args = { name: toolCall.name, arguments: JSON.stringify(toolCall.parameters) };
console.log('Function tool call:', toolCall);
await eventSource.emit(event_types.LLM_FUNCTION_TOOL_CALL, args);
data.allowEmptyResponse = true;
}
}
}
@@ -3905,6 +3925,9 @@ function getMaxContextOpenAI(value) {
if (oai_settings.max_context_unlocked) {
return unlocked_max;
}
else if (value.startsWith('o1-')) {
return max_128k;
}
else if (value.includes('chatgpt-4o-latest') || value.includes('gpt-4-turbo') || value.includes('gpt-4o') || value.includes('gpt-4-1106') || value.includes('gpt-4-0125') || value.includes('gpt-4-vision')) {
return max_128k;
}

View File

@@ -2241,7 +2241,7 @@ function setEphemeralStopStrings(value) {
async function generateRawCallback(args, value) {
if (!value) {
console.warn('WARN: No argument provided for /genraw command');
return;
return '';
}
// Prevent generate recursion
@@ -2260,12 +2260,16 @@ async function generateRawCallback(args, value) {
setEphemeralStopStrings(resolveVariable(args?.stop));
const result = await generateRaw(value, '', isFalseBoolean(args?.instruct), quietToLoud, systemPrompt, length);
return result;
} catch (err) {
console.error('Error on /genraw generation', err);
toastr.error(err.message, 'API Error', { preventDuplicates: true });
} finally {
if (lock) {
activateSendButtons();
}
flushEphemeralStoppingStrings();
}
return '';
}
/**
@@ -2291,12 +2295,16 @@ async function generateCallback(args, value) {
const name = args?.name;
const result = await generateQuietPrompt(value, quietToLoud, false, '', name, length);
return result;
} catch (err) {
console.error('Error on /gen generation', err);
toastr.error(err.message, 'API Error', { preventDuplicates: true });
} finally {
if (lock) {
activateSendButtons();
}
flushEphemeralStoppingStrings();
}
return '';
}
/**

View File

@@ -108,6 +108,7 @@ const KNOWN_DECORATORS = ['@@activate', '@@dont_activate'];
* @property {number} [cooldown] The cooldown of the entry
* @property {number} [delay] The delay of the entry
* @property {string[]} [decorators] Array of decorators for the entry
* @property {number} [hash] The hash of the entry
*/
/**
@@ -382,12 +383,6 @@ class WorldInfoBuffer {
* Represents a timed effects manager for World Info.
*/
class WorldInfoTimedEffects {
/**
* Cache for entry hashes. Uses weak map to avoid memory leaks.
* @type {WeakMap<WIScanEntry, number>}
*/
#entryHashCache = new WeakMap();
/**
* Array of chat messages.
* @type {string[]}
@@ -485,13 +480,7 @@ class WorldInfoTimedEffects {
* @returns {number} String hash
*/
#getEntryHash(entry) {
if (this.#entryHashCache.has(entry)) {
return this.#entryHashCache.get(entry);
}
const hash = getStringHash(JSON.stringify(entry));
this.#entryHashCache.set(entry, hash);
return hash;
return entry.hash;
}
/**
@@ -3603,10 +3592,13 @@ export async function getSortedEntries() {
// Chat lore always goes first
entries = [...chatLore.sort(sortFn), ...entries];
// Parse decorators
// Calculate hash and parse decorators. Split maps to preserve old hashes.
entries = entries.map((entry) => {
const [decorators, content] = parseDecorators(entry.content || '');
return { ...entry, decorators, content };
}).map((entry) => {
const hash = getStringHash(JSON.stringify(entry));
return { ...entry, hash };
});
console.debug(`[WI] Found ${entries.length} world lore entries. Sorted by strategy`, Object.entries(world_info_insertion_strategy).find((x) => x[1] === world_info_character_strategy));