Introduce new credential for LocalAI, Pass optional auth to LocalAI, New env var
This commit is contained in:
parent
79e988be09
commit
58f9e88b1f
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||||
|
|
||||||
|
class LocalAIApi implements INodeCredential {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'LocalAI API'
|
||||||
|
this.name = 'LocalAIApi'
|
||||||
|
this.version = 1.0
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'LocalAI Api Key',
|
||||||
|
name: 'LocalAIApiKey',
|
||||||
|
type: 'password'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { credClass: LocalAIApi }
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
import { getBaseClasses } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
import { OpenAIChat } from 'langchain/llms/openai'
|
import { OpenAIChat } from 'langchain/llms/openai'
|
||||||
import { OpenAIChatInput } from 'langchain/chat_models/openai'
|
import { OpenAIChatInput } from 'langchain/chat_models/openai'
|
||||||
import { BaseCache } from 'langchain/schema'
|
import { BaseCache } from 'langchain/schema'
|
||||||
|
|
@ -14,6 +14,7 @@ class ChatLocalAI_ChatModels implements INode {
|
||||||
category: string
|
category: string
|
||||||
description: string
|
description: string
|
||||||
baseClasses: string[]
|
baseClasses: string[]
|
||||||
|
credential: INodeParams
|
||||||
inputs: INodeParams[]
|
inputs: INodeParams[]
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -25,6 +26,16 @@ class ChatLocalAI_ChatModels implements INode {
|
||||||
this.category = 'Chat Models'
|
this.category = 'Chat Models'
|
||||||
this.description = 'Use local LLMs like llama.cpp, gpt4all using LocalAI'
|
this.description = 'Use local LLMs like llama.cpp, gpt4all using LocalAI'
|
||||||
this.baseClasses = [this.type, 'BaseChatModel', ...getBaseClasses(OpenAIChat)]
|
this.baseClasses = [this.type, 'BaseChatModel', ...getBaseClasses(OpenAIChat)]
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
credentialNames: ['LocalAIApi'],
|
||||||
|
optional: true
|
||||||
|
}
|
||||||
|
|
||||||
|
const modelOptions = JSON.parse(process.env.LOCALAI_CHAT_MODELS || '[]');
|
||||||
|
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
{
|
{
|
||||||
label: 'Cache',
|
label: 'Cache',
|
||||||
|
|
@ -41,8 +52,10 @@ class ChatLocalAI_ChatModels implements INode {
|
||||||
{
|
{
|
||||||
label: 'Model Name',
|
label: 'Model Name',
|
||||||
name: 'modelName',
|
name: 'modelName',
|
||||||
type: 'string',
|
type: 'options',
|
||||||
placeholder: 'gpt4all-lora-quantized.bin'
|
options: modelOptions,
|
||||||
|
default: modelOptions.length > 0 ? modelOptions[0].name : '',
|
||||||
|
optional: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Temperature',
|
label: 'Temperature',
|
||||||
|
|
@ -79,19 +92,23 @@ class ChatLocalAI_ChatModels implements INode {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(nodeData: INodeData): Promise<any> {
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
const temperature = nodeData.inputs?.temperature as string
|
const temperature = nodeData.inputs?.temperature as string
|
||||||
const modelName = nodeData.inputs?.modelName as string
|
const modelName = nodeData.inputs?.modelName as string
|
||||||
const maxTokens = nodeData.inputs?.maxTokens as string
|
const maxTokens = nodeData.inputs?.maxTokens as string
|
||||||
const topP = nodeData.inputs?.topP as string
|
const topP = nodeData.inputs?.topP as string
|
||||||
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 openAIApiKey = getCredentialParam('LocalAIApiKey', credentialData, nodeData)
|
||||||
|
|
||||||
const cache = nodeData.inputs?.cache as BaseCache
|
const cache = nodeData.inputs?.cache as BaseCache
|
||||||
|
|
||||||
const obj: Partial<OpenAIChatInput> & BaseLLMParams & { openAIApiKey?: string } = {
|
const obj: Partial<OpenAIChatInput> & BaseLLMParams & { openAIApiKey?: string } = {
|
||||||
temperature: parseFloat(temperature),
|
temperature: parseFloat(temperature),
|
||||||
modelName,
|
modelName,
|
||||||
openAIApiKey: 'sk-'
|
openAIApiKey
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10)
|
if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10)
|
||||||
|
|
|
||||||
|
|
@ -26,3 +26,5 @@ PORT=3000
|
||||||
# LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
|
# LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
|
||||||
# LANGCHAIN_API_KEY=your_api_key
|
# LANGCHAIN_API_KEY=your_api_key
|
||||||
# LANGCHAIN_PROJECT=your_project
|
# LANGCHAIN_PROJECT=your_project
|
||||||
|
|
||||||
|
# LOCALAI_CHAT_MODELS='[{"label": "model1", "name": "model1"}, {"label": "model2", "name": "model2"}]'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue