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() {
|
constructor() {
|
||||||
this.label = 'LocalAI API'
|
this.label = 'LocalAI API'
|
||||||
this.name = 'LocalAIApi'
|
this.name = 'localAIApi'
|
||||||
this.version = 1.0
|
this.version = 1.0
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
{
|
{
|
||||||
label: 'LocalAI Api Key',
|
label: 'LocalAI Api Key',
|
||||||
name: 'LocalAIApiKey',
|
name: 'localAIApiKey',
|
||||||
type: 'password'
|
type: 'password'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -30,7 +30,7 @@ class ChatLocalAI_ChatModels implements INode {
|
||||||
label: 'Connect Credential',
|
label: 'Connect Credential',
|
||||||
name: 'credential',
|
name: 'credential',
|
||||||
type: 'credential',
|
type: 'credential',
|
||||||
credentialNames: ['LocalAIApi'],
|
credentialNames: ['localAIApi'],
|
||||||
optional: true
|
optional: true
|
||||||
}
|
}
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
|
|
@ -95,11 +95,11 @@ class ChatLocalAI_ChatModels implements INode {
|
||||||
const timeout = nodeData.inputs?.timeout as string
|
const timeout = nodeData.inputs?.timeout as string
|
||||||
const basePath = nodeData.inputs?.basePath as string
|
const basePath = nodeData.inputs?.basePath as string
|
||||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
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 cache = nodeData.inputs?.cache as BaseCache
|
||||||
|
|
||||||
const obj: Partial<OpenAIChatInput> & BaseLLMParams & { localAIApiKey?: string } = {
|
const obj: Partial<OpenAIChatInput> & BaseLLMParams & { openAIApiKey?: string } = {
|
||||||
temperature: parseFloat(temperature),
|
temperature: parseFloat(temperature),
|
||||||
modelName,
|
modelName,
|
||||||
openAIApiKey: 'sk-'
|
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'
|
import { OpenAIEmbeddings, OpenAIEmbeddingsParams } from 'langchain/embeddings/openai'
|
||||||
|
|
||||||
class LocalAIEmbedding_Embeddings implements INode {
|
class LocalAIEmbedding_Embeddings implements INode {
|
||||||
|
|
@ -10,6 +11,7 @@ class LocalAIEmbedding_Embeddings implements INode {
|
||||||
category: string
|
category: string
|
||||||
description: string
|
description: string
|
||||||
baseClasses: string[]
|
baseClasses: string[]
|
||||||
|
credential: INodeParams
|
||||||
inputs: INodeParams[]
|
inputs: INodeParams[]
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -21,6 +23,13 @@ class LocalAIEmbedding_Embeddings implements INode {
|
||||||
this.category = 'Embeddings'
|
this.category = 'Embeddings'
|
||||||
this.description = 'Use local embeddings models like llama.cpp'
|
this.description = 'Use local embeddings models like llama.cpp'
|
||||||
this.baseClasses = [this.type, 'Embeddings']
|
this.baseClasses = [this.type, 'Embeddings']
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
credentialNames: ['localAIApi'],
|
||||||
|
optional: true
|
||||||
|
}
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
{
|
{
|
||||||
label: 'Base Path',
|
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 modelName = nodeData.inputs?.modelName as string
|
||||||
const basePath = nodeData.inputs?.basePath 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 } = {
|
const obj: Partial<OpenAIEmbeddingsParams> & { openAIApiKey?: string } = {
|
||||||
modelName,
|
modelName,
|
||||||
openAIApiKey: 'sk-'
|
openAIApiKey: 'sk-'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localAIApiKey) obj.openAIApiKey = localAIApiKey
|
||||||
|
|
||||||
const model = new OpenAIEmbeddings(obj, { basePath })
|
const model = new OpenAIEmbeddings(obj, { basePath })
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue