[feat] ooba formating
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -15,7 +15,7 @@ dist-ssr
|
|||||||
*.local
|
*.local
|
||||||
xplugin/
|
xplugin/
|
||||||
src-others/
|
src-others/
|
||||||
|
/memo.txt
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { OpenAIChat, OpenAIChatFull } from ".";
|
|||||||
import { DataBase, setDatabase, type character } from "../storage/database";
|
import { DataBase, setDatabase, type character } from "../storage/database";
|
||||||
import { pluginProcess } from "../plugins/plugins";
|
import { pluginProcess } from "../plugins/plugins";
|
||||||
import { language } from "../../lang";
|
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 { globalFetch, isNodeServer, isTauri } from "../storage/globalApi";
|
||||||
import { sleep } from "../util";
|
import { sleep } from "../util";
|
||||||
import { createDeep } from "./deepai";
|
import { createDeep } from "./deepai";
|
||||||
@@ -348,62 +348,31 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
case "textgen_webui":{
|
case "textgen_webui":{
|
||||||
let DURL = db.textgenWebUIURL
|
let DURL = db.textgenWebUIURL
|
||||||
let bodyTemplate:any
|
let bodyTemplate:any
|
||||||
const proompt = stringlizeChat(formated, currentChar?.name ?? '')
|
const proompt = stringlizeChatOba(formated, currentChar?.name ?? '')
|
||||||
const isNewAPI = DURL.includes('api')
|
const isNewAPI = DURL.includes('api')
|
||||||
const stopStrings = [`\nUser:`,`\nuser:`,`\n${db.username}:`]
|
const stopStrings = [`\nUser:`,`\nuser:`,`\n${db.username}:`]
|
||||||
|
console.log(proompt)
|
||||||
if(isNewAPI){
|
bodyTemplate = {
|
||||||
bodyTemplate = {
|
'max_new_tokens': db.maxResponse,
|
||||||
'max_new_tokens': db.maxResponse,
|
'do_sample': true,
|
||||||
'do_sample': true,
|
'temperature': (db.temperature / 100),
|
||||||
'temperature': (db.temperature / 100),
|
'top_p': 0.9,
|
||||||
'top_p': 0.9,
|
'typical_p': 1,
|
||||||
'typical_p': 1,
|
'repetition_penalty': db.PresensePenalty,
|
||||||
'repetition_penalty': db.PresensePenalty < 85 ? 0.85 : (db.PresensePenalty / 100),
|
'encoder_repetition_penalty': 1,
|
||||||
'encoder_repetition_penalty': 1,
|
'top_k': 100,
|
||||||
'top_k': 100,
|
'min_length': 0,
|
||||||
'min_length': 0,
|
'no_repeat_ngram_size': 0,
|
||||||
'no_repeat_ngram_size': 0,
|
'num_beams': 1,
|
||||||
'num_beams': 1,
|
'penalty_alpha': 0,
|
||||||
'penalty_alpha': 0,
|
'length_penalty': 1,
|
||||||
'length_penalty': 1,
|
'early_stopping': false,
|
||||||
'early_stopping': false,
|
'truncation_length': maxTokens,
|
||||||
'truncation_length': maxTokens,
|
'ban_eos_token': false,
|
||||||
'ban_eos_token': false,
|
'stopping_strings': stopStrings,
|
||||||
'stopping_strings': stopStrings,
|
'seed': -1,
|
||||||
'seed': -1,
|
add_bos_token: true,
|
||||||
add_bos_token: true,
|
prompt: proompt
|
||||||
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)] };
|
|
||||||
|
|
||||||
}
|
}
|
||||||
const res = await globalFetch(DURL, {
|
const res = await globalFetch(DURL, {
|
||||||
body: bodyTemplate,
|
body: bodyTemplate,
|
||||||
|
|||||||
@@ -23,6 +23,26 @@ export function stringlizeChat(formated:OpenAIChat[], char:string = ''){
|
|||||||
return resultString.join('\n\n') + `\n\n${char}:`
|
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 = ''){
|
export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string = ''){
|
||||||
let minIndex = -1
|
let minIndex = -1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user