mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Allow markers to inspected for their content
This commit is contained in:
@ -672,7 +672,10 @@ function prepareOpenAIMessages({
|
||||
chatCompletion.log(error);
|
||||
}
|
||||
} finally {
|
||||
promptManager.populateTokenHandler(chatCompletion.getMessages());
|
||||
const messages = chatCompletion.getMessages();
|
||||
promptManager.populateTokenHandler(messages);
|
||||
promptManager.setMessages(messages);
|
||||
console.log(messages)
|
||||
|
||||
// All information are up-to-date, render without dry-run.
|
||||
if (false === dryRun) promptManager.render(false);
|
||||
@ -1289,6 +1292,14 @@ class MessageCollection {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
getChat() {
|
||||
return this.collection.reduce((acc, message) => {
|
||||
const name = message.name;
|
||||
if (message.content) acc.push({role: message.role, ...(name && { name }), content: message.content});
|
||||
return acc;
|
||||
}, []);
|
||||
}
|
||||
|
||||
getCollection() {
|
||||
return this.collection;
|
||||
}
|
||||
@ -1297,6 +1308,14 @@ class MessageCollection {
|
||||
this.collection.push(item);
|
||||
}
|
||||
|
||||
getItemByIdentifier(identifier) {
|
||||
return this.collection.find(item => item.identifier === identifier);
|
||||
}
|
||||
|
||||
hasItemWithIdentifier(identifier) {
|
||||
return this.collection.some(message => message.identifier === identifier);
|
||||
}
|
||||
|
||||
getTokens() {
|
||||
return this.collection.reduce((tokens, message) => tokens + message.getTokens(), 0);
|
||||
}
|
||||
@ -1373,7 +1392,7 @@ class ChatCompletion {
|
||||
}
|
||||
|
||||
has(identifier) {
|
||||
return this.messages.collection.some(message => message.identifier === identifier);
|
||||
return this.messages.hasItemWithIdentifier(identifier);
|
||||
}
|
||||
|
||||
getTotalTokenCount() {
|
||||
@ -1384,12 +1403,9 @@ class ChatCompletion {
|
||||
const chat = [];
|
||||
for (let item of this.messages.collection) {
|
||||
if (item instanceof MessageCollection) {
|
||||
const messages = item.collection.reduce((acc, message) => {
|
||||
const name = message.name;
|
||||
if (message.content) acc.push({role: message.role, ...(name && { name }), content: message.content});
|
||||
return acc;
|
||||
}, []);
|
||||
chat.push(...messages);
|
||||
chat.push(...item.getChat());
|
||||
} else {
|
||||
chat.push(item);
|
||||
}
|
||||
}
|
||||
return chat;
|
||||
|
Reference in New Issue
Block a user