Skip to content

Commit

Permalink
Add Gemini-pro model for chat (ai-shifu#678)
Browse files Browse the repository at this point in the history
* Add langchain/google-genai package and update langchain to 0.0.207 for Gemini

* Gemini up and running

* Update gemini-logo.png

---------

Co-authored-by: Sunner Sun <[email protected]>
  • Loading branch information
awesdroid and sunner authored Jan 13, 2024
1 parent 9c42a26 commit 7ee941e
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 7 deletions.
117 changes: 111 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"prepare": "husky install"
},
"dependencies": {
"@langchain/google-genai": "^0.0.7",
"@kangc/v-md-editor": "^2.3.16",
"@mdi/font": "^7.4.47",
"@vueuse/rxjs": "^10.7.1",
Expand All @@ -38,7 +39,7 @@
"electron-builder": "^24.9.1",
"jszip": "^3.10.1",
"katex": "^0.16.9",
"langchain": "~0.1.2",
"langchain": "^0.1.2",
"localforage": "^1.10.0",
"material-design-icons": "^3.0.1",
"prismjs": "^1.29.0",
Expand Down Expand Up @@ -107,6 +108,7 @@
],
"license": "Apache-2.0",
"overrides": {
"@langchain/core": "0.1.5",
"vue-cli-plugin-electron-builder": {
"electron-builder": "^24.0.0"
}
Expand Down
Binary file added public/bots/gemini-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions src/bots/GeminiBot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import LangChainBot from "@/bots/LangChainBot";
import store from "@/store";
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";

export default class GeminiBot extends LangChainBot {
static _brandId = "gemini";
static _className = "GeminiBot";
static _logoFilename = "gemini-logo.png"; // Place it in public/bots/
static _model = "gemini-pro";

constructor() {
super();
}

async _checkAvailability() {
let available = false;

if (store.state.gemini.apiKey) {
const chatModel = new ChatGoogleGenerativeAI({
apiKey: store.state.gemini.apiKey,
modelName: this.constructor._model ? this.constructor._model : "",
temperature: store.state.gemini.temperature,
streaming: true,
topK: store.state.gemini.topK,
topP: store.state.gemini.topP,
});
this.constructor._chatModel = chatModel;
available = true;
}
return available;
}

getPastRounds() {
return store.state.gemini.pastRounds;
}
}
3 changes: 3 additions & 0 deletions src/bots/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Bots
import GeminiBot from "@/bots/GeminiBot";
import ChatGPT35Bot from "@/bots/openai/ChatGPT35Bot";
import ChatGPT4Bot from "@/bots/openai/ChatGPT4Bot";
import ChatGPTBrowsingBot from "@/bots/openai/ChatGPTBrowsingBot";
Expand Down Expand Up @@ -60,6 +61,7 @@ import WenxinQianfan4Bot from "./baidu/WenxinQianfan4Bot";
import Zephyr7bBot from "./huggingface/Zephyr7bBot";

const all = [
GeminiBot.getInstance(),
Qihoo360AIBrainBot.getInstance(),
AlpacaBot.getInstance(),
SageBot.getInstance(), // Assistant@Poe
Expand Down Expand Up @@ -217,6 +219,7 @@ export const botTags = {
bots.getBotByClassName("Zephyr7bBot"),
],
api: [
bots.getBotByClassName("GeminiBot"),
bots.getBotByClassName("AzureOpenAIAPIBot"),
bots.getBotByClassName("OpenAIAPI35Bot"),
bots.getBotByClassName("OpenAIAPI3516KBot"),
Expand Down
75 changes: 75 additions & 0 deletions src/components/BotSettings/GeminiBotSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<CommonBotSettings
:settings="settings"
:brand-id="brandId"
mutation-type="setGemini"
></CommonBotSettings>
</template>

<script>
import Bot from "@/bots/GeminiBot";
import CommonBotSettings from "@/components/BotSettings/CommonBotSettings.vue";
import i18n from "@/i18n";
import { Type } from "./settings.const";
const settings = [
{
type: Type.Text,
name: "apiKey",
title: i18n.global.t("openaiApi.apiKey"),
description: i18n.global.t("settings.secretPrompt"),
placeholder: "...",
},
{
type: Type.Slider,
name: "temperature",
title: i18n.global.t("openaiApi.temperature"),
description: i18n.global.t("openaiApi.temperaturePrompt"),
min: 0,
max: 1,
step: 0.1,
ticks: {
0: i18n.global.t("openaiApi.temperature0"),
2: i18n.global.t("openaiApi.temperature2"),
},
},
{
type: Type.Slider,
name: "topK",
title: i18n.global.t("gemini.topK"),
description: i18n.global.t("gemini.topKPrompt"),
min: 1,
max: 100,
step: 1,
},
{
type: Type.Slider,
name: "topP",
title: i18n.global.t("gemini.topP"),
description: i18n.global.t("gemini.topPPrompt"),
min: 0.1,
max: 1,
step: 0.01,
},
{
type: Type.Slider,
name: "pastRounds",
title: i18n.global.t("bot.pastRounds"),
description: i18n.global.t("bot.pastRoundsPrompt"),
min: 0,
max: 10,
step: 1,
},
];
export default {
components: {
CommonBotSettings,
},
data() {
return {
settings: settings,
brandId: Bot._brandId,
};
},
};
</script>
2 changes: 2 additions & 0 deletions src/components/SettingsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import ChatSettings from "@/components/ChatSetting.vue";
import ChatGPTBotSettings from "@/components/BotSettings/ChatGPTBotSettings.vue";
import OpenAIAPIBotSettings from "@/components/BotSettings/OpenAIAPIBotSettings.vue";
import GeminiBotSettings from "@/components/BotSettings/GeminiBotSettings.vue";
import AzureOpenAIAPIBotSettings from "./BotSettings/AzureOpenAIAPIBotSettings.vue";
import BingChatBotSettings from "@/components/BotSettings/BingChatBotSettings.vue";
import SparkBotSettings from "./BotSettings/SparkBotSettings.vue";
Expand Down Expand Up @@ -143,6 +144,7 @@ const botSettings = [
{ brand: "lmsys", component: LMSYSBotSettings },
{ brand: "moss", component: MOSSBotSettings },
{ brand: "openaiApi", component: OpenAIAPIBotSettings },
{ brand: "gemini", component: GeminiBotSettings },
{ brand: "openAssistant", component: OpenAssistantBotSettings },
{ brand: "phind", component: PhindBotSettings },
{ brand: "pi", component: PiBotSettings },
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
"text-davinci-002-render-sha": "GPT-3.5",
"gpt-4": "GPT-4"
},
"gemini": {
"name": "Gemini",
"gemini-pro": "Gemini-Pro",
"topK": "topK",
"topKPrompt": "Ein topK von 1 bedeutet, dass das ausgewählte Token das wahrscheinlichste unter allen Token im Vokabular des Modells ist (auch gieriges Decodieren genannt).",
"topP": "topP",
"topPPrompt": "Token werden vom wahrscheinlichsten bis zum am wenigsten wahrscheinlichen ausgewählt, bis die Summe ihrer Wahrscheinlichkeiten den topP-Wert ergibt."
},
"bingChat": {
"name": "Bing Chat",
"h3imaginative": "Kreativ",
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
"gpt-4-browsing": "Web Browsing",
"gpt-4-mobile": "GPT-4 Mobile V2"
},
"gemini": {
"name": "Gemini",
"gemini-pro": "Gemini-Pro",
"topK": "topK",
"topKPrompt": "A topK of 1 means the selected token is the most probable among all the tokens in the model's vocabulary (also called greedy decoding)",
"topP": "topP",
"topPPrompt": "Tokens are selected from the most to least probable until the sum of their probabilities equals the topP value."
},
"claudeAi": {
"name": "Claude 2"
},
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
"gpt-4-browsing": "Navegación Web",
"gpt-4-mobile": "GPT-4 móvil V2"
},
"gemini": {
"name": "Gemini",
"gemini-pro": "Gemini-Pro",
"topK": "topK",
"topKPrompt": "Un topK de 1 significa que el token seleccionado es el más probable entre todos los tokens en el vocabulario del modelo (también llamado decodificación voraz).",
"topP": "topP",
"topPPrompt": "Los tokens se seleccionan desde el más probable hasta el menos probable hasta que la suma de sus probabilidades iguale el valor de topP"
},
"claudeAi": {
"name": "Claude 2"
},
Expand Down
Loading

0 comments on commit 7ee941e

Please sign in to comment.