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
168 lines (164 loc) • 4.66 kB
text/typescript
export { C as CheckProfanityResult, F as FilterConfig, L as Language } from '../types-B9c_ik4k.cjs';
/**
* OpenAI Function Calling Integration for glin-profanity
*
* Provides ready-to-use tool definitions for OpenAI's function calling API.
* Compatible with GPT-4o, GPT-4, GPT-3.5-turbo, and other OpenAI models.
*
* @example
* ```typescript
* import OpenAI from 'openai';
* import { profanityTools, executeProfanityTool } from 'glin-profanity/ai/openai';
*
* const client = new OpenAI();
* const response = await client.chat.completions.create({
* model: 'gpt-4o',
* messages: [{ role: 'user', content: 'Check if this text is appropriate: "Hello world"' }],
* tools: profanityTools,
* });
*
* // Handle tool calls
* const toolCall = response.choices[0]?.message.tool_calls?.[0];
* if (toolCall) {
* const result = await executeProfanityTool(toolCall.function.name, JSON.parse(toolCall.function.arguments));
* }
* ```
*
* @packageDocumentation
* @module glin-profanity/ai/openai
*/
/**
* OpenAI tool definition type
*/
interface OpenAITool {
type: 'function';
function: {
name: string;
description: string;
parameters: {
type: 'object';
properties: Record<string, unknown>;
required?: string[];
};
};
}
/**
* Check profanity tool parameters
*/
interface CheckProfanityParams {
text: string;
languages?: string[];
detectLeetspeak?: boolean;
normalizeUnicode?: boolean;
}
/**
* Censor text tool parameters
*/
interface CensorTextParams {
text: string;
replacement?: string;
languages?: string[];
}
/**
* Batch check tool parameters
*/
interface BatchCheckParams {
texts: string[];
languages?: string[];
detectLeetspeak?: boolean;
}
/**
* Analyze context tool parameters
*/
interface AnalyzeContextParams {
text: string;
languages?: string[];
contextWindow?: number;
confidenceThreshold?: number;
}
/**
* OpenAI-compatible tool definitions for profanity detection
*/
declare const profanityTools: OpenAITool[];
/**
* Execute a profanity tool by name with the given arguments
*
* @param toolName - The name of the tool to execute
* @param args - The arguments for the tool
* @returns The tool execution result
*
* @example
* ```typescript
* const result = await executeProfanityTool('check_profanity', {
* text: 'Hello world',
* detectLeetspeak: true,
* });
* console.log(result.containsProfanity); // false
* ```
*/
declare function executeProfanityTool(toolName: string, args: Record<string, unknown>): Promise<unknown>;
/**
* Zod schemas for OpenAI tool parameters (requires zod peer dependency)
*
* @example
* ```typescript
* import { zodFunction } from 'openai/helpers/zod';
* import { profanityToolSchemas } from 'glin-profanity/ai/openai';
*
* const tools = [
* zodFunction({ name: 'check_profanity', parameters: profanityToolSchemas.checkProfanity }),
* ];
* ```
*/
declare const profanityToolSchemas: {
/**
* Returns Zod schema for check_profanity tool
* Lazily loaded to avoid requiring zod as a hard dependency
*/
readonly checkProfanity: any;
/**
* Returns Zod schema for censor_text tool
*/
readonly censorText: any;
/**
* Returns Zod schema for batch_check_profanity tool
*/
readonly batchCheck: any;
/**
* Returns Zod schema for analyze_context tool
*/
readonly analyzeContext: any;
};
/**
* Creates a runnable tools configuration for OpenAI's runTools helper
*
* @example
* ```typescript
* import OpenAI from 'openai';
* import { createRunnableTools } from 'glin-profanity/ai/openai';
*
* const client = new OpenAI();
* const runner = client.chat.completions.runTools({
* model: 'gpt-4o',
* messages: [{ role: 'user', content: 'Check this text for profanity: "Hello world"' }],
* tools: createRunnableTools(),
* });
*
* const result = await runner.finalContent();
* ```
*/
declare function createRunnableTools(): {
type: "function";
function: {
function: (args: Record<string, unknown>) => Promise<unknown>;
parse: (text: string, reviver?: (this: any, key: string, value: any) => any) => any;
name: string;
description: string;
parameters: {
type: "object";
properties: Record<string, unknown>;
required?: string[];
};
};
}[];
export { type AnalyzeContextParams, type BatchCheckParams, type CensorTextParams, type CheckProfanityParams, type OpenAITool, createRunnableTools, executeProfanityTool, profanityToolSchemas, profanityTools };