[feat] add mistral support
This commit is contained in:
BIN
public/token/mistral/tokenizer.model
Normal file
BIN
public/token/mistral/tokenizer.model
Normal file
Binary file not shown.
@@ -134,6 +134,10 @@
|
||||
<span class="text-textcolor">Claude {language.apiKey}</span>
|
||||
<TextInput marginBottom={true} size={"sm"} placeholder="..." bind:value={$DataBase.claudeAPIKey}/>
|
||||
{/if}
|
||||
{#if $DataBase.aiModel.startsWith('mistral') || $DataBase.subModel.startsWith('mistral')}
|
||||
<span class="text-textcolor">Mistral {language.apiKey}</span>
|
||||
<TextInput marginBottom={true} size={"sm"} placeholder="..." bind:value={$DataBase.mistralKey}/>
|
||||
{/if}
|
||||
{#if $DataBase.aiModel === 'reverse_proxy' || $DataBase.subModel === 'reverse_proxy'}
|
||||
<span class="text-textcolor mt-2">{language.forceReplaceUrl} URL <Help key="forceUrl"/></span>
|
||||
<TextInput marginBottom={false} size={"sm"} bind:value={$DataBase.forceReplaceUrl} placeholder="https//..." />
|
||||
|
||||
@@ -69,6 +69,12 @@
|
||||
return "GPT-4 Turbo 1106 Vision"
|
||||
case 'palm2_unicorn':
|
||||
return "PaLM2 Unicorn"
|
||||
case 'mistral-tiny':
|
||||
return "Mistral Tiny"
|
||||
case 'mistral-small':
|
||||
return "Mistral Small"
|
||||
case 'mistral-medium':
|
||||
return "Mistral Medium"
|
||||
default:
|
||||
if(name.startsWith("horde:::")){
|
||||
return name.replace(":::", " ")
|
||||
@@ -144,6 +150,11 @@
|
||||
{/if}
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('mancer')}}>Mancer</button>
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('openrouter')}}>OpenRouter</button>
|
||||
<Arcodion name="Mistral API">
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('mistral-tiny')}}>Mistral Tiny</button>
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('mistral-small')}}>Mistral Small</button>
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('mistral-medium')}}>Mistral Medium</button>
|
||||
</Arcodion>
|
||||
{#if showUnrec}
|
||||
<Arcodion name="Google Palm2">
|
||||
<button class="hover:bg-selected px-6 py-2 text-lg" on:click={() => {changeModel('palm2')}}>Bison</button>
|
||||
|
||||
@@ -148,6 +148,9 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
case 'gpt4_0301':
|
||||
case 'gptvi4_1106':
|
||||
case 'openrouter':
|
||||
case 'mistral-tiny':
|
||||
case 'mistral-small':
|
||||
case 'mistral-medium':
|
||||
case 'reverse_proxy':{
|
||||
let formatedChat:OpenAIChatExtra[] = []
|
||||
|
||||
@@ -281,6 +284,53 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
requestModel = db.customProxyRequestModel
|
||||
}
|
||||
|
||||
if(aiModel.startsWith('mistral')){
|
||||
requestModel = aiModel
|
||||
|
||||
const res = await globalFetch("https://api.mistral.ai/v1/chat/completions", {
|
||||
body: {
|
||||
model: requestModel,
|
||||
messages: formatedChat,
|
||||
temperature: temperature,
|
||||
max_tokens: maxTokens,
|
||||
top_p: db.top_p,
|
||||
},
|
||||
headers: {
|
||||
"Authorization": "Bearer " + db.mistralKey,
|
||||
},
|
||||
abortSignal,
|
||||
})
|
||||
|
||||
const dat = res.data as any
|
||||
if(res.ok){
|
||||
try {
|
||||
const msg:OpenAIChatFull = (dat.choices[0].message)
|
||||
return {
|
||||
type: 'success',
|
||||
result: msg.content
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
type: 'fail',
|
||||
result: (language.errors.httpError + `${JSON.stringify(dat)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(dat.error && dat.error.message){
|
||||
return {
|
||||
type: 'fail',
|
||||
result: (language.errors.httpError + `${dat.error.message}`)
|
||||
}
|
||||
}
|
||||
else{
|
||||
return {
|
||||
type: 'fail',
|
||||
result: (language.errors.httpError + `${JSON.stringify(res.data)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.cipherChat = false
|
||||
let body = ({
|
||||
|
||||
@@ -559,6 +559,7 @@ export interface Database{
|
||||
accessToken: string
|
||||
projectId: string
|
||||
}
|
||||
mistralKey?:string
|
||||
}
|
||||
|
||||
export interface customscript{
|
||||
|
||||
@@ -18,6 +18,9 @@ async function encode(data:string):Promise<(number[]|Uint32Array|Int32Array)>{
|
||||
if(db.aiModel.startsWith('novelai')){
|
||||
return await tokenizeWebTokenizers(data, 'novelai')
|
||||
}
|
||||
if(db.aiModel.startsWith('mistral')){
|
||||
return await tokenizeWebTokenizers(data, 'mistral')
|
||||
}
|
||||
if(db.aiModel.startsWith('local_') ||
|
||||
db.aiModel === 'mancer' ||
|
||||
db.aiModel === 'textgen_webui' ||
|
||||
@@ -29,7 +32,7 @@ async function encode(data:string):Promise<(number[]|Uint32Array|Int32Array)>{
|
||||
return await tikJS(data)
|
||||
}
|
||||
|
||||
type tokenizerType = 'novellist'|'claude'|'novelai'|'llama'
|
||||
type tokenizerType = 'novellist'|'claude'|'novelai'|'llama'|'mistral'
|
||||
|
||||
let tikParser:Tiktoken = null
|
||||
let tokenizersTokenizer:Tokenizer = null
|
||||
@@ -73,6 +76,12 @@ async function tokenizeWebTokenizers(text:string, type:tokenizerType) {
|
||||
tokenizersTokenizer = await webTokenizer.Tokenizer.fromSentencePiece(
|
||||
await (await fetch("/token/llama/llama.model")
|
||||
).arrayBuffer())
|
||||
break
|
||||
case 'mistral':
|
||||
tokenizersTokenizer = await webTokenizer.Tokenizer.fromSentencePiece(
|
||||
await (await fetch("/token/mistral/tokenizer.model")
|
||||
).arrayBuffer())
|
||||
break
|
||||
|
||||
}
|
||||
tokenizersType = type
|
||||
|
||||
Reference in New Issue
Block a user