From a0b9af975428667817ef43800f7bccc754cd7c3c Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Thu, 7 Sep 2023 11:09:40 +0000 Subject: [PATCH 1/3] Added Google PaLM chat model --- .../ChatGooglePaLM/ChatGooglePaLM.ts | 140 ++++++++++++++++++ .../ChatGooglePaLM/Google_PaLM_Logo.svg | 67 +++++++++ 2 files changed, 207 insertions(+) create mode 100644 packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts create mode 100644 packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg diff --git a/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts new file mode 100644 index 00000000..38cb1168 --- /dev/null +++ b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts @@ -0,0 +1,140 @@ +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { ChatGooglePaLM, GooglePaLMChatInput } from 'langchain/chat_models/googlepalm' + +class ChatGooglePaLM_ChatModels implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'ChatGooglePaLM' + this.name = 'chatGooglePaLM' + this.version = 1.0 + this.type = 'ChatGooglePaLM' + this.icon = 'Google_PaLM_Logo.svg' + this.category = 'Chat Models' + this.description = 'Wrapper around Google MakerSuite PaLM large language models using the Chat endpoint' + this.baseClasses = [this.type, ...getBaseClasses(ChatGooglePaLM)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleMakerSuite'] + } + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'models/chat-bison-001', + name: 'models/chat-bison-001' + } + ], + default: 'models/chat-bison-001', + optional: true + }, + { + label: 'Temperature', + name: 'temperature', + type: 'number', + step: 0.1, + default: 0.7, + optional: true, + description: + 'Controls the randomness of the output.\n' + + 'Values can range from [0.0,1.0], inclusive. A value closer to 1.0 ' + + 'will produce responses that are more varied and creative, while ' + + 'a value closer to 0.0 will typically result in more straightforward ' + + 'responses from the model.' + }, + { + label: 'Top Probability', + name: 'topP', + type: 'number', + step: 0.1, + optional: true, + additionalParams: true, + description: + 'Top-p changes how the model selects tokens for output.\n' + + 'Tokens are selected from most probable to least until ' + + 'the sum of their probabilities equals the top-p value.\n' + + 'For example, if tokens A, B, and C have a probability of .3, .2, and .1 ' + + 'and the top-p value is .5, then the model will select either A or B ' + + 'as the next token (using temperature).' + }, + { + label: 'Top-k', + name: 'topK', + type: 'number', + step: 1, + optional: true, + additionalParams: true, + description: + 'Top-k changes how the model selects tokens for output.\n' + + 'A top-k of 1 means the selected token is the most probable among ' + + 'all tokens in the model vocabulary (also called greedy decoding), ' + + 'while a top-k of 3 means that the next token is selected from ' + + 'among the 3 most probable tokens (using temperature).' + } + /* + { + label: 'Examples', + name: 'examplesObj', + type: 'json', + optional: true, + additionalParams: true + //default: { list:[] }, + //description: + // 'The "examples" field should contain a list of pairs of strings to use as prior turns for this conversation.' + } + */ + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + const temperature = nodeData.inputs?.temperature as string + const topP = nodeData.inputs?.topP as string + const topK = nodeData.inputs?.topK as string + //const examplesObj = nodeData.inputs?.examplesObj + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) + + const obj: Partial = { + modelName: modelName, + temperature: parseFloat(temperature), + apiKey: googleMakerSuiteKey + } + + if (topP) obj.topP = parseFloat(topP) + if (topK) obj.topK = parseFloat(topK) + + /* + let parsedExamples: any | undefined = undefined + if (examplesObj) { + try { + parsedExamples = typeof examplseObj === 'object' ? examplseObj : JSON.parse(examplseObj) + obj.examples = parsedExamples.examples || [] + } catch (exception) { + throw new Error("Invalid JSON in the GooglePaLM's examplseObj: " + exception) + } + } + */ + + const model = new ChatGooglePaLM(obj) + return model + } +} + +module.exports = { nodeClass: ChatGooglePaLM_ChatModels } diff --git a/packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg b/packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg new file mode 100644 index 00000000..5c345fe1 --- /dev/null +++ b/packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 43e9b63dcdcc4a35a11e77f181cab4903206960e Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Thu, 7 Sep 2023 15:03:04 +0000 Subject: [PATCH 2/3] Added Google PaLM embeddings model --- .../GooglePaLMEmbedding.ts | 65 ++++++++++++++++++ .../GooglePaLMEmbedding/Google_PaLM_Logo.svg | 67 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts create mode 100644 packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg diff --git a/packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts b/packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts new file mode 100644 index 00000000..81507d00 --- /dev/null +++ b/packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts @@ -0,0 +1,65 @@ +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { GooglePaLMEmbeddings, GooglePaLMEmbeddingsParams } from 'langchain/embeddings/googlepalm' + +class GooglePaLMEmbedding_Embeddings implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'Google PaLM Embeddings' + this.name = 'googlePaLMEmbeddings' + this.version = 1.0 + this.type = 'GooglePaLMEmbeddings' + this.icon = 'Google_PaLM_Logo.svg' + this.category = 'Embeddings' + this.description = 'Google MakerSuite PaLM API to generate embeddings for a given text' + this.baseClasses = [this.type, ...getBaseClasses(GooglePaLMEmbeddings)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleMakerSuite'] + } + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'models/embedding-gecko-001', + name: 'models/embedding-gecko-001' + } + ], + default: 'models/embedding-gecko-001', + optional: true + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) + + const obj: Partial = { + modelName: modelName, + apiKey: googleMakerSuiteKey + } + + const model = new GooglePaLMEmbeddings(obj) + return model + } +} + +module.exports = { nodeClass: GooglePaLMEmbedding_Embeddings } diff --git a/packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg b/packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg new file mode 100644 index 00000000..5c345fe1 --- /dev/null +++ b/packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a969b0650746cfb93b95b439e2898685802eef0d Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Tue, 12 Sep 2023 15:54:31 +0000 Subject: [PATCH 3/3] Remove commented unused code - unlikely to interface productively with other langchain components, even if implemented --- .../ChatGooglePaLM/ChatGooglePaLM.ts | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts index 38cb1168..642ddb5e 100644 --- a/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts +++ b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts @@ -86,18 +86,8 @@ class ChatGooglePaLM_ChatModels implements INode { 'while a top-k of 3 means that the next token is selected from ' + 'among the 3 most probable tokens (using temperature).' } - /* - { - label: 'Examples', - name: 'examplesObj', - type: 'json', - optional: true, - additionalParams: true - //default: { list:[] }, - //description: - // 'The "examples" field should contain a list of pairs of strings to use as prior turns for this conversation.' - } - */ + // 'The "examples" field should contain a list of pairs of strings to use as prior turns for this conversation.' + // NB: While 'examples:[]' exists in langchain.ts backend, it is unlikely to be actually used there, since ChatOpenAI doesn't support it ] } @@ -106,7 +96,6 @@ class ChatGooglePaLM_ChatModels implements INode { const temperature = nodeData.inputs?.temperature as string const topP = nodeData.inputs?.topP as string const topK = nodeData.inputs?.topK as string - //const examplesObj = nodeData.inputs?.examplesObj const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) @@ -120,18 +109,6 @@ class ChatGooglePaLM_ChatModels implements INode { if (topP) obj.topP = parseFloat(topP) if (topK) obj.topK = parseFloat(topK) - /* - let parsedExamples: any | undefined = undefined - if (examplesObj) { - try { - parsedExamples = typeof examplseObj === 'object' ? examplseObj : JSON.parse(examplseObj) - obj.examples = parsedExamples.examples || [] - } catch (exception) { - throw new Error("Invalid JSON in the GooglePaLM's examplseObj: " + exception) - } - } - */ - const model = new ChatGooglePaLM(obj) return model }