@matsukky/perspective-client
Version:
Client library for the Perspective API
66 lines (65 loc) • 2.65 kB
TypeScript
import { AxiosError } from "axios";
import type { AnalyzeResponse, AttributeType, CommentRequestOptions, RequestedAttribute, LanguageCode } from "./types";
export declare const availableAttributes: {
IDENTITY_ATTACK: string[];
INSULT: string[];
PROFANITY: string[];
SEVERE_TOXICITY: string[];
THREAT: string[];
TOXICITY: string[];
FLIRTATION: string[];
IDENTITY_ATTACK_EXPERIMENTAL: string[];
INSULT_EXPERIMENTAL: string[];
PROFANITY_EXPERIMENTAL: string[];
SEVERE_TOXICITY_EXPERIMENTAL: string[];
SEXUALLY_EXPLICIT: string[];
THREAT_EXPERIMENTAL: string[];
TOXICITY_EXPERIMENTAL: string[];
AFFINITY_EXPERIMENTAL: string[];
COMPASSION_EXPERIMENTAL: string[];
CURIOSITY_EXPERIMENTAL: string[];
NUANCE_EXPERIMENTAL: string[];
PERSONAL_STORY_EXPERIMENTAL: string[];
REASONING_EXPERIMENTAL: string[];
RESPECT_EXPERIMENTAL: string[];
ATTACK_ON_AUTHOR: string[];
ATTACK_ON_COMMENTER: string[];
INCOHERENT: string[];
INFLAMMATORY: string[];
LIKELY_TO_REJECT: string[];
OBSCENE: string[];
SPAM: string[];
UNSUBSTANTIAL: string[];
};
type AvailableAttributes = keyof typeof availableAttributes;
export declare const MAX_LENGTH = 20480;
export declare class PerspectiveAPIClientError extends Error {
constructor(message: string);
}
export declare class TextEmptyError extends PerspectiveAPIClientError {
constructor();
}
export declare class TextTooLongError extends PerspectiveAPIClientError {
constructor();
}
export declare class ResponseError extends PerspectiveAPIClientError {
response: AxiosError;
constructor(message: string, response: AxiosError);
}
export declare class Perspective {
static readonly PerspectiveAPIClientError: typeof PerspectiveAPIClientError;
static readonly TextEmptyError: typeof TextEmptyError;
static readonly TextTooLongError: typeof TextTooLongError;
static readonly ResponseError: typeof ResponseError;
apiKey: string;
constructor({ apiKey }: {
apiKey: string;
});
analyze(text: string, attriubtes?: Partial<Record<AttributeType, RequestedAttribute>> | AttributeType[], options?: CommentRequestOptions): Promise<AnalyzeResponse>;
validateComment(text: string): void;
validateLanguages(languages: string[]): void;
validateAttributesAndLanguages(attributes: AvailableAttributes[], languages: LanguageCode[]): void;
parseAttributes(attributes: Partial<Record<AttributeType, RequestedAttribute>> | Partial<AttributeType>[]): Partial<Record<AttributeType, RequestedAttribute>>;
}
export * as Types from "./types";
export default Perspective;