diff --git a/packages/components/credentials/TogetherAIApi.credential.ts b/packages/components/credentials/TogetherAIApi.credential.ts new file mode 100644 index 00000000000..dba31a97068 --- /dev/null +++ b/packages/components/credentials/TogetherAIApi.credential.ts @@ -0,0 +1,23 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class TogetherAIApi implements INodeCredential { + label: string + name: string + version: number + inputs: INodeParams[] + + constructor() { + this.label = 'TogetherAI API' + this.name = 'togetherAIApi' + this.version = 1.0 + this.inputs = [ + { + label: 'TogetherAI Api Key', + name: 'togetherAIApiKey', + type: 'password' + } + ] + } +} + +module.exports = { credClass: TogetherAIApi } diff --git a/packages/components/nodes/chatmodels/ChatTogetherAI/ChatTogetherAI.ts b/packages/components/nodes/chatmodels/ChatTogetherAI/ChatTogetherAI.ts new file mode 100644 index 00000000000..fe36bbe3327 --- /dev/null +++ b/packages/components/nodes/chatmodels/ChatTogetherAI/ChatTogetherAI.ts @@ -0,0 +1,80 @@ +import { BaseCache } from '@langchain/core/caches' +import { ChatTogetherAI } from '@langchain/community/chat_models/togetherai' +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' + +class ChatTogetherAI_ChatModels implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + inputs: INodeParams[] + credential: INodeParams + + constructor() { + this.label = 'ChatTogetherAI' + this.name = 'chatTogetherAI' + this.version = 1.0 + this.type = 'ChatTogetherAI' + this.icon = 'togetherai.png' + this.category = 'Chat Models' + this.description = 'Wrapper around TogetherAI large language models' + this.baseClasses = [this.type, ...getBaseClasses(ChatTogetherAI)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['togetherAIApi'] + } + this.inputs = [ + { + label: 'Cache', + name: 'cache', + type: 'BaseCache', + optional: true + }, + { + label: 'Model Name', + name: 'modelName', + type: 'string', + placeholder: 'mixtral-8x7b-32768', + description: 'Refer to models page' + }, + { + label: 'Temperature', + name: 'temperature', + type: 'number', + step: 0.1, + default: 0.9, + optional: true + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + const cache = nodeData.inputs?.cache as BaseCache + const temperature = nodeData.inputs?.temperature as string + const streaming = nodeData.inputs?.streaming as boolean + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const togetherAIApiKey = getCredentialParam('togetherAIApiKey', credentialData, nodeData) + + const obj: any = { + model: modelName, + temperature: parseFloat(temperature), + togetherAIApiKey: togetherAIApiKey, + streaming: streaming ?? true + } + if (cache) obj.cache = cache + + const model = new ChatTogetherAI(obj) + return model + } +} + +module.exports = { nodeClass: ChatTogetherAI_ChatModels } diff --git a/packages/components/nodes/chatmodels/ChatTogetherAI/togetherai.png b/packages/components/nodes/chatmodels/ChatTogetherAI/togetherai.png new file mode 100644 index 00000000000..371103f6f83 Binary files /dev/null and b/packages/components/nodes/chatmodels/ChatTogetherAI/togetherai.png differ diff --git a/packages/components/nodes/embeddings/TogetherAIEmbedding/TogetherAIEmbedding.ts b/packages/components/nodes/embeddings/TogetherAIEmbedding/TogetherAIEmbedding.ts new file mode 100644 index 00000000000..96d95e7dd0c --- /dev/null +++ b/packages/components/nodes/embeddings/TogetherAIEmbedding/TogetherAIEmbedding.ts @@ -0,0 +1,68 @@ +import { TogetherAIEmbeddings, TogetherAIEmbeddingsParams } from '@langchain/community/embeddings/togetherai' +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' + +class TogetherAIEmbedding_Embeddings implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + inputs: INodeParams[] + credential: INodeParams + + constructor() { + this.label = 'TogetherAIEmbedding' + this.name = 'togetherAIEmbedding' + this.version = 1.0 + this.type = 'TogetherAIEmbedding' + this.icon = 'togetherai.png' + this.category = 'Embeddings' + this.description = 'TogetherAI Embedding models to generate embeddings for a given text' + this.baseClasses = [this.type, ...getBaseClasses(TogetherAIEmbeddings)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['togetherAIApi'] + } + this.inputs = [ + { + label: 'Cache', + name: 'cache', + type: 'BaseCache', + optional: true + }, + { + label: 'Model Name', + name: 'modelName', + type: 'string', + placeholder: 'sentence-transformers/msmarco-bert-base-dot-v5', + description: 'Refer to embedding models page' + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const togetherAIApiKey = getCredentialParam('togetherAIApiKey', credentialData, nodeData) + + const obj: Partial = { + modelName: modelName, + apiKey: togetherAIApiKey, + //@ts-ignore + model: modelName, + togetherAIApiKey: togetherAIApiKey + } + + const model = new TogetherAIEmbeddings(obj) + return model + } +} + +module.exports = { nodeClass: TogetherAIEmbedding_Embeddings } diff --git a/packages/components/nodes/embeddings/TogetherAIEmbedding/togetherai.png b/packages/components/nodes/embeddings/TogetherAIEmbedding/togetherai.png new file mode 100644 index 00000000000..371103f6f83 Binary files /dev/null and b/packages/components/nodes/embeddings/TogetherAIEmbedding/togetherai.png differ diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 8c195b51584..a233b94f704 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -1024,7 +1024,8 @@ export const isFlowValidForStream = (reactFlowNodes: IReactFlowNode[], endingNod 'chatMistralAI', 'groqChat', 'chatCohere', - 'chatGoogleGenerativeAI' + 'chatGoogleGenerativeAI', + 'chatTogetherAI' ], LLMs: ['azureOpenAI', 'openAI', 'ollama'] }