Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

openaiPolicy

import { openaiPolicy } from "https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts";

Passes event content to OpenAI and then rejects flagged events.

By default, this policy will reject kind 1 events that OpenAI flags. It's possible to pass a custom handler for more control. An OpenAI API key is required.

@example
// Default handler. It's so strict it's suitable for school children.
openaiPolicy(msg, { apiKey: Deno.env.get('OPENAI_API_KEY') });

// With a custom handler.
openaiPolicy(msg, {
  apiKey: Deno.env.get('OPENAI_API_KEY'),
  handler(event, result) {
    // Loop each result.
    return data.results.some((result) => {
      if (result.flagged) {
        const { sexual, violence } = result.categories;
        // Reject only events flagged as sexual and violent.
        return sexual && violence;
      }
    });
  },
});
const openaiPolicy: Policy<OpenAI>;