Add support for WebLLM

This commit is contained in:
kwaroran
2024-01-09 00:27:58 +09:00
parent 1ee7107153
commit 350bc66851
4 changed files with 32 additions and 4 deletions

View File

@@ -329,7 +329,7 @@
<span class="text-textcolor2 mb-6 text-sm">{($DataBase.top_k).toFixed(0)}</span> <span class="text-textcolor2 mb-6 text-sm">{($DataBase.top_k).toFixed(0)}</span>
{/if} {/if}
{#if $DataBase.aiModel === 'textgen_webui' || $DataBase.aiModel === 'mancer' || $DataBase.aiModel.startsWith('local_')} {#if $DataBase.aiModel === 'textgen_webui' || $DataBase.aiModel === 'mancer' || $DataBase.aiModel.startsWith('local_') || $DataBase.aiModel.startsWith('hf:::')}
<span class="text-textcolor">Repetition Penalty</span> <span class="text-textcolor">Repetition Penalty</span>
<SliderInput min={1} max={1.5} step={0.01} bind:value={$DataBase.ooba.repetition_penalty}/> <SliderInput min={1} max={1.5} step={0.01} bind:value={$DataBase.ooba.repetition_penalty}/>
<span class="text-textcolor2 mb-6 text-sm">{($DataBase.ooba.repetition_penalty).toFixed(2)}</span> <span class="text-textcolor2 mb-6 text-sm">{($DataBase.ooba.repetition_penalty).toFixed(2)}</span>

View File

@@ -3,7 +3,6 @@
import { getHordeModels } from "src/ts/horde/getModels"; import { getHordeModels } from "src/ts/horde/getModels";
import Arcodion from "./Arcodion.svelte"; import Arcodion from "./Arcodion.svelte";
import { language } from "src/lang"; import { language } from "src/lang";
import { isNodeServer, isTauri } from "src/ts/storage/globalApi";
import Help from "../Others/Help.svelte"; import Help from "../Others/Help.svelte";
import CheckInput from "./GUI/CheckInput.svelte"; import CheckInput from "./GUI/CheckInput.svelte";
@@ -86,6 +85,10 @@
const split = name.split(":::") const split = name.split(":::")
return `Horde ${split[1]}` return `Horde ${split[1]}`
} }
if(name.startsWith('tf:::')){
const split = name.split(":::")
return `${split[1]}`
}
return name return name
} }
} }
@@ -190,7 +193,14 @@
</button> </button>
{/each} {/each}
{/await} {/await}
</Arcodion> </Arcodion>
{#if showUnrec}
<Arcodion name="WebLLM Local">
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('hf:::Xenova/opt-350m')}}>opt-350m</button>
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('hf:::Xenova/tiny-random-mistral')}}>tiny-random-mistral</button>
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('hf:::Xenova/gpt2-large-conversational')}}>gpt2-large-conversational</button>
</Arcodion>
{/if}
{#if $DataBase.plugins.length > 0} {#if $DataBase.plugins.length > 0}
<button on:click={() => {changeModel('custom')}} class="hover:bg-selected px-6 py-2 text-lg" >Plugin</button> <button on:click={() => {changeModel('custom')}} class="hover:bg-selected px-6 py-2 text-lg" >Plugin</button>
{/if} {/if}

View File

@@ -1,6 +1,6 @@
import {env, AutoTokenizer, pipeline, type SummarizationOutput, type TextGenerationConfig, type TextGenerationOutput, FeatureExtractionPipeline, TextToAudioPipeline } from '@xenova/transformers'; import {env, AutoTokenizer, pipeline, type SummarizationOutput, type TextGenerationConfig, type TextGenerationOutput, FeatureExtractionPipeline, TextToAudioPipeline } from '@xenova/transformers';
import { unzip } from 'fflate'; import { unzip } from 'fflate';
import { loadAsset, saveAsset } from 'src/ts/storage/globalApi'; import { globalFetch, loadAsset, saveAsset } from 'src/ts/storage/globalApi';
import { selectSingleFile } from 'src/ts/util'; import { selectSingleFile } from 'src/ts/util';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
let tfCache:Cache = null let tfCache:Cache = null

View File

@@ -21,6 +21,7 @@ import { supportsInlayImage } from "../image";
import { OaifixEmdash } from "../plugins/fixer"; import { OaifixEmdash } from "../plugins/fixer";
import { Capacitor } from "@capacitor/core"; import { Capacitor } from "@capacitor/core";
import { getFreeOpenRouterModel } from "../model/openrouter"; import { getFreeOpenRouterModel } from "../model/openrouter";
import { runTransformers } from "./embedding/transformers";
@@ -1632,6 +1633,23 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
} }
}
if(aiModel.startsWith('hf:::')){
const realModel = aiModel.split(":::")[1]
const suggesting = model === "submodel"
const proompt = stringlizeChatOba(formated, currentChar.name, suggesting, arg.continue)
const v = await runTransformers(proompt, realModel, {
temperature: temperature,
max_new_tokens: maxTokens,
top_k: db.ooba.top_k,
top_p: db.ooba.top_p,
repetition_penalty: db.ooba.repetition_penalty,
typical_p: db.ooba.typical_p,
})
return {
type: 'success',
result: unstringlizeChat(v.generated_text, formated, currentChar?.name ?? '')
}
} }
if(aiModel.startsWith('local_')){ if(aiModel.startsWith('local_')){
console.log('running local model') console.log('running local model')