glin-profanity
Version:
Glin-Profanity is a lightweight and efficient npm package designed to detect and filter profane language in text inputs across multiple languages. Whether you’re building a chat application, a comment section, or any platform where user-generated content
232 lines (228 loc) • 6.03 kB
text/typescript
export { C as CheckProfanityResult, F as FilterConfig, L as Language } from '../types-B9c_ik4k.cjs';
/**
* LangChain Tool Integration for glin-profanity
*
* Provides ready-to-use tools for LangChain agents and chains.
* Compatible with LangChain.js and Python (via equivalent API).
*
* @example
* ```typescript
* import { createAgent } from 'langchain';
* import { profanityCheckTool, censorTextTool, batchCheckTool } from 'glin-profanity/ai/langchain';
*
* const agent = createAgent({
* model: 'gpt-4o',
* tools: [profanityCheckTool, censorTextTool, batchCheckTool],
* });
*
* const result = await agent.invoke('Check if "Hello world" contains profanity');
* ```
*
* @packageDocumentation
* @module glin-profanity/ai/langchain
*/
/**
* LangChain tool definition interface
*/
interface LangChainTool<T = unknown> {
name: string;
description: string;
schema: unknown;
invoke: (input: T) => Promise<unknown>;
}
/**
* Tool input types
*/
interface CheckProfanityInput {
text: string;
languages?: string[];
detectLeetspeak?: boolean;
normalizeUnicode?: boolean;
}
interface CensorTextInput {
text: string;
replacement?: string;
languages?: string[];
}
interface BatchCheckInput {
texts: string[];
languages?: string[];
detectLeetspeak?: boolean;
}
interface AnalyzeContextInput {
text: string;
languages?: string[];
contextWindow?: number;
confidenceThreshold?: number;
}
/**
* Creates a profanity check tool for LangChain
*
* @example
* ```typescript
* import { tool } from '@langchain/core/tools';
* import { createProfanityCheckTool } from 'glin-profanity/ai/langchain';
*
* const profanityTool = createProfanityCheckTool();
* const result = await profanityTool.invoke({ text: 'Hello world' });
* ```
*/
declare function createProfanityCheckTool(): {
name: string;
description: string;
schema: any;
invoke: (input: CheckProfanityInput) => Promise<string>;
};
/**
* Creates a censor text tool for LangChain
*/
declare function createCensorTextTool(): {
name: string;
description: string;
schema: any;
invoke: (input: CensorTextInput) => Promise<string>;
};
/**
* Creates a batch check tool for LangChain
*/
declare function createBatchCheckTool(): {
name: string;
description: string;
schema: any;
invoke: (input: BatchCheckInput) => Promise<string>;
};
/**
* Creates a context-aware analysis tool for LangChain
*/
declare function createContextAnalysisTool(): {
name: string;
description: string;
schema: any;
invoke: (input: AnalyzeContextInput) => Promise<string>;
};
/**
* Creates a supported languages tool for LangChain
*/
declare function createSupportedLanguagesTool(): {
name: string;
description: string;
schema: any;
invoke: () => Promise<string>;
};
/**
* Pre-built profanity check tool instance
* Use directly with LangChain agents
*/
declare const profanityCheckTool: {
name: string;
description: string;
schema: any;
invoke: (input: CheckProfanityInput) => Promise<string>;
};
/**
* Pre-built censor text tool instance
*/
declare const censorTextTool: {
name: string;
description: string;
schema: any;
invoke: (input: CensorTextInput) => Promise<string>;
};
/**
* Pre-built batch check tool instance
*/
declare const batchCheckTool: {
name: string;
description: string;
schema: any;
invoke: (input: BatchCheckInput) => Promise<string>;
};
/**
* Pre-built context analysis tool instance
*/
declare const contextAnalysisTool: {
name: string;
description: string;
schema: any;
invoke: (input: AnalyzeContextInput) => Promise<string>;
};
/**
* Pre-built supported languages tool instance
*/
declare const supportedLanguagesTool: {
name: string;
description: string;
schema: any;
invoke: () => Promise<string>;
};
/**
* All profanity tools bundled together
*
* @example
* ```typescript
* import { createAgent } from 'langchain';
* import { allProfanityTools } from 'glin-profanity/ai/langchain';
*
* const agent = createAgent({
* model: 'gpt-4o',
* tools: allProfanityTools,
* });
* ```
*/
declare const allProfanityTools: ({
name: string;
description: string;
schema: any;
invoke: (input: CheckProfanityInput) => Promise<string>;
} | {
name: string;
description: string;
schema: any;
invoke: (input: CensorTextInput) => Promise<string>;
} | {
name: string;
description: string;
schema: any;
invoke: (input: BatchCheckInput) => Promise<string>;
} | {
name: string;
description: string;
schema: any;
invoke: (input: AnalyzeContextInput) => Promise<string>;
})[];
/**
* Creates all profanity tools with custom configuration
*
* @param config - Optional filter configuration to apply to all tools
* @returns Array of LangChain-compatible tools
*
* @example
* ```typescript
* const tools = createAllProfanityTools({
* languages: ['english', 'spanish'],
* detectLeetspeak: true,
* });
* ```
*/
declare function createAllProfanityTools(): ({
name: string;
description: string;
schema: any;
invoke: (input: CheckProfanityInput) => Promise<string>;
} | {
name: string;
description: string;
schema: any;
invoke: (input: CensorTextInput) => Promise<string>;
} | {
name: string;
description: string;
schema: any;
invoke: (input: BatchCheckInput) => Promise<string>;
} | {
name: string;
description: string;
schema: any;
invoke: (input: AnalyzeContextInput) => Promise<string>;
})[];
export { type AnalyzeContextInput, type BatchCheckInput, type CensorTextInput, type CheckProfanityInput, type LangChainTool, allProfanityTools, batchCheckTool, censorTextTool, contextAnalysisTool, createAllProfanityTools, createBatchCheckTool, createCensorTextTool, createContextAnalysisTool, createProfanityCheckTool, createSupportedLanguagesTool, profanityCheckTool, supportedLanguagesTool };