Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/components/credentials/LMStudioApi.credential.ts
Original file line number Diff line number Diff line change
@@ -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.0
Comment thread
Dotify71 marked this conversation as resolved.
Outdated
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 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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.0
Comment thread
Dotify71 marked this conversation as resolved.
Outdated
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<any> {
const modelName = nodeData.inputs?.modelName as string
Comment thread
Dotify71 marked this conversation as resolved.
if (!modelName) throw new Error('Model Name is required for LM Studio Embeddings')
const basePath = nodeData.inputs?.basePath as string
Comment thread
Dotify71 marked this conversation as resolved.
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,
openAIApiKey: 'not-needed' // LM Studio typically doesn't require an API key
}

if (lmstudioApiKey) obj.openAIApiKey = lmstudioApiKey

if (basePath) obj.configuration = { baseURL: basePath }
Comment thread
Dotify71 marked this conversation as resolved.
Outdated

const model = new OpenAIEmbeddings(obj)

return model
}
}

module.exports = { nodeClass: LMStudioEmbedding_Embeddings }
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.