Add cache point

This commit is contained in:
Kwaroran
2025-03-08 17:49:19 +09:00
parent 02fb780395
commit 93a53da983
6 changed files with 70 additions and 6 deletions

View File

@@ -1062,4 +1062,6 @@ export const languageEnglish = {
thinkingTokens: "Thinking Tokens", thinkingTokens: "Thinking Tokens",
antiServerOverload: "Anti-Server Overload", antiServerOverload: "Anti-Server Overload",
localActivationInGlobalLorebook: "Local Activation in Global Lorebook", localActivationInGlobalLorebook: "Local Activation in Global Lorebook",
cachePoint: "Cache Point",
all: "All",
} }

View File

@@ -979,5 +979,7 @@ export const languageKorean = {
"paste": "붙여넣기", "paste": "붙여넣기",
"depth": "깊이", "depth": "깊이",
"alwaysActiveInChat": "언제나 활성화 (현재 챗)", "alwaysActiveInChat": "언제나 활성화 (현재 챗)",
"childLoreDesc": "이것은 캐릭터 로어의 복사본이며, 삭제하거나 원본 로어에서 직접 비활성화하기 전에는 '언제나 활성화' 상태로 유지됩니다." "childLoreDesc": "이것은 캐릭터 로어의 복사본이며, 삭제하거나 원본 로어에서 직접 비활성화하기 전에는 '언제나 활성화' 상태로 유지됩니다.",
"cachePoint": "캐시 포인트",
"all": "모두",
} }

View File

@@ -183,6 +183,10 @@
promptItem.text = "" promptItem.text = ""
promptItem.role = "system" promptItem.role = "system"
} }
if(promptItem.type === 'cache'){
promptItem.depth = 1
promptItem.role = 'all'
}
if(promptItem.type === 'chat'){ if(promptItem.type === 'chat'){
promptItem.rangeStart = -1000 promptItem.rangeStart = -1000
promptItem.rangeEnd = 'end' promptItem.rangeEnd = 'end'
@@ -198,6 +202,7 @@
<OptionInput value="memory">{language.formating.memory}</OptionInput> <OptionInput value="memory">{language.formating.memory}</OptionInput>
<OptionInput value="postEverything">{language.formating.postEverything}</OptionInput> <OptionInput value="postEverything">{language.formating.postEverything}</OptionInput>
<OptionInput value="chatML">{"chatML"}</OptionInput> <OptionInput value="chatML">{"chatML"}</OptionInput>
<OptionInput value="cache">{language.cachePoint}</OptionInput>
{#if DBState.db.promptSettings.customChainOfThought} {#if DBState.db.promptSettings.customChainOfThought}
<OptionInput value="cot">{language.cot}</OptionInput> <OptionInput value="cot">{language.cot}</OptionInput>
@@ -224,6 +229,17 @@
<span>{language.prompt}</span> <span>{language.prompt}</span>
<TextAreaInput highlight bind:value={promptItem.text} /> <TextAreaInput highlight bind:value={promptItem.text} />
{/if} {/if}
{#if promptItem.type === 'cache'}
<span>{language.depth}</span>
<NumberInput bind:value={promptItem.depth} />
<span>{language.role}</span>
<SelectInput bind:value={promptItem.role}>
<OptionInput value="all">{language.all}</OptionInput>
<OptionInput value="user">{language.user}</OptionInput>
<OptionInput value="bot">{language.character}</OptionInput>
<OptionInput value="system">{language.systemPrompt}</OptionInput>
</SelectInput>
{/if}
{#if promptItem.type === 'chat'} {#if promptItem.type === 'chat'}
{#if promptItem.rangeStart !== -1000} {#if promptItem.rangeStart !== -1000}
<span>{language.rangeStart}</span> <span>{language.rangeStart}</span>

View File

@@ -40,6 +40,7 @@ export interface OpenAIChat{
attr?:string[] attr?:string[]
multimodals?: MultiModal[] multimodals?: MultiModal[]
thoughts?: string[] thoughts?: string[]
cachePoint?: boolean
} }
export interface MultiModal{ export interface MultiModal{
@@ -635,6 +636,9 @@ export async function sendChat(chatProcessIndex = -1,arg:{
supaMemoryCardUsed = true supaMemoryCardUsed = true
break break
} }
case 'cache':{
break
}
} }
} }
} }
@@ -1142,6 +1146,22 @@ export async function sendChat(chatProcessIndex = -1,arg:{
} }
pushPrompts(pmt) pushPrompts(pmt)
break
}
case 'cache':{
let pointer = formated.length - 1
let depthRemaining = card.depth
while(pointer >= 0){
if(depthRemaining === 0){
break
}
if(formated[pointer].role === card.role || card.role === 'all'){
formated[pointer].cachePoint = true
depthRemaining--
}
}
break
} }
} }
} }

