Add pools

This commit is contained in:
kwaroran
2024-12-08 15:46:54 +09:00
parent 8d5fb1a139
commit 0c62b8bbfe
6 changed files with 33 additions and 7 deletions

View File

@@ -171,6 +171,7 @@ export const languageEnglish = {
translatorPrompt: "The prompt that is used for translation. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the dest language, {{solt::content}} for the content, and {{slot::tnote}} for the translator note.", translatorPrompt: "The prompt that is used for translation. if it is blank, it will use the default prompt. you can also use ChatML formating with {{slot}} for the dest language, {{solt::content}} for the content, and {{slot::tnote}} for the translator note.",
translateBeforeHTMLFormatting: "If enabled, it will translate the text before Regex scripts and HTML formatting. this could make the token lesser but could break the formatting.", translateBeforeHTMLFormatting: "If enabled, it will translate the text before Regex scripts and HTML formatting. this could make the token lesser but could break the formatting.",
autoTranslateCachedOnly: "If enabled, it will automatically translate only the text that the user has translated previously.", autoTranslateCachedOnly: "If enabled, it will automatically translate only the text that the user has translated previously.",
APIPool: "If enabled, it will connect to RisuAI API Pool. Every user which API pool is enabled, the API key will be shared if it used for free, rate-limited models, making it user to make more request of rate-limited models by using other's API key that didn't used much."
}, },
setup: { setup: {
chooseProvider: "Choose AI Provider", chooseProvider: "Choose AI Provider",
@@ -818,4 +819,5 @@ export const languageEnglish = {
customFlags: "Custom Flags", customFlags: "Custom Flags",
enableCustomFlags: "Enable Custom Flags", enableCustomFlags: "Enable Custom Flags",
googleCloudTokenization: "Google Cloud Tokenization", googleCloudTokenization: "Google Cloud Tokenization",
APIPool: "API Pool"
} }

View File

@@ -220,6 +220,12 @@
{#if DBState.db.aiModel === 'reverse_proxy' || DBState.db.subModel === 'reverse_proxy'} {#if DBState.db.aiModel === 'reverse_proxy' || DBState.db.subModel === 'reverse_proxy'}
<Check bind:check={DBState.db.reverseProxyOobaMode} name={`${language.reverseProxyOobaMode}`}/> <Check bind:check={DBState.db.reverseProxyOobaMode} name={`${language.reverseProxyOobaMode}`}/>
{/if} {/if}
{#if modelInfo.flags.includes(LLMFlags.poolSupported) && DBState.db.useExperimental}
<Check bind:check={DBState.db.risuPool} name={language.APIPool}>
<Help key="APIPool" />
<Help key="experimental" />
</Check>
{/if}
{#if modelInfo.provider === LLMProvider.NovelAI || subModelInfo.provider === LLMProvider.NovelAI} {#if modelInfo.provider === LLMProvider.NovelAI || subModelInfo.provider === LLMProvider.NovelAI}
<Check bind:check={DBState.db.NAIadventure} name={language.textAdventureNAI}/> <Check bind:check={DBState.db.NAIadventure} name={language.textAdventureNAI}/>

View File

@@ -906,6 +906,7 @@ async function fetchWithProxy(url: string, arg: GlobalFetchArgs): Promise<Global
"risu-url": encodeURIComponent(url), "risu-url": encodeURIComponent(url),
"Content-Type": arg.body instanceof URLSearchParams ? "application/x-www-form-urlencoded" : "application/json", "Content-Type": arg.body instanceof URLSearchParams ? "application/x-www-form-urlencoded" : "application/json",
...(arg.useRisuToken && { "x-risu-tk": "use" }), ...(arg.useRisuToken && { "x-risu-tk": "use" }),
"risu-pool": DBState.db.risuPool ? 'true' : 'false'
}; };
const body = arg.body instanceof URLSearchParams ? arg.body.toString() : JSON.stringify(arg.body); const body = arg.body instanceof URLSearchParams ? arg.body.toString() : JSON.stringify(arg.body);

View File

@@ -13,6 +13,7 @@ export enum LLMFlags{
hasStreaming, hasStreaming,
requiresAlternateRole, requiresAlternateRole,
mustStartWithUserInput, mustStartWithUserInput,
poolSupported
} }
export enum LLMProvider{ export enum LLMProvider{
@@ -766,16 +767,16 @@ export const LLMModels: LLMModel[] = [
id: 'gemini-exp-1121', id: 'gemini-exp-1121',
provider: LLMProvider.GoogleCloud, provider: LLMProvider.GoogleCloud,
format: LLMFormat.GoogleCloud, format: LLMFormat.GoogleCloud,
flags: [LLMFlags.hasImageInput, LLMFlags.hasFirstSystemPrompt], flags: [LLMFlags.hasImageInput, LLMFlags.hasFirstSystemPrompt, LLMFlags.poolSupported],
parameters: ['temperature', 'top_k', 'top_p'], parameters: ['temperature', 'top_k', 'top_p'],
tokenizer: LLMTokenizer.GoogleCloud tokenizer: LLMTokenizer.GoogleCloud,
}, },
{ {
name: "Gemini Exp 1206", name: "Gemini Exp 1206",
id: 'gemini-exp-1206', id: 'gemini-exp-1206',
provider: LLMProvider.GoogleCloud, provider: LLMProvider.GoogleCloud,
format: LLMFormat.GoogleCloud, format: LLMFormat.GoogleCloud,
flags: [LLMFlags.hasImageInput, LLMFlags.hasFirstSystemPrompt], flags: [LLMFlags.hasImageInput, LLMFlags.hasFirstSystemPrompt, LLMFlags.poolSupported],
recommended: true, recommended: true,
parameters: ['temperature', 'top_k', 'top_p'], parameters: ['temperature', 'top_k', 'top_p'],
tokenizer: LLMTokenizer.GoogleCloud tokenizer: LLMTokenizer.GoogleCloud

View File

@@ -1578,14 +1578,29 @@ async function requestGoogleCloudVertex(arg:RequestDataArgumentExtended):Promise
} }
} }
const url = arg.customURL ?? (arg.modelInfo.format === LLMFormat.VertexAIGemini ? let url = ''
`https://${REGION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/${arg.modelInfo.internalID}:streamGenerateContent` const pool = arg.modelInfo.flags.includes(LLMFlags.poolSupported) && db.risuPool && (!arg.customURL) && arg.modelInfo.format !== LLMFormat.VertexAIGemini
: `https://generativelanguage.googleapis.com/v1beta/models/${arg.modelInfo.internalID}:generateContent?key=${(arg.aiModel === 'reverse_proxy') ? db.proxyKey : db.google.accessToken}`)
if(arg.customURL){
const u = new URL(arg.customURL)
u.searchParams.set('key', db.proxyKey)
url = u.toString()
}
else if(arg.modelInfo.format === LLMFormat.VertexAIGemini){
url =`https://${REGION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/${arg.modelInfo.internalID}:streamGenerateContent`
}
else if(pool){
url = `https://sv.risuai.xyz/rapi/pool?model=${arg.modelInfo.internalID}&key=${db.google.accessToken}&type=google`
}
else{
url = `https://generativelanguage.googleapis.com/v1beta/models/${arg.modelInfo.internalID}:generateContent?key=${db.google.accessToken}`
}
const res = await globalFetch(url, { const res = await globalFetch(url, {
headers: headers, headers: headers,
body: body, body: body,
chatId: arg.chatId, chatId: arg.chatId,
abortSignal: arg.abortSignal abortSignal: arg.abortSignal,
plainFetchForce: pool
}) })
if(!res.ok){ if(!res.ok){

View File

@@ -854,6 +854,7 @@ export interface Database{
customFlags: LLMFlags[] customFlags: LLMFlags[]
enableCustomFlags: boolean enableCustomFlags: boolean
googleClaudeTokenizing: boolean googleClaudeTokenizing: boolean
risuPool: boolean
} }
interface SeparateParameters{ interface SeparateParameters{