diff --git a/packages/components/credentials/LMStudioApi.credential.ts b/packages/components/credentials/LMStudioApi.credential.ts new file mode 100644 index 00000000000..960a2e8dc7a --- /dev/null +++ b/packages/components/credentials/LMStudioApi.credential.ts @@ -0,0 +1,24 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class LMStudioApi implements INodeCredential { + label: string + name: string + version: number + inputs: INodeParams[] + + constructor() { + this.label = 'LM Studio API' + this.name = 'lmstudioApi' + this.version = 1 + this.inputs = [ + { + label: 'LM Studio Api Key', + name: 'lmstudioApiKey', + type: 'password', + description: 'Optional. Most local LM Studio instances do not require an API key.' + } + ] + } +} + +module.exports = { credClass: LMStudioApi } diff --git a/packages/components/nodes/embeddings/LMStudioEmbedding/LMStudioEmbedding.ts b/packages/components/nodes/embeddings/LMStudioEmbedding/LMStudioEmbedding.ts new file mode 100644 index 00000000000..dbdd648b2c5 --- /dev/null +++ b/packages/components/nodes/embeddings/LMStudioEmbedding/LMStudioEmbedding.ts @@ -0,0 +1,70 @@ +import { ClientOptions, OpenAIEmbeddings, OpenAIEmbeddingsParams } from '@langchain/openai' +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getCredentialData, getCredentialParam } from '../../../src/utils' + +class LMStudioEmbedding_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 = 'LM Studio Embedding' + this.name = 'lmStudioEmbeddings' + this.version = 1 + this.type = 'LM Studio Embeddings' + this.icon = 'lmstudio.png' + this.category = 'Embeddings' + this.description = 'Use LM Studio local embeddings models' + this.baseClasses = [this.type, 'Embeddings'] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['lmstudioApi'], + optional: true + } + this.inputs = [ + { + label: 'Base Path', + name: 'basePath', + type: 'string', + default: 'http://localhost:1234/v1' + }, + { + label: 'Model Name', + name: 'modelName', + type: 'string', + placeholder: 'nomic-embed-text-v1.5' + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + if (!modelName) throw new Error('Model Name is required for LM Studio Embeddings') + const basePath = nodeData.inputs?.basePath as string + if (!basePath) throw new Error('Base Path is required for LM Studio Embeddings') + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const lmstudioApiKey = getCredentialParam('lmstudioApiKey', credentialData, nodeData) + + const obj: OpenAIEmbeddingsParams = { + modelName, + apiKey: lmstudioApiKey, + configuration: { baseURL: basePath } + } + + const model = new OpenAIEmbeddings(obj) + + return model + } +} + +module.exports = { nodeClass: LMStudioEmbedding_Embeddings } diff --git a/packages/components/nodes/embeddings/LMStudioEmbedding/lmstudio.png b/packages/components/nodes/embeddings/LMStudioEmbedding/lmstudio.png new file mode 100644 index 00000000000..c2a7c102ca0 Binary files /dev/null and b/packages/components/nodes/embeddings/LMStudioEmbedding/lmstudio.png differ