mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Atomic treatment of message examples blocks in OpenAI
This commit is contained in:
@ -395,23 +395,22 @@ async function prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldI
|
|||||||
|
|
||||||
console.log(total_count);
|
console.log(total_count);
|
||||||
|
|
||||||
for (const example of openai_msgs_example) {
|
// each example block contains multiple user/bot messages
|
||||||
// get the current example block with multiple user/bot messages
|
for (let example_block of openai_msgs_example) {
|
||||||
let example_block = example;
|
if (example_block.length == 0) { continue; }
|
||||||
|
|
||||||
for (let k = 0; k < example_block.length; k++) {
|
// include the heading
|
||||||
if (example_block.length == 0) { continue; }
|
example_block = [new_chat_msg, ...example_block];
|
||||||
let example_count = countTokens(example_block[k], true);
|
|
||||||
// add all the messages from the example
|
// add the block only if there is enough space for all its messages
|
||||||
if ((total_count + example_count + start_chat_count) < (this_max_context - oai_settings.openai_max_tokens)) {
|
const example_count = countTokens(example_block, true);
|
||||||
if (k == 0) {
|
if ((total_count + example_count) < (this_max_context - oai_settings.openai_max_tokens)) {
|
||||||
examples_tosend.push(new_chat_msg);
|
examples_tosend.push(...example_block)
|
||||||
total_count += start_chat_count;
|
total_count += example_count;
|
||||||
}
|
}
|
||||||
examples_tosend.push(example_block[k]);
|
else {
|
||||||
total_count += example_count;
|
// early break since more examples probably won't fit anyway
|
||||||
}
|
break;
|
||||||
else { break; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user