mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Make groups on OAI work
This commit is contained in:
@ -1129,7 +1129,7 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs").
|
|||||||
let mesExamplesArray = mesExamples.split(/<START>/gi).slice(1).map(block => `<START>\n${block.trim()}\n`);
|
let mesExamplesArray = mesExamples.split(/<START>/gi).slice(1).map(block => `<START>\n${block.trim()}\n`);
|
||||||
|
|
||||||
if (main_api === 'openai') {
|
if (main_api === 'openai') {
|
||||||
const oai_chat = [...chat];
|
const oai_chat = [...chat].filter(x => !x.is_system);
|
||||||
|
|
||||||
if (type == 'swipe') {
|
if (type == 'swipe') {
|
||||||
oai_chat.pop();
|
oai_chat.pop();
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
name1,
|
name1,
|
||||||
name2,
|
name2,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
|
import { groups, selected_group } from "./group-chats.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
pin_examples,
|
pin_examples,
|
||||||
@ -81,6 +82,11 @@ function setOpenAIMessages(chat) {
|
|||||||
let role = chat[j]['is_user'] ? 'user' : 'assistant';
|
let role = chat[j]['is_user'] ? 'user' : 'assistant';
|
||||||
let content = chat[j]['mes'];
|
let content = chat[j]['mes'];
|
||||||
|
|
||||||
|
// for groups - prepend a character's name
|
||||||
|
if (selected_group) {
|
||||||
|
content = `${name2}: ${content}`;
|
||||||
|
}
|
||||||
|
|
||||||
// system messages produce no content
|
// system messages produce no content
|
||||||
if (chat[j]['is_system']) {
|
if (chat[j]['is_system']) {
|
||||||
role = 'system';
|
role = 'system';
|
||||||
@ -141,6 +147,11 @@ function parseExampleIntoIndividual(messageExampleString) {
|
|||||||
// remove char name
|
// remove char name
|
||||||
// strip to remove extra spaces
|
// strip to remove extra spaces
|
||||||
let parsed_msg = cur_msg_lines.join("\n").replace(name + ":", "").trim();
|
let parsed_msg = cur_msg_lines.join("\n").replace(name + ":", "").trim();
|
||||||
|
|
||||||
|
if (selected_group && role == 'assistant') {
|
||||||
|
parsed_msg = `${name}: ${parsed_msg}`;
|
||||||
|
}
|
||||||
|
|
||||||
result.push({ "role": role, "content": parsed_msg });
|
result.push({ "role": role, "content": parsed_msg });
|
||||||
cur_msg_lines = [];
|
cur_msg_lines = [];
|
||||||
}
|
}
|
||||||
@ -226,6 +237,14 @@ function prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldInfoAft
|
|||||||
openai_msgs.push(bias_msg);
|
openai_msgs.push(bias_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selected_group) {
|
||||||
|
const groupMembers = groups.find(x => x.id === selected_group)?.members;
|
||||||
|
const names = Array.isArray(groupMembers) ? groupMembers.join(', ') : '';
|
||||||
|
new_chat_msg.content = `[Start a new group chat. Group members: ${names}]`;
|
||||||
|
let group_nudge = { "role": "system", "content": `[Write the next reply only as ${name2}]` };
|
||||||
|
openai_msgs.push(group_nudge);
|
||||||
|
}
|
||||||
|
|
||||||
// The user wants to always have all example messages in the context
|
// The user wants to always have all example messages in the context
|
||||||
if (pin_examples) {
|
if (pin_examples) {
|
||||||
// first we send *all* example messages
|
// first we send *all* example messages
|
||||||
|
Reference in New Issue
Block a user