From 97968f0a7043012b143caf6543cad1f07bd07290 Mon Sep 17 00:00:00 2001 From: asyncButNeverAwaits <111964298+asyncButNeverAwaits@users.noreply.github.com> Date: Sat, 13 Apr 2024 21:06:01 +0800 Subject: [PATCH] add mistral large (#784) * Mistral * mistral-logo.png --- public/bots/mistral-logo.png | Bin 0 -> 548 bytes src/bots/MistralBot.js | 142 ++++++++++++++++++ src/bots/index.js | 3 + .../BotSettings/MistralBotSettings.vue | 37 +++++ src/components/SettingsModal.vue | 2 + src/i18n/locales/en.json | 3 + src/store/index.js | 6 + 7 files changed, 193 insertions(+) create mode 100644 public/bots/mistral-logo.png create mode 100644 src/bots/MistralBot.js create mode 100644 src/components/BotSettings/MistralBotSettings.vue diff --git a/public/bots/mistral-logo.png b/public/bots/mistral-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..ff2f3e8b63bd8f193f84c4d070152beed8ee7e80 GIT binary patch literal 548 zcmV+<0^9wGP)Y}1MV*b z|IGmJzySTQ0RN-_`=0>JrUCzP0NP>!|4ag{a|HiM0`Elw%sdAF00!>?2Z}Kc%mfQY zI21)D6-E^pDIysq8yXrK8-S}Y(f|MeBy>_vQvei0LtkKGZi&vW;-{zsRfY%?3goQMIEfk3x#eTU?V~D0@oUz*+yVbEeIP_5fG z?DyvfiupL`NQC#IV>%IE)Hfa97FnaCK{YYF ziLDQ~`LwfLMtNlsQ7VzBtAjXn51U(*UkiuxicEW9ToqbByh0Mftm2OLS)VlfvuHQF m>dpTmOsJ5T|DQJ$!|(-q1XZ9vsKFut0000 { + this.onResponseDownloadProgress( + progressEvent, + onUpdateResponse, + callbackParam, + ); + }, + }, + ); + } catch (error) { + console.error("Error MistralBot _sendPrompt", error); + } finally { + onUpdateResponse(callbackParam, { + done: true, + }); + } + } + + onResponseDownloadProgress(progressEvent, onUpdateResponse, callbackParam) { + try { + let text = ""; + const responses = progressEvent?.event?.currentTarget?.response + ?.split("\n") // split with new line + ?.filter((n) => n); // filter empty string in array + for (const response of responses) { + const chunks = this.separateChunks(response); + if (chunks.number == 0) { + text += chunks.content + .slice(1, chunks.content.length - 1) + .replaceAll("\\n", "\n"); + onUpdateResponse(callbackParam, { + content: text, + done: false, + }); + } + } + onUpdateResponse(callbackParam, { + done: true, + }); + } catch (error) { + console.error("Error MistralBot onChatDownloadProgress", error); + } + } + + separateChunks(line) { + const regex = /^(\d+):(.*)/; + const match = line.match(regex); + if (match) { + return { number: match[1], content: match[2] }; + } else { + return { number: undefined, content: line }; + } + } +} diff --git a/src/bots/index.js b/src/bots/index.js index fc395d748e..1d2ad75b99 100644 --- a/src/bots/index.js +++ b/src/bots/index.js @@ -12,6 +12,7 @@ import BardBot from "@/bots/google/BardBot"; import OpenAIAPI35Bot from "@/bots/openai/OpenAIAPI35Bot"; import OpenAIAPI4Bot from "@/bots/openai/OpenAIAPI4Bot"; import OpenAIAPI4128KBot from "@/bots/openai/OpenAIAPI4128KBot"; +import MistralBot from "./MistralBot"; import MOSSBot from "@/bots/MOSSBot"; import WenxinQianfanBot from "@/bots/baidu/WenxinQianfanBot"; import VicunaBot from "@/bots/lmsys/VicunaBot"; @@ -129,6 +130,7 @@ const all = [ Llama270bPoeBot.getInstance(), Llama270bBot.getInstance(), Llama2HC70bBot.getInstance(), + MistralBot.getInstance(), MOSSBot.getInstance(), HuggingChatBot.getInstance(), GooglePalm2PoeBot.getInstance(), @@ -197,6 +199,7 @@ export const botTags = { bots.getBotByClassName("Llama2HC70bBot"), bots.getBotByClassName("CodeLlamaBot"), bots.getBotByClassName("CodeLlamaHCBot"), + bots.getBotByClassName("MistralBot"), bots.getBotByClassName("MOSSBot"), bots.getBotByClassName("Qihoo360AIBrainBot"), bots.getBotByClassName("QianWenBot"), diff --git a/src/components/BotSettings/MistralBotSettings.vue b/src/components/BotSettings/MistralBotSettings.vue new file mode 100644 index 0000000000..857399fdb9 --- /dev/null +++ b/src/components/BotSettings/MistralBotSettings.vue @@ -0,0 +1,37 @@ + + + diff --git a/src/components/SettingsModal.vue b/src/components/SettingsModal.vue index 6bae3e49d1..490bbd5a28 100644 --- a/src/components/SettingsModal.vue +++ b/src/components/SettingsModal.vue @@ -106,6 +106,7 @@ import AzureOpenAIAPIBotSettings from "./BotSettings/AzureOpenAIAPIBotSettings.v import BingChatBotSettings from "@/components/BotSettings/BingChatBotSettings.vue"; import SparkBotSettings from "./BotSettings/SparkBotSettings.vue"; import BardBotSettings from "@/components/BotSettings/BardBotSettings.vue"; +import MistralBotSettings from "@/components/BotSettings/MistralBotSettings.vue"; import MOSSBotSettings from "@/components/BotSettings/MOSSBotSettings.vue"; import WenxinQianfanBotSettings from "@/components/BotSettings/WenxinQianfanBotSettings.vue"; import GradioAppBotSettings from "@/components/BotSettings/GradioAppBotSettings.vue"; @@ -151,6 +152,7 @@ const botSettings = [ { brand: "huggingChat", component: HuggingChatBotSettings }, { brand: "kimi", component: KimiBotSettings }, { brand: "lmsys", component: LMSYSBotSettings }, + { brand: "mistral", component: MistralBotSettings }, { brand: "moss", component: MOSSBotSettings }, { brand: "openaiApi", component: OpenAIAPIBotSettings }, { brand: "geminiApi", component: GeminiAPIBotSettings }, diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 265c6d67cb..622ea8f722 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -207,6 +207,9 @@ "claude-3-sonnet-20240229": "claude-3-sonnet-20240229", "claude-3-opus-20240229": "claude-3-opus-20240229" }, + "mistral": { + "name": "Mistral" + }, "moss": { "name": "MOSS" }, diff --git a/src/store/index.js b/src/store/index.js index cd5e45c08e..c3d7469338 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -62,6 +62,9 @@ export default createStore({ url: "", fnIndex: 0, }, + mistral: { + model: "mistral-large", + }, moss: { token: "", }, @@ -239,6 +242,9 @@ export default createStore({ setPhind(state, values) { state.phind = { ...state.phind, ...values }; }, + setMistral(state, values) { + state.mistral = { ...state.mistral, ...values }; + }, setLatestPromptIndex(state, promptIndex) { Chats.table.update(state.currentChatIndex, { latestPromptIndex: promptIndex,