slight naming changes

This commit is contained in:
Henry
2023-11-22 17:10:18 +00:00
parent 619fb4f5c1
commit c274085d42
5 changed files with 454 additions and 13 deletions
@@ -37,14 +37,6 @@ class LLMChain_Chains implements INode {
name: 'model',
type: 'BaseLanguageModel'
},
{
label: 'Input Moderation',
description: 'Detect text that could generate harmful output and prevent it from being sent to the language model',
name: 'inputModeration',
type: 'Moderation',
optional: true,
list: true
},
{
label: 'Prompt',
name: 'prompt',
@@ -56,6 +48,14 @@ class LLMChain_Chains implements INode {
type: 'BaseLLMOutputParser',
optional: true
},
{
label: 'Input Moderation',
description: 'Detect text that could generate harmful output and prevent it from being sent to the language model',
name: 'inputModeration',
type: 'Moderation',
optional: true,
list: true
},
{
label: 'Chain Name',
name: 'chainName',
@@ -166,6 +166,7 @@ const runPrediction = async (
// Use the output of the moderation chain as input for the LLM chain
input = await checkInputs(moderations, chain.llm, input)
} catch (e) {
await new Promise((resolve) => setTimeout(resolve, 500))
streamResponse(isStreaming, e.message, socketIO, socketIOClientId)
return formatResponse(e.message)
}
@@ -15,7 +15,7 @@ class OpenAIModeration implements INode {
inputs: INodeParams[]
constructor() {
this.label = 'Moderation - Open AI'
this.label = 'OpenAI Moderation'
this.name = 'inputModerationOpenAI'
this.version = 1.0
this.type = 'Moderation'
@@ -15,13 +15,13 @@ class SimplePromptModeration implements INode {
inputs: INodeParams[]
constructor() {
this.label = 'Moderation - Simple Prompt'
this.label = 'Simple Prompt Moderation'
this.name = 'inputModerationSimple'
this.version = 1.0
this.type = 'Moderation'
this.icon = 'simple_moderation.png'
this.category = 'Responsible AI'
this.description = 'Detecting and mitigating prompt attacks'
this.description = 'Check whether input consists of any text from Deny list, and prevent being sent to LLM'
this.baseClasses = [this.type, ...getBaseClasses(Moderation)]
this.inputs = [
{
@@ -44,7 +44,6 @@ class SimplePromptModeration implements INode {
]
}
// eslint-disable-next-line unused-imports/no-unused-vars
async init(nodeData: INodeData): Promise<any> {
const denyList = nodeData.inputs?.denyList as string
const moderationErrorMessage = nodeData.inputs?.moderationErrorMessage as string
@@ -13,7 +13,7 @@ export class SimplePromptModerationRunner implements Moderation {
this.moderationErrorMessage = moderationErrorMessage
}
async checkForViolations(llm: BaseLanguageModel, input: string): Promise<string> {
async checkForViolations(_: BaseLanguageModel, input: string): Promise<string> {
this.denyList.split('\n').forEach((denyListItem) => {
if (denyListItem && denyListItem !== '' && input.includes(denyListItem)) {
throw Error(this.moderationErrorMessage)