Fix prompt manager issues
This commit is contained in:
parent
9d495d6b47
commit
efa0f12349
|
@ -513,7 +513,8 @@ function populateChatHistory(prompts, chatCompletion, type = null, cyclePrompt =
|
||||||
const chatMessage = Message.fromPrompt(promptManager.preparePrompt(prompt));
|
const chatMessage = Message.fromPrompt(promptManager.preparePrompt(prompt));
|
||||||
|
|
||||||
if (true === promptManager.serviceSettings.names_in_completion && prompt.name) {
|
if (true === promptManager.serviceSettings.names_in_completion && prompt.name) {
|
||||||
chatMessage.name = promptManager.isValidName(prompt.name) ? prompt.name : promptManager.sanitizeName(prompt.name);
|
const messageName = promptManager.isValidName(prompt.name) ? prompt.name : promptManager.sanitizeName(prompt.name);
|
||||||
|
chatMessage.setName(messageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatCompletion.canAfford(chatMessage)) chatCompletion.insertAtStart(chatMessage, 'chatHistory');
|
if (chatCompletion.canAfford(chatMessage)) chatCompletion.insertAtStart(chatMessage, 'chatHistory');
|
||||||
|
@ -1371,7 +1372,7 @@ function countTokens(messages, full = false) {
|
||||||
|
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
const model = getTokenizerModel();
|
const model = getTokenizerModel();
|
||||||
const hash = getStringHash(message.content);
|
const hash = getStringHash(JSON.stringify(message));
|
||||||
const cacheKey = `${model}-${hash}`;
|
const cacheKey = `${model}-${hash}`;
|
||||||
const cachedCount = tokenCache[chatId][cacheKey];
|
const cachedCount = tokenCache[chatId][cacheKey];
|
||||||
|
|
||||||
|
@ -1443,7 +1444,7 @@ class Message {
|
||||||
this.role = role;
|
this.role = role;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
|
||||||
if (this.content) {
|
if (typeof this.content === 'string') {
|
||||||
this.tokens = tokenHandler.count({ role: this.role, content: this.content });
|
this.tokens = tokenHandler.count({ role: this.role, content: this.content });
|
||||||
} else {
|
} else {
|
||||||
this.tokens = 0;
|
this.tokens = 0;
|
||||||
|
@ -1452,6 +1453,7 @@ class Message {
|
||||||
|
|
||||||
setName(name) {
|
setName(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.tokens = tokenHandler.count({ role: this.role, content: this.content, name: this.name });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3460,7 +3460,7 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
|
||||||
config.responseType = 'stream';
|
config.responseType = 'stream';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function makeRequest(config, response_generate_openai, request, retries = 5, timeout = 1000) {
|
async function makeRequest(config, response_generate_openai, request, retries = 5, timeout = 5000) {
|
||||||
try {
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
|
|
||||||
|
@ -3482,7 +3482,7 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.status === 429 && retries > 0) {
|
if (error.response && error.response.status === 429 && retries > 0) {
|
||||||
console.log('Out of quota, retrying...');
|
console.log(`Out of quota, retrying in ${Math.round(timeout / 1000)}s`);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
makeRequest(config, response_generate_openai, request, retries - 1);
|
makeRequest(config, response_generate_openai, request, retries - 1);
|
||||||
}, timeout);
|
}, timeout);
|
||||||
|
|
Loading…
Reference in New Issue