Add plenty of features
This commit is contained in:
@@ -9,6 +9,7 @@ export enum LLMFlags{
|
||||
hasCache,
|
||||
hasFullSystemPrompt,
|
||||
hasFirstSystemPrompt,
|
||||
hasStreaming,
|
||||
requiresAlternateRole,
|
||||
mustStartWithUserInput,
|
||||
}
|
||||
@@ -26,6 +27,7 @@ export enum LLMProvider{
|
||||
WebLLM,
|
||||
Horde,
|
||||
AWS,
|
||||
AI21
|
||||
}
|
||||
|
||||
export enum LLMFormat{
|
||||
@@ -87,7 +89,7 @@ export const LLMModels: LLMModel[] = [
|
||||
name: 'GPT-3.5',
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [LLMFlags.hasFullSystemPrompt],
|
||||
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
{
|
||||
@@ -96,7 +98,7 @@ export const LLMModels: LLMModel[] = [
|
||||
name: 'InstructGPT-3.5',
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAILegacyInstruct,
|
||||
flags: [LLMFlags.hasFullSystemPrompt],
|
||||
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
{
|
||||
@@ -105,7 +107,7 @@ export const LLMModels: LLMModel[] = [
|
||||
name: 'GPT-4 Turbo',
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [LLMFlags.hasFullSystemPrompt],
|
||||
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
{
|
||||
@@ -116,7 +118,8 @@ export const LLMModels: LLMModel[] = [
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
recommended: true,
|
||||
parameters: OpenAIParameters,
|
||||
@@ -129,7 +132,8 @@ export const LLMModels: LLMModel[] = [
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
recommended: true,
|
||||
parameters: OpenAIParameters,
|
||||
@@ -141,7 +145,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -152,7 +157,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -163,7 +169,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -174,7 +181,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -185,7 +193,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -196,7 +205,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -207,7 +217,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -218,7 +229,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -229,7 +241,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -240,7 +253,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -251,7 +265,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -262,7 +277,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -273,7 +289,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -283,7 +300,10 @@ export const LLMModels: LLMModel[] = [
|
||||
name: 'GPT-4 Vision 1106',
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [LLMFlags.hasImageInput],
|
||||
flags: [
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
{
|
||||
@@ -293,7 +313,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -305,7 +326,8 @@ export const LLMModels: LLMModel[] = [
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -317,7 +339,8 @@ export const LLMModels: LLMModel[] = [
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -329,7 +352,8 @@ export const LLMModels: LLMModel[] = [
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -341,7 +365,8 @@ export const LLMModels: LLMModel[] = [
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -352,7 +377,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -363,7 +389,8 @@ export const LLMModels: LLMModel[] = [
|
||||
provider: LLMProvider.OpenAI,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [
|
||||
LLMFlags.hasFullSystemPrompt
|
||||
LLMFlags.hasFullSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: OpenAIParameters,
|
||||
},
|
||||
@@ -376,7 +403,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
recommended: true,
|
||||
parameters: ClaudeParameters,
|
||||
@@ -390,7 +418,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
recommended: true,
|
||||
parameters: ClaudeParameters,
|
||||
@@ -404,7 +433,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: ClaudeParameters,
|
||||
},
|
||||
@@ -417,7 +447,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: ClaudeParameters,
|
||||
},
|
||||
@@ -430,7 +461,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: ClaudeParameters,
|
||||
},
|
||||
@@ -443,7 +475,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: ClaudeParameters,
|
||||
},
|
||||
@@ -456,7 +489,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: ClaudeParameters,
|
||||
},
|
||||
@@ -469,7 +503,8 @@ export const LLMModels: LLMModel[] = [
|
||||
flags: [
|
||||
LLMFlags.hasPrefill,
|
||||
LLMFlags.hasImageInput,
|
||||
LLMFlags.hasFirstSystemPrompt
|
||||
LLMFlags.hasFirstSystemPrompt,
|
||||
LLMFlags.hasStreaming
|
||||
],
|
||||
parameters: ClaudeParameters,
|
||||
},
|
||||
@@ -593,7 +628,7 @@ export const LLMModels: LLMModel[] = [
|
||||
id: 'openrouter',
|
||||
provider: LLMProvider.AsIs,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasImageInput],
|
||||
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasImageInput, LLMFlags.hasStreaming],
|
||||
parameters: ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k'],
|
||||
recommended: true
|
||||
},
|
||||
@@ -930,7 +965,7 @@ export const LLMModels: LLMModel[] = [
|
||||
name: "Custom API",
|
||||
provider: LLMProvider.AsIs,
|
||||
format: LLMFormat.OpenAICompatible,
|
||||
flags: [LLMFlags.hasFullSystemPrompt],
|
||||
flags: [LLMFlags.hasFullSystemPrompt, LLMFlags.hasStreaming],
|
||||
recommended: true,
|
||||
parameters: ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k']
|
||||
}
|
||||
|
||||
@@ -1465,9 +1465,8 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
formated: promptbody,
|
||||
bias: emobias,
|
||||
currentChar: currentChar,
|
||||
temperature: 0.4,
|
||||
maxTokens: 30,
|
||||
}, 'submodel', abortSignal)
|
||||
}, 'emotion', abortSignal)
|
||||
|
||||
if(rq.type === 'fail' || rq.type === 'streaming' || rq.type === 'multiline'){
|
||||
if(abortSignal.aborted){
|
||||
|
||||
@@ -5,6 +5,7 @@ import { requestChatData } from "../request";
|
||||
import { HypaProcesser } from "./hypamemory";
|
||||
import { globalFetch } from "src/ts/globalApi.svelte";
|
||||
import { runSummarizer } from "../transformers";
|
||||
import { parseChatML } from "src/ts/parser.svelte";
|
||||
|
||||
export interface HypaV2Data {
|
||||
chunks: {
|
||||
@@ -83,7 +84,10 @@ async function summary(stringlizedChat: string): Promise<{ success: boolean; dat
|
||||
};
|
||||
}
|
||||
} else {
|
||||
const promptbody: OpenAIChat[] = [
|
||||
|
||||
let parsedPrompt = parseChatML(supaPrompt.replaceAll('{{slot}}', stringlizedChat))
|
||||
|
||||
const promptbody: OpenAIChat[] = parsedPrompt ?? [
|
||||
{
|
||||
role: "user",
|
||||
content: stringlizedChat
|
||||
@@ -99,7 +103,7 @@ async function summary(stringlizedChat: string): Promise<{ success: boolean; dat
|
||||
bias: {},
|
||||
useStreaming: false,
|
||||
noMultiGen: true
|
||||
}, 'submodel');
|
||||
}, 'memory');
|
||||
if (da.type === 'fail' || da.type === 'streaming' || da.type === 'multiline') {
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -7,6 +7,7 @@ import { stringlizeChat } from "../stringlize";
|
||||
import { globalFetch } from "src/ts/globalApi.svelte";
|
||||
import { runSummarizer } from "../transformers";
|
||||
import { getUserName } from "src/ts/util";
|
||||
import { parseChatML } from "src/ts/parser.svelte";
|
||||
|
||||
export async function supaMemory(
|
||||
chats:OpenAIChat[],
|
||||
@@ -252,7 +253,8 @@ export async function supaMemory(
|
||||
}
|
||||
}
|
||||
else {
|
||||
const promptbody:OpenAIChat[] = [
|
||||
let parsedPrompt = parseChatML(supaPrompt.replaceAll('{{slot}}', stringlizedChat))
|
||||
const promptbody:OpenAIChat[] = parsedPrompt ?? [
|
||||
{
|
||||
role: "user",
|
||||
content: stringlizedChat
|
||||
@@ -267,7 +269,7 @@ export async function supaMemory(
|
||||
bias: {},
|
||||
useStreaming: false,
|
||||
noMultiGen: true
|
||||
}, 'submodel')
|
||||
}, 'memory')
|
||||
if(da.type === 'fail' || da.type === 'streaming' || da.type === 'multiline'){
|
||||
return {
|
||||
currentTokens: currentTokens,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { MultiModal, OpenAIChat, OpenAIChatFull } from "./index.svelte";
|
||||
import { getCurrentCharacter, getDatabase, type character } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getDatabase, setDatabase, type character } from "../storage/database.svelte";
|
||||
import { pluginProcess } from "../plugins/plugins";
|
||||
import { language } from "../../lang";
|
||||
import { stringlizeAINChat, getStopStrings, unstringlizeAIN, unstringlizeChat } from "./stringlize";
|
||||
@@ -47,6 +47,7 @@ interface RequestDataArgumentExtended extends requestDataArgument{
|
||||
abortSignal?:AbortSignal
|
||||
modelInfo?:LLMModel
|
||||
customURL?:string
|
||||
mode?:ModelModeExtended
|
||||
}
|
||||
|
||||
type requestDataResponse = {
|
||||
@@ -89,12 +90,31 @@ interface OaiFunctions {
|
||||
|
||||
|
||||
export type Parameter = 'temperature'|'top_k'|'repetition_penalty'|'min_p'|'top_a'|'top_p'|'frequency_penalty'|'presence_penalty'
|
||||
export type ModelModeExtended = 'model'|'submodel'|'memory'|'emotion'|'otherAx'|'translate'
|
||||
type ParameterMap = {
|
||||
[key in Parameter]?: string;
|
||||
};
|
||||
|
||||
function applyParameters(data: { [key: string]: any }, parameters: Parameter[], rename: ParameterMap = {}) {
|
||||
function applyParameters(data: { [key: string]: any }, parameters: Parameter[], rename: ParameterMap, ModelMode:ModelModeExtended): { [key: string]: any } {
|
||||
const db = getDatabase()
|
||||
if(db.seperateParametersEnabled && ModelMode !== 'model'){
|
||||
if(ModelMode === 'submodel'){
|
||||
ModelMode = 'otherAx'
|
||||
}
|
||||
|
||||
for(const parameter of parameters){
|
||||
let value = db.seperateParameters[ModelMode][parameter]
|
||||
|
||||
if(value === -1000 || value === undefined){
|
||||
continue
|
||||
}
|
||||
|
||||
data[rename[parameter] ?? parameter] = value
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
for(const parameter of parameters){
|
||||
let value = 0
|
||||
switch(parameter){
|
||||
@@ -141,7 +161,7 @@ function applyParameters(data: { [key: string]: any }, parameters: Parameter[],
|
||||
return data
|
||||
}
|
||||
|
||||
export async function requestChatData(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
export async function requestChatData(arg:requestDataArgument, model:ModelModeExtended, abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
const db = getDatabase()
|
||||
let trys = 0
|
||||
while(true){
|
||||
@@ -240,7 +260,7 @@ function reformater(formated:OpenAIChat[],modelInfo:LLMModel){
|
||||
}
|
||||
|
||||
|
||||
export async function requestChatDataMain(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
export async function requestChatDataMain(arg:requestDataArgument, model:ModelModeExtended, abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
const db = getDatabase()
|
||||
const targ:RequestDataArgumentExtended = arg
|
||||
targ.formated = safeStructuredClone(arg.formated)
|
||||
@@ -255,6 +275,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
targ.multiGen = ((db.genTime > 1 && targ.aiModel.startsWith('gpt') && (!arg.continue)) && (!arg.noMultiGen))
|
||||
targ.abortSignal = abortSignal
|
||||
targ.modelInfo = getModelInfo(targ.aiModel)
|
||||
targ.mode = model
|
||||
if(targ.aiModel === 'reverse_proxy'){
|
||||
targ.modelInfo.internalID = db.customProxyRequestModel
|
||||
targ.modelInfo.format = db.customAPIFormat
|
||||
@@ -502,7 +523,7 @@ async function requestOpenAI(arg:RequestDataArgumentExtended):Promise<requestDat
|
||||
top_p: db.top_p,
|
||||
safe_prompt: false,
|
||||
max_tokens: arg.maxTokens,
|
||||
}, ['temperature', 'presence_penalty', 'frequency_penalty'] ),
|
||||
}, ['temperature', 'presence_penalty', 'frequency_penalty'], {}, arg.mode ),
|
||||
headers: {
|
||||
"Authorization": "Bearer " + db.mistralKey,
|
||||
},
|
||||
@@ -625,8 +646,11 @@ async function requestOpenAI(arg:RequestDataArgumentExtended):Promise<requestDat
|
||||
}
|
||||
}
|
||||
|
||||
body = applyParameters(body,
|
||||
aiModel === 'openrouter' ? ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k'] : ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty']
|
||||
body = applyParameters(
|
||||
body,
|
||||
aiModel === 'openrouter' ? ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty', 'repetition_penalty', 'min_p', 'top_a', 'top_k'] : ['temperature', 'top_p', 'frequency_penalty', 'presence_penalty'],
|
||||
{},
|
||||
arg.mode
|
||||
)
|
||||
|
||||
if(aiModel === 'reverse_proxy' && db.reverseProxyOobaMode){
|
||||
@@ -1465,7 +1489,7 @@ async function requestGoogleCloudVertex(arg:RequestDataArgumentExtended):Promise
|
||||
"maxOutputTokens": maxTokens,
|
||||
}, ['temperature', 'top_p'], {
|
||||
'top_p': "topP"
|
||||
}),
|
||||
}, arg.mode),
|
||||
safetySettings: uncensoredCatagory
|
||||
}
|
||||
|
||||
@@ -1523,11 +1547,22 @@ async function requestGoogleCloudVertex(arg:RequestDataArgumentExtended):Promise
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
return data.access_token;
|
||||
const token = data.access_token;
|
||||
|
||||
const db2 = getDatabase()
|
||||
db2.vertexAccessToken = token
|
||||
db2.vertexAccessTokenExpires = Date.now() + 3500 * 1000
|
||||
setDatabase(db2)
|
||||
return token;
|
||||
}
|
||||
|
||||
if(arg.modelInfo.format === LLMFormat.VertexAIGemini){
|
||||
headers['Authorization'] = "Bearer " + generateToken(db.google.clientEmail, db.google.privateKey)
|
||||
if(db.vertexAccessTokenExpires < Date.now()){
|
||||
headers['Authorization'] = "Bearer " + generateToken(db.vertexClientEmail, db.vertexPrivateKey)
|
||||
}
|
||||
else{
|
||||
headers['Authorization'] = "Bearer " + db.vertexAccessToken
|
||||
}
|
||||
}
|
||||
|
||||
const url = arg.customURL ?? (arg.modelInfo.format === LLMFormat.VertexAIGemini ?
|
||||
@@ -1606,7 +1641,7 @@ async function requestKobold(arg:RequestDataArgumentExtended):Promise<requestDat
|
||||
'top_a'
|
||||
], {
|
||||
'repetition_penalty': 'rep_pen'
|
||||
}) as KoboldGenerationInputSchema
|
||||
}, arg.mode) as KoboldGenerationInputSchema
|
||||
|
||||
const da = await globalFetch(url.toString(), {
|
||||
method: "POST",
|
||||
@@ -1802,7 +1837,7 @@ async function requestCohere(arg:RequestDataArgumentExtended):Promise<requestDat
|
||||
], {
|
||||
'top_k': 'k',
|
||||
'top_p': 'p',
|
||||
})
|
||||
}, arg.mode)
|
||||
|
||||
if(aiModel !== 'cohere-command-r-03-2024' && aiModel !== 'cohere-command-r-plus-04-2024'){
|
||||
body.safety_mode = "NONE"
|
||||
@@ -2091,7 +2126,7 @@ async function requestClaude(arg:RequestDataArgumentExtended):Promise<requestDat
|
||||
system: systemPrompt.trim(),
|
||||
max_tokens: maxTokens,
|
||||
stream: useStreaming ?? false
|
||||
}, ['temperature', 'top_k', 'top_p'])
|
||||
}, ['temperature', 'top_k', 'top_p'], {}, arg.mode)
|
||||
|
||||
if(systemPrompt === ''){
|
||||
delete body.system
|
||||
|
||||
@@ -448,6 +448,17 @@ export function setDatabase(data:Database){
|
||||
data.customAPIFormat ??= LLMFormat.OpenAICompatible
|
||||
data.systemContentReplacement ??= `system: {{slot}}`
|
||||
data.systemRoleReplacement ??= 'user'
|
||||
data.vertexAccessToken ??= ''
|
||||
data.vertexAccessTokenExpires ??= 0
|
||||
data.vertexClientEmail ??= ''
|
||||
data.vertexPrivateKey ??= ''
|
||||
data.seperateParametersEnabled ??= false
|
||||
data.seperateParameters = {
|
||||
memory: {},
|
||||
emotion: {},
|
||||
translate: {},
|
||||
otherAx: {}
|
||||
}
|
||||
changeLanguage(data.language)
|
||||
setDatabaseLite(data)
|
||||
}
|
||||
@@ -724,8 +735,6 @@ export interface Database{
|
||||
google: {
|
||||
accessToken: string
|
||||
projectId: string
|
||||
privateKey: string
|
||||
clientEmail: string
|
||||
}
|
||||
mistralKey?:string
|
||||
chainOfThought?:boolean
|
||||
@@ -825,6 +834,29 @@ export interface Database{
|
||||
customAPIFormat:LLMFormat
|
||||
systemContentReplacement:string
|
||||
systemRoleReplacement:'user'|'assistant'
|
||||
vertexPrivateKey: string
|
||||
vertexClientEmail: string
|
||||
vertexAccessToken: string
|
||||
vertexAccessTokenExpires: number
|
||||
seperateParametersEnabled:boolean
|
||||
seperateParameters:{
|
||||
memory: SeparateParameters,
|
||||
emotion: SeparateParameters,
|
||||
translate: SeparateParameters,
|
||||
otherAx: SeparateParameters
|
||||
}
|
||||
translateBeforeHTMLFormatting:boolean
|
||||
}
|
||||
|
||||
interface SeparateParameters{
|
||||
temperature?:number
|
||||
top_k?:number
|
||||
repetition_penalty?:number
|
||||
min_p?:number
|
||||
top_a?:number
|
||||
top_p?:number
|
||||
frequency_penalty?:number
|
||||
presence_penalty?:number
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
@@ -1519,6 +1551,7 @@ import type { HypaV2Data } from '../process/memory/hypav2';
|
||||
import { decodeRPack, encodeRPack } from '../rpack/rpack_bg';
|
||||
import { DBState, selectedCharID } from '../stores.svelte';
|
||||
import { LLMFormat } from '../model/modellist';
|
||||
import type { Parameter } from '../process/request';
|
||||
|
||||
export async function downloadPreset(id:number, type:'json'|'risupreset'|'return' = 'json'){
|
||||
saveCurrentPreset()
|
||||
|
||||
@@ -10,12 +10,17 @@ import { selectedCharID } from "../stores.svelte"
|
||||
import { getModuleRegexScripts } from "../process/modules"
|
||||
import { getNodetextToSentence, sleep } from "../util"
|
||||
import { processScriptFull } from "../process/scripts"
|
||||
import localforage from "localforage"
|
||||
|
||||
let cache={
|
||||
origin: [''],
|
||||
trans: ['']
|
||||
}
|
||||
|
||||
const LLMCacheStorage = localforage.createInstance({
|
||||
name: "LLMTranslateCache"
|
||||
})
|
||||
|
||||
let waitTrans = 0
|
||||
|
||||
export async function translate(text:string, reverse:boolean) {
|
||||
@@ -442,10 +447,10 @@ function needSuperChunkedTranslate(){
|
||||
return getDatabase().translatorType === 'deeplX'
|
||||
}
|
||||
|
||||
let llmCache = new Map<string, string>()
|
||||
async function translateLLM(text:string, arg:{to:string}){
|
||||
if(llmCache.has(text)){
|
||||
return llmCache.get(text)
|
||||
async function translateLLM(text:string, arg:{to:string}):Promise<string>{
|
||||
const cacheMatch = await LLMCacheStorage.getItem(text)
|
||||
if(cacheMatch){
|
||||
return cacheMatch as string
|
||||
}
|
||||
const styleDecodeRegex = /\<risu-style\>(.+?)\<\/risu-style\>/gms
|
||||
let styleDecodes:string[] = []
|
||||
@@ -489,7 +494,7 @@ async function translateLLM(text:string, arg:{to:string}){
|
||||
useStreaming: false,
|
||||
noMultiGen: true,
|
||||
maxTokens: db.translatorMaxResponse,
|
||||
}, 'submodel')
|
||||
}, 'translate')
|
||||
|
||||
if(rq.type === 'fail' || rq.type === 'streaming' || rq.type === 'multiline'){
|
||||
alertError(`${rq.result}`)
|
||||
@@ -498,6 +503,6 @@ async function translateLLM(text:string, arg:{to:string}){
|
||||
const result = rq.result.replace(/<style-data style-index="(\d+)" ?\/?>/g, (match, p1) => {
|
||||
return styleDecodes[parseInt(p1)] ?? ''
|
||||
}).replace(/<\/style-data>/g, '')
|
||||
llmCache.set(text, result)
|
||||
await LLMCacheStorage.setItem(text, result)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user