feat: add trigger effect RunAxLLM (#752)
# PR Checklist - [ ] Have you checked if it works normally in all models? *Ignore this if it doesn't use models.* - [ ] Have you checked if it works normally in all web, local, and node hosted versions? If it doesn't, have you blocked it in those versions? - [ ] Have you added type definitions? # Description This PR introduces new trigger effect 'RunAxLLM' which allows running auxiliary model separately from the main model. Basically, the logic is the same except that a request of type 'otherAx' is made instead of 'model'.
This commit is contained in:
@@ -842,6 +842,7 @@ export const languageEnglish = {
|
|||||||
checkCorruption: "Check Corruption",
|
checkCorruption: "Check Corruption",
|
||||||
showPromptComparison: "Show Prompt Comparison",
|
showPromptComparison: "Show Prompt Comparison",
|
||||||
inlayErrorResponse: "Inlay Error Response",
|
inlayErrorResponse: "Inlay Error Response",
|
||||||
|
triggerEffRunAxLLM: "Run Auxiliary Model",
|
||||||
hypaV3Settings: {
|
hypaV3Settings: {
|
||||||
descriptionLabel: "HypaMemory V3 is a long-term memory system that uses both summarization and vector search.",
|
descriptionLabel: "HypaMemory V3 is a long-term memory system that uses both summarization and vector search.",
|
||||||
supaMemoryPromptPlaceHolder: "Leave it blank to use default",
|
supaMemoryPromptPlaceHolder: "Leave it blank to use default",
|
||||||
|
|||||||
@@ -768,6 +768,7 @@ export const languageKorean = {
|
|||||||
"translateBeforeHTMLFormatting": "HTML 포맷 전 번역",
|
"translateBeforeHTMLFormatting": "HTML 포맷 전 번역",
|
||||||
"retranslate": "다시 번역",
|
"retranslate": "다시 번역",
|
||||||
"loading": "로딩중",
|
"loading": "로딩중",
|
||||||
|
"triggerEffRunAxLLM": "보조 모델 실행",
|
||||||
"autoTranslateCachedOnly": "캐시된 메시지만 자동 번역",
|
"autoTranslateCachedOnly": "캐시된 메시지만 자동 번역",
|
||||||
"hypaV3Settings": {
|
"hypaV3Settings": {
|
||||||
"descriptionLabel": "HypaMemory V3는 요약과 벡터 검색을 모두 사용하는 장기 기억 시스템입니다.",
|
"descriptionLabel": "HypaMemory V3는 요약과 벡터 검색을 모두 사용하는 장기 기억 시스템입니다.",
|
||||||
|
|||||||
@@ -304,6 +304,13 @@
|
|||||||
index: ''
|
index: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(effect.type === 'runAxLLM'){
|
||||||
|
value.effect[i] = {
|
||||||
|
type: 'runAxLLM',
|
||||||
|
value: '',
|
||||||
|
inputVar: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
}}>
|
}}>
|
||||||
<OptionInput value="setvar">{language.triggerEffSetVar}</OptionInput>
|
<OptionInput value="setvar">{language.triggerEffSetVar}</OptionInput>
|
||||||
<OptionInput value="impersonate">{language.triggerEffImperson}</OptionInput>
|
<OptionInput value="impersonate">{language.triggerEffImperson}</OptionInput>
|
||||||
@@ -319,6 +326,7 @@
|
|||||||
<OptionInput value="runImgGen">{language.runImgGen}</OptionInput>
|
<OptionInput value="runImgGen">{language.runImgGen}</OptionInput>
|
||||||
<OptionInput value="cutchat">{language.cutChat}</OptionInput>
|
<OptionInput value="cutchat">{language.cutChat}</OptionInput>
|
||||||
<OptionInput value="modifychat">{language.modifyChat}</OptionInput>
|
<OptionInput value="modifychat">{language.modifyChat}</OptionInput>
|
||||||
|
<OptionInput value="runAxLLM">{language.triggerEffRunAxLLM}</OptionInput>
|
||||||
</SelectInput>
|
</SelectInput>
|
||||||
{#if
|
{#if
|
||||||
(value.type !== 'start' && (effect.type === 'systemprompt' || effect.type === 'stop')) ||
|
(value.type !== 'start' && (effect.type === 'systemprompt' || effect.type === 'stop')) ||
|
||||||
@@ -333,7 +341,8 @@
|
|||||||
effect.type === 'showAlert' ||
|
effect.type === 'showAlert' ||
|
||||||
effect.type === 'sendAIprompt' ||
|
effect.type === 'sendAIprompt' ||
|
||||||
effect.type === 'extractRegex' ||
|
effect.type === 'extractRegex' ||
|
||||||
effect.type === 'runImgGen'
|
effect.type === 'runImgGen' ||
|
||||||
|
effect.type === 'runAxLLM'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
<span class="text-red-400 text-sm">{language.triggerLowLevelOnly}</span>
|
<span class="text-red-400 text-sm">{language.triggerLowLevelOnly}</span>
|
||||||
@@ -459,6 +468,14 @@
|
|||||||
<TextAreaInput highlight bind:value={effect.value} />
|
<TextAreaInput highlight bind:value={effect.value} />
|
||||||
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if effect.type === 'runAxLLM'}
|
||||||
|
<span class="text-textcolor2 text-sm">{language.prompt} <Help key="triggerLLMPrompt" /></span>
|
||||||
|
<TextAreaInput highlight bind:value={effect.value} />
|
||||||
|
|
||||||
|
<span class="text-textcolor2 text-sm">{language.resultStoredVar}</span>
|
||||||
|
<TextInput bind:value={effect.inputVar} />
|
||||||
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -419,6 +419,64 @@ export async function runLua(code:string, arg:{
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
luaEngine.global.set('axLLMMain', async (id:string, promptStr:string) => {
|
||||||
|
let prompt:{
|
||||||
|
role: string,
|
||||||
|
content: string
|
||||||
|
}[] = JSON.parse(promptStr)
|
||||||
|
if(!LuaLowLevelIds.has(id)){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let promptbody:OpenAIChat[] = prompt.map((dict) => {
|
||||||
|
let role:'system'|'user'|'assistant' = 'assistant'
|
||||||
|
switch(dict['role']){
|
||||||
|
case 'system':
|
||||||
|
case 'sys':
|
||||||
|
role = 'system'
|
||||||
|
break
|
||||||
|
case 'user':
|
||||||
|
role = 'user'
|
||||||
|
break
|
||||||
|
case 'assistant':
|
||||||
|
case 'bot':
|
||||||
|
case 'char':{
|
||||||
|
role = 'assistant'
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
content: dict['content'] ?? '',
|
||||||
|
role: role,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const result = await requestChatData({
|
||||||
|
formated: promptbody,
|
||||||
|
bias: {},
|
||||||
|
useStreaming: false,
|
||||||
|
noMultiGen: true,
|
||||||
|
}, 'otherAx')
|
||||||
|
|
||||||
|
if(result.type === 'fail'){
|
||||||
|
return JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
result: 'Error: ' + result.result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result.type === 'streaming' || result.type === 'multiline'){
|
||||||
|
return JSON.stringify({
|
||||||
|
success: false,
|
||||||
|
result: result.result
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify({
|
||||||
|
success: true,
|
||||||
|
result: result.result
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
await luaEngine.doString(luaCodeWarper(code))
|
await luaEngine.doString(luaCodeWarper(code))
|
||||||
luaEngineState.code = code
|
luaEngineState.code = code
|
||||||
}
|
}
|
||||||
@@ -538,6 +596,10 @@ function LLM(id, prompt)
|
|||||||
return json.decode(LLMMain(id, json.encode(prompt)):await())
|
return json.decode(LLMMain(id, json.encode(prompt)):await())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function axLLM(id, prompt)
|
||||||
|
return json.decode(axLLMMain(id, json.encode(prompt)):await())
|
||||||
|
end
|
||||||
|
|
||||||
local editRequestFuncs = {}
|
local editRequestFuncs = {}
|
||||||
local editDisplayFuncs = {}
|
local editDisplayFuncs = {}
|
||||||
local editInputFuncs = {}
|
local editInputFuncs = {}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export interface triggerscript{
|
|||||||
|
|
||||||
export type triggerCondition = triggerConditionsVar|triggerConditionsExists|triggerConditionsChatIndex
|
export type triggerCondition = triggerConditionsVar|triggerConditionsExists|triggerConditionsChatIndex
|
||||||
|
|
||||||
export type triggerEffect = triggerCode|triggerEffectCutChat|triggerEffectModifyChat|triggerEffectImgGen|triggerEffectRegex|triggerEffectRunLLM|triggerEffectCheckSimilarity|triggerEffectSendAIprompt|triggerEffectShowAlert|triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand|triggerEffectStop|triggerEffectRunTrigger
|
export type triggerEffect = triggerCode|triggerEffectCutChat|triggerEffectModifyChat|triggerEffectImgGen|triggerEffectRegex|triggerEffectRunLLM|triggerEffectCheckSimilarity|triggerEffectSendAIprompt|triggerEffectShowAlert|triggerEffectSetvar|triggerEffectSystemPrompt|triggerEffectImpersonate|triggerEffectCommand|triggerEffectStop|triggerEffectRunTrigger|triggerEffectRunAxLLM
|
||||||
|
|
||||||
export type triggerConditionsVar = {
|
export type triggerConditionsVar = {
|
||||||
type:'var'|'value'
|
type:'var'|'value'
|
||||||
@@ -138,6 +138,12 @@ export interface triggerEffectRunLLM{
|
|||||||
inputVar: string
|
inputVar: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface triggerEffectRunAxLLM{
|
||||||
|
type: 'runAxLLM',
|
||||||
|
value: string,
|
||||||
|
inputVar: string
|
||||||
|
}
|
||||||
|
|
||||||
export type additonalSysPrompt = {
|
export type additonalSysPrompt = {
|
||||||
start:string,
|
start:string,
|
||||||
historyend: string,
|
historyend: string,
|
||||||
@@ -504,6 +510,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
|||||||
setVar(effect.inputVar, res)
|
setVar(effect.inputVar, res)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'triggerlua':{
|
case 'triggerlua':{
|
||||||
const triggerCodeResult = await runLua(effect.code,{
|
const triggerCodeResult = await runLua(effect.code,{
|
||||||
lowLevelAccess: trigger.lowLevelAccess,
|
lowLevelAccess: trigger.lowLevelAccess,
|
||||||
@@ -520,6 +527,33 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
|||||||
chat = getCurrentChat()
|
chat = getCurrentChat()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'runAxLLM':{
|
||||||
|
if(!trigger.lowLevelAccess){
|
||||||
|
break
|
||||||
|
}
|
||||||
|
const effectValue = risuChatParser(effect.value,{chara:char})
|
||||||
|
const varName = effect.inputVar
|
||||||
|
let promptbody:OpenAIChat[] = parseChatML(effectValue)
|
||||||
|
if(!promptbody){
|
||||||
|
promptbody = [{role:'user', content:effectValue}]
|
||||||
|
}
|
||||||
|
const result = await requestChatData({
|
||||||
|
formated: promptbody,
|
||||||
|
bias: {},
|
||||||
|
useStreaming: false,
|
||||||
|
noMultiGen: true,
|
||||||
|
}, 'otherAx')
|
||||||
|
|
||||||
|
if(result.type === 'fail' || result.type === 'streaming' || result.type === 'multiline'){
|
||||||
|
setVar(varName, 'Error: ' + result.result)
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
setVar(varName, result.result)
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user