From e722efb73dd2feaa97f10b6470c06db4d90401db Mon Sep 17 00:00:00 2001 From: kwaroran Date: Sun, 9 Jul 2023 17:24:10 +0900 Subject: [PATCH] [feat] ooba formating --- .gitignore | 2 +- src/ts/process/request.ts | 79 +++++++++++------------------------- src/ts/process/stringlize.ts | 20 +++++++++ 3 files changed, 45 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index b8fe2c1f..5dfb985c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ dist-ssr *.local xplugin/ src-others/ - +/memo.txt # Editor directories and files .vscode/* !.vscode/extensions.json diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index 83cb20d9..71bb1c12 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -3,7 +3,7 @@ import type { OpenAIChat, OpenAIChatFull } from "."; import { DataBase, setDatabase, type character } from "../storage/database"; import { pluginProcess } from "../plugins/plugins"; import { language } from "../../lang"; -import { stringlizeAINChat, stringlizeChat, unstringlizeAIN, unstringlizeChat } from "./stringlize"; +import { stringlizeAINChat, stringlizeChat, stringlizeChatOba, unstringlizeAIN, unstringlizeChat } from "./stringlize"; import { globalFetch, isNodeServer, isTauri } from "../storage/globalApi"; import { sleep } from "../util"; import { createDeep } from "./deepai"; @@ -348,62 +348,31 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' case "textgen_webui":{ let DURL = db.textgenWebUIURL let bodyTemplate:any - const proompt = stringlizeChat(formated, currentChar?.name ?? '') + const proompt = stringlizeChatOba(formated, currentChar?.name ?? '') const isNewAPI = DURL.includes('api') const stopStrings = [`\nUser:`,`\nuser:`,`\n${db.username}:`] - - if(isNewAPI){ - bodyTemplate = { - 'max_new_tokens': db.maxResponse, - 'do_sample': true, - 'temperature': (db.temperature / 100), - 'top_p': 0.9, - 'typical_p': 1, - 'repetition_penalty': db.PresensePenalty < 85 ? 0.85 : (db.PresensePenalty / 100), - 'encoder_repetition_penalty': 1, - 'top_k': 100, - 'min_length': 0, - 'no_repeat_ngram_size': 0, - 'num_beams': 1, - 'penalty_alpha': 0, - 'length_penalty': 1, - 'early_stopping': false, - 'truncation_length': maxTokens, - 'ban_eos_token': false, - 'stopping_strings': stopStrings, - 'seed': -1, - add_bos_token: true, - prompt: proompt - } - } - else{ - const payload = [ - proompt, - { - 'max_new_tokens': 80, - 'do_sample': true, - 'temperature': (db.temperature / 100), - 'top_p': 0.9, - 'typical_p': 1, - 'repetition_penalty': db.PresensePenalty < 85 ? 0.85 : (db.PresensePenalty / 100), - 'encoder_repetition_penalty': 1, - 'top_k': 100, - 'min_length': 0, - 'no_repeat_ngram_size': 0, - 'num_beams': 1, - 'penalty_alpha': 0, - 'length_penalty': 1, - 'early_stopping': false, - 'truncation_length': maxTokens, - 'ban_eos_token': false, - 'custom_stopping_strings': stopStrings, - 'seed': -1, - add_bos_token: true, - } - ]; - - bodyTemplate = { "data": [JSON.stringify(payload)] }; - + console.log(proompt) + bodyTemplate = { + 'max_new_tokens': db.maxResponse, + 'do_sample': true, + 'temperature': (db.temperature / 100), + 'top_p': 0.9, + 'typical_p': 1, + 'repetition_penalty': db.PresensePenalty, + 'encoder_repetition_penalty': 1, + 'top_k': 100, + 'min_length': 0, + 'no_repeat_ngram_size': 0, + 'num_beams': 1, + 'penalty_alpha': 0, + 'length_penalty': 1, + 'early_stopping': false, + 'truncation_length': maxTokens, + 'ban_eos_token': false, + 'stopping_strings': stopStrings, + 'seed': -1, + add_bos_token: true, + prompt: proompt } const res = await globalFetch(DURL, { body: bodyTemplate, diff --git a/src/ts/process/stringlize.ts b/src/ts/process/stringlize.ts index 5381c77a..fb130d44 100644 --- a/src/ts/process/stringlize.ts +++ b/src/ts/process/stringlize.ts @@ -23,6 +23,26 @@ export function stringlizeChat(formated:OpenAIChat[], char:string = ''){ return resultString.join('\n\n') + `\n\n${char}:` } +export function stringlizeChatOba(formated:OpenAIChat[], char:string = ''){ + let resultString:string[] = [] + for(const form of formated){ + if(form.role === 'system'){ + resultString.push(form.content) + } + else if(form.name){ + resultString.push(form.name + ": " + form.content) + } + else if(form.role === 'assistant' && char){ + resultString.push(char + ": " + form.content) + + } + else{ + resultString.push(form.content) + } + } + return resultString.join('\n\n') + `\n\n${char}:` +} + export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string = ''){ let minIndex = -1