Fixing naming, handling embeddings for LocalAI also
This commit is contained in:
parent
06201e7cf0
commit
b9d1d75d6a
|
|
@ -8,12 +8,12 @@ class LocalAIApi implements INodeCredential {
|
|||
|
||||
constructor() {
|
||||
this.label = 'LocalAI API'
|
||||
this.name = 'LocalAIApi'
|
||||
this.name = 'localAIApi'
|
||||
this.version = 1.0
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'LocalAI Api Key',
|
||||
name: 'LocalAIApiKey',
|
||||
name: 'localAIApiKey',
|
||||
type: 'password'
|
||||
}
|
||||
]
|
||||
|
|
@ -30,7 +30,7 @@ class ChatLocalAI_ChatModels implements INode {
|
|||
label: 'Connect Credential',
|
||||
name: 'credential',
|
||||
type: 'credential',
|
||||
credentialNames: ['LocalAIApi'],
|
||||
credentialNames: ['localAIApi'],
|
||||
optional: true
|
||||
}
|
||||
this.inputs = [
|
||||
|
|
@ -95,11 +95,11 @@ class ChatLocalAI_ChatModels implements INode {
|
|||
const timeout = nodeData.inputs?.timeout as string
|
||||
const basePath = nodeData.inputs?.basePath as string
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const localAIApiKey = getCredentialParam('LocalAIApiKey', credentialData, nodeData)
|
||||
const localAIApiKey = getCredentialParam('localAIApiKey', credentialData, nodeData)
|
||||
|
||||
const cache = nodeData.inputs?.cache as BaseCache
|
||||
|
||||
const obj: Partial<OpenAIChatInput> & BaseLLMParams & { localAIApiKey?: string } = {
|
||||
const obj: Partial<OpenAIChatInput> & BaseLLMParams & { openAIApiKey?: string } = {
|
||||
temperature: parseFloat(temperature),
|
||||
modelName,
|
||||
openAIApiKey: 'sk-'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||
import { getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { OpenAIEmbeddings, OpenAIEmbeddingsParams } from 'langchain/embeddings/openai'
|
||||
|
||||
class LocalAIEmbedding_Embeddings implements INode {
|
||||
|
|
@ -10,6 +11,7 @@ class LocalAIEmbedding_Embeddings implements INode {
|
|||
category: string
|
||||
description: string
|
||||
baseClasses: string[]
|
||||
credential: INodeParams
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
|
|
@ -21,6 +23,13 @@ class LocalAIEmbedding_Embeddings implements INode {
|
|||
this.category = 'Embeddings'
|
||||
this.description = 'Use local embeddings models like llama.cpp'
|
||||
this.baseClasses = [this.type, 'Embeddings']
|
||||
this.credential = {
|
||||
label: 'Connect Credential',
|
||||
name: 'credential',
|
||||
type: 'credential',
|
||||
credentialNames: ['localAIApi'],
|
||||
optional: true
|
||||
}
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Base Path',
|
||||
|
|
@ -37,15 +46,20 @@ class LocalAIEmbedding_Embeddings implements INode {
|
|||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const modelName = nodeData.inputs?.modelName as string
|
||||
const basePath = nodeData.inputs?.basePath as string
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const localAIApiKey = getCredentialParam('localAIApiKey', credentialData, nodeData)
|
||||
|
||||
const obj: Partial<OpenAIEmbeddingsParams> & { openAIApiKey?: string } = {
|
||||
modelName,
|
||||
openAIApiKey: 'sk-'
|
||||
}
|
||||
|
||||
if (localAIApiKey) obj.openAIApiKey = localAIApiKey
|
||||
|
||||
const model = new OpenAIEmbeddings(obj, { basePath })
|
||||
|
||||
return model
|
||||
|
|
|
|||
Loading…
Reference in New Issue