View File

@@ -4,7 +4,7 @@ import { getDatabase, presetTemplate, setDatabase, type Database } from "../stor
import { alertError, alertNormal } from "../alert"; import { alertError, alertNormal } from "../alert";
import type { OobaChatCompletionRequestParams } from "../model/ooba"; import type { OobaChatCompletionRequestParams } from "../model/ooba";
export type PromptItem = PromptItemPlain|PromptItemTyped|PromptItemChat|PromptItemAuthorNote|PromptItemChatML export type PromptItem = PromptItemPlain|PromptItemTyped|PromptItemChat|PromptItemAuthorNote|PromptItemChatML|PromptItemCache
export type PromptType = PromptItem['type']; export type PromptType = PromptItem['type'];
export type PromptSettings = { export type PromptSettings = {
assistantPrefill: string assistantPrefill: string
@@ -52,6 +52,14 @@ export interface PromptItemChat {
name?: string name?: string
} }
export interface PromptItemCache {
type: 'cache';
name: string
depth: number
role: 'user'|'assistant'|'system'|'all'
}
export async function tokenizePreset(prompts:PromptItem[], consti:boolean = false){ export async function tokenizePreset(prompts:PromptItem[], consti:boolean = false){
let total = 0 let total = 0
for(const prompt of prompts){ for(const prompt of prompts){

View File

@@ -370,6 +370,7 @@ export interface OpenAIChatExtra {
thoughts?:string[] thoughts?:string[]
prefix?:boolean prefix?:boolean
reasoning_content?:string reasoning_content?:string
cachePoint?:boolean
} }
function reformater(formated:OpenAIChat[],modelInfo:LLMModel){ function reformater(formated:OpenAIChat[],modelInfo:LLMModel){
@@ -570,6 +571,7 @@ async function requestOpenAI(arg:RequestDataArgumentExtended):Promise<requestDat
delete formatedChat[i].attr delete formatedChat[i].attr
delete formatedChat[i].multimodals delete formatedChat[i].multimodals
delete formatedChat[i].thoughts delete formatedChat[i].thoughts
delete formatedChat[i].cachePoint
} }
if(aiModel === 'reverse_proxy' && db.reverseProxyOobaMode && formatedChat[i].role === 'system'){ if(aiModel === 'reverse_proxy' && db.reverseProxyOobaMode && formatedChat[i].role === 'system'){
const cont = formatedChat[i].content const cont = formatedChat[i].content
@@ -2490,7 +2492,8 @@ async function requestClaude(arg:RequestDataArgumentExtended):Promise<requestDat
const addClaudeChat = (chat:{ const addClaudeChat = (chat:{
role: 'user'|'assistant' role: 'user'|'assistant'
content: string content: string,
cache: boolean
}, multimodals?:MultiModal[]) => { }, multimodals?:MultiModal[]) => {
if(claudeChat.length > 0 && claudeChat[claudeChat.length-1].role === chat.role){ if(claudeChat.length > 0 && claudeChat[claudeChat.length-1].role === chat.role){
let content = claudeChat[claudeChat.length-1].content let content = claudeChat[claudeChat.length-1].content
@@ -2533,6 +2536,11 @@ async function requestClaude(arg:RequestDataArgumentExtended):Promise<requestDat
} }
} }
} }
if(chat.cache){
content[content.length-1].cache_control = {
type: 'ephemeral'
}
}
claudeChat[claudeChat.length-1].content = content claudeChat[claudeChat.length-1].content = content
} }
else{ else{
@@ -2566,6 +2574,11 @@ async function requestClaude(arg:RequestDataArgumentExtended):Promise<requestDat
} }
} }
if(chat.cache){
formatedChat.content[0].cache_control = {
type: 'ephemeral'
}
}
claudeChat.push(formatedChat) claudeChat.push(formatedChat)
} }
} }
@@ -2574,14 +2587,16 @@ async function requestClaude(arg:RequestDataArgumentExtended):Promise<requestDat
case 'user':{ case 'user':{
addClaudeChat({ addClaudeChat({
role: 'user', role: 'user',
content: chat.content content: chat.content,
cache: chat.cachePoint
}, chat.multimodals) }, chat.multimodals)
break break
} }
case 'assistant':{ case 'assistant':{
addClaudeChat({ addClaudeChat({
role: 'assistant', role: 'assistant',
content: chat.content content: chat.content,
cache: chat.cachePoint
}, chat.multimodals) }, chat.multimodals)
break break
} }
@@ -2592,7 +2607,8 @@ async function requestClaude(arg:RequestDataArgumentExtended):Promise<requestDat
else{ else{
addClaudeChat({ addClaudeChat({
role: 'user', role: 'user',
content: "System: " + chat.content content: "System: " + chat.content,
cache: chat.cachePoint
}) })
} }
break break