#1412 Add randomized user ids to OpenAI

This commit is contained in:
Cohee 2023-11-29 00:11:10 +02:00
parent 9145406522
commit e541c2b186
3 changed files with 18 additions and 2 deletions

View File

@ -50,4 +50,7 @@ extras:
captioningModel: Xenova/vit-gpt2-image-captioning captioningModel: Xenova/vit-gpt2-image-captioning
embeddingModel: Xenova/all-mpnet-base-v2 embeddingModel: Xenova/all-mpnet-base-v2
promptExpansionModel: Cohee/fooocus_expansion-onnx promptExpansionModel: Cohee/fooocus_expansion-onnx
# -- OPENAI CONFIGURATION --
openai:
# Will send a random user ID to OpenAI completion API
randomizeUserId: false

View File

@ -55,7 +55,7 @@ const characterCardParser = require('./src/character-card-parser.js');
const contentManager = require('./src/content-manager'); const contentManager = require('./src/content-manager');
const statsHelpers = require('./statsHelpers.js'); const statsHelpers = require('./statsHelpers.js');
const { readSecret, migrateSecrets, SECRET_KEYS } = require('./src/secrets'); const { readSecret, migrateSecrets, SECRET_KEYS } = require('./src/secrets');
const { delay, getVersion, deepMerge, getConfigValue, color } = require('./src/util'); const { delay, getVersion, deepMerge, getConfigValue, color, uuidv4 } = require('./src/util');
const { invalidateThumbnail, ensureThumbnailCache } = require('./src/thumbnails'); const { invalidateThumbnail, ensureThumbnailCache } = require('./src/thumbnails');
const { getTokenizerModel, getTiktokenTokenizer, loadTokenizers, TEXT_COMPLETION_MODELS, getSentencepiceTokenizer, sentencepieceTokenizers } = require('./src/tokenizers'); const { getTokenizerModel, getTiktokenTokenizer, loadTokenizers, TEXT_COMPLETION_MODELS, getSentencepiceTokenizer, sentencepieceTokenizers } = require('./src/tokenizers');
const { convertClaudePrompt } = require('./src/chat-completion'); const { convertClaudePrompt } = require('./src/chat-completion');
@ -3247,6 +3247,10 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
api_key_openai = request.body.reverse_proxy ? request.body.proxy_password : readSecret(SECRET_KEYS.OPENAI); api_key_openai = request.body.reverse_proxy ? request.body.proxy_password : readSecret(SECRET_KEYS.OPENAI);
headers = {}; headers = {};
bodyParams = {}; bodyParams = {};
if (getConfigValue('openai.randomizeUserId', false)) {
bodyParams['user'] = uuidv4();
}
} else { } else {
api_url = 'https://openrouter.ai/api/v1'; api_url = 'https://openrouter.ai/api/v1';
api_key_openai = readSecret(SECRET_KEYS.OPENROUTER); api_key_openai = readSecret(SECRET_KEYS.OPENROUTER);

View File

@ -259,6 +259,14 @@ const color = {
white: (mess) => color.byNum(mess, 37) white: (mess) => color.byNum(mess, 37)
}; };
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
module.exports = { module.exports = {
getConfig, getConfig,
getConfigValue, getConfigValue,
@ -270,4 +278,5 @@ module.exports = {
delay, delay,
deepMerge, deepMerge,
color, color,
uuidv4,
}; };