Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ export class OpenAIModerationRunner implements Moderation {
private openAIApiKey = ''
private moderationErrorMessage: string = "Text was found that violates OpenAI's content policy."

constructor(openAIApiKey: string) {
this.openAIApiKey = openAIApiKey
constructor(openAIApiKey: string | any) {
// Handle case where openAIApiKey might be passed as an object instead of a string
if (typeof openAIApiKey === 'object' && openAIApiKey !== null) {
// If it's an object, try to extract the key from common property names
this.openAIApiKey = openAIApiKey.openAIApiKey || openAIApiKey.apiKey || openAIApiKey.key || ''
} else {
this.openAIApiKey = openAIApiKey || ''
}
}

async checkForViolations(input: string): Promise<string> {
Expand Down