feat(Google Gemini Chat Model Node): Add support for new Google Gemini models (#9130)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
oleg
2024-04-15 13:56:44 +02:00
committed by GitHub
parent fa93fb81b0
commit f1215cdb6b
11 changed files with 483 additions and 14 deletions

View File

@@ -21,6 +21,7 @@ import { CombiningOutputParser } from 'langchain/output_parsers';
import { LLMChain } from 'langchain/chains';
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
import { HumanMessage } from '@langchain/core/messages';
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
import { getTemplateNoticeField } from '../../../utils/sharedFields';
import {
getOptionalOutputParsers,
@@ -74,14 +75,19 @@ async function getImageMessage(
}
const bufferData = await context.helpers.getBinaryDataBuffer(itemIndex, binaryDataKey);
const model = (await context.getInputConnectionData(
NodeConnectionType.AiLanguageModel,
0,
)) as BaseLanguageModel;
const dataURI = `data:image/jpeg;base64,${bufferData.toString('base64')}`;
const imageUrl = model instanceof ChatGoogleGenerativeAI ? dataURI : { url: dataURI, detail };
return new HumanMessage({
content: [
{
type: 'image_url',
image_url: {
url: `data:image/jpeg;base64,${bufferData.toString('base64')}`,
detail,
},
image_url: imageUrl,
},
],
});