Skip to content

Commit 3f283c6

Browse files
Merge pull request #96 from intelligentnode/fix-gemini
Fix gemini
2 parents e80e83d + ee3f3db commit 3f283c6

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

IntelliNode/function/Chatbot.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ class Chatbot {
143143
const content = line.replace(/^(User|Assistant): /, '');
144144
return { role, content };
145145
});
146+
} else if (modelInput instanceof GeminiInput) {
147+
messages = modelInput.messages.map(message => {
148+
const role = message.role;
149+
const content = message.parts.map(part => part.text).join(" ");
150+
return { role, content };
151+
});
146152
} else if (Array.isArray(modelInput.messages)) {
147153
messages = modelInput.messages;
148154
} else {
@@ -151,7 +157,7 @@ class Chatbot {
151157
}
152158

153159
lastMessage = messages[messages.length - 1];
154-
160+
155161
if (lastMessage && lastMessage.role === "user") {
156162

157163
const semanticResult = await this.extendedController.semanticSearch(lastMessage.content, modelInput.searchK);

IntelliNode/model/input/ChatModelInput.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ class GeminiInput extends ChatModelInput {
210210
contents: this.messages
211211
};
212212
}
213+
214+
cleanMessages() {
215+
this.messages = [];
216+
}
217+
218+
deleteLastMessage(message) {
219+
if (this.messages.length > 0) {
220+
this.messages.splice(-1, 1);
221+
return true;
222+
}
223+
return false;
224+
}
225+
213226
}
214227

215228
class ChatLLamaInput extends ChatModelInput {

IntelliNode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "intellinode",
3-
"version": "1.7.7",
3+
"version": "1.7.8",
44
"description": "Integrate and evaluate various AI models, such as ChatGPT, Llama, Diffusion, Cohere, Gemini and Hugging Face.",
55
"main": "index.js",
66
"keywords": [
@@ -16,8 +16,8 @@
1616
"speech synthesis",
1717
"prompt",
1818
"automation",
19-
"Mistral",
20-
"Google Gemini"
19+
"mistralai",
20+
"gemini"
2121
],
2222
"author": "IntelliNode",
2323
"license": "Apache",

IntelliNode/test/integration/ChatbotWithData.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ const { ChatGPTInput,
77
ChatLLamaInput,
88
CohereInput,
99
LLamaReplicateInput,
10+
GeminiInput,
1011
LLamaSageInput } = require("../../model/input/ChatModelInput");
1112

1213
const openaiKey = process.env.OPENAI_API_KEY;
1314
const replicateApiKey = process.env.REPLICATE_API_KEY;
1415
const intelliKey = process.env.INTELLI_ONE_KEY;
16+
const geminiApiKey = process.env.GEMINI_API_KEY;
1517
// openai bot
1618
const bot = new Chatbot(openaiKey, SupportedChatModels.OPENAI, null,
1719
{oneKey:intelliKey, intelliBase: process.env.INTELLI_API_BASE});
1820
// llama - replicate bot
1921
const replicateBot = new Chatbot(replicateApiKey, SupportedChatModels.REPLICATE, null,
2022
{oneKey:intelliKey, intelliBase: process.env.INTELLI_API_BASE});
23+
// gemini api key
24+
const geminiBot = new Chatbot(geminiApiKey, SupportedChatModels.GEMINI, null,
25+
{oneKey:intelliKey, intelliBase: process.env.INTELLI_API_BASE});
2126

2227
async function testOpenaiChatGPTCase1() {
2328
try {
@@ -107,6 +112,24 @@ async function testCohereChatCase() {
107112
assert(responses.length > 0, "Cohere chat response length should be greater than 0");
108113
}
109114

115+
async function testGeminiChatCase1() {
116+
try {
117+
console.log('\ngemini test case 1: \n')
118+
119+
const input = new GeminiInput("", {searchK:4});
120+
input.addUserMessage("Tell me about the Mars the Red Planet? summarize the context");
121+
122+
const responses = await geminiBot.chat(input);
123+
124+
console.log('### the chatbot response ###')
125+
responses.forEach((response) => console.log("- " + response));
126+
127+
assert(responses.length > 0, "testOpenaiChatGPTCase1 response length should be greater than 0");
128+
} catch (error) {
129+
console.error("Test case failed with exception:", error.message);
130+
}
131+
}
132+
110133
(async () => {
111134

112135
console.log('### Openai model ###')
@@ -122,4 +145,7 @@ async function testCohereChatCase() {
122145
console.log('### Cohere model ###')
123146
await testCohereChatCase();
124147

148+
console.log('### Gemini model ###')
149+
testGeminiChatCase1();
150+
125151
})();

0 commit comments

Comments
 (0)