fix error TS2322 part 2

This commit is contained in:
chungyau97 2024-01-14 01:35:39 +08:00
parent bdc892df2b
commit 203b182cd5
1 changed files with 16 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { convertStringToArrayString, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' import { convertStringToArrayString, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { BaseCache } from 'langchain/schema' import { BaseCache } from 'langchain/schema'
import { ChatGoogleGenerativeAI } from '@langchain/google-genai' import { ChatGoogleGenerativeAI, GoogleGenerativeAIChatInput } from '@langchain/google-genai'
import { HarmBlockThreshold, HarmCategory } from '@google/generative-ai' import { HarmBlockThreshold, HarmCategory } from '@google/generative-ai'
class GoogleGenerativeAI_ChatModels implements INode { class GoogleGenerativeAI_ChatModels implements INode {
@ -158,10 +158,23 @@ class GoogleGenerativeAI_ChatModels implements INode {
const harmBlockThreshold = nodeData.inputs?.harmBlockThreshold as string const harmBlockThreshold = nodeData.inputs?.harmBlockThreshold as string
const cache = nodeData.inputs?.cache as BaseCache const cache = nodeData.inputs?.cache as BaseCache
const obj = { // safetySettings
let harmCategories: string[] = convertStringToArrayString(harmCategory)
let harmBlockThresholds: string[] = convertStringToArrayString(harmBlockThreshold)
if (harmCategories.length != harmBlockThresholds.length)
throw new Error(`Harm Category & Harm Block Threshold are not the same length`)
const safetySettings = harmCategories.map((value, index) => {
return {
category: value,
threshold: harmBlockThresholds[index]
}
})
const obj: Partial<GoogleGenerativeAIChatInput> = {
apiKey: apiKey, apiKey: apiKey,
modelName: modelName, modelName: modelName,
maxOutputTokens: 2048 maxOutputTokens: 2048,
safetySettings: safetySettings.length > 0 ? safetySettings : undefined
} }
if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10)
@ -172,19 +185,6 @@ class GoogleGenerativeAI_ChatModels implements INode {
if (cache) model.cache = cache if (cache) model.cache = cache
if (temperature) model.temperature = parseFloat(temperature) if (temperature) model.temperature = parseFloat(temperature)
// safetySettings
let harmCategories: string[] = convertStringToArrayString(harmCategory)
let harmBlockThresholds: string[] = convertStringToArrayString(harmBlockThreshold)
if (harmCategories.length != harmBlockThresholds.length)
throw new Error(`Harm Category & Harm Block Threshold are not the same length`)
const safetySettings: typeof model.safetySettings = harmCategories.map((value, index) => {
return {
category: value,
threshold: harmBlockThresholds[index]
}
})
if (safetySettings.length > 0) model.safetySettings = safetySettings
return model return model
} }
} }