Skip to content

How can i use moderation api from open ai with vercel ai sdk, there was nothing about this in vercel ai docs #2555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Akshmit11 opened this issue Aug 6, 2024 · 6 comments · May be fixed by #5439
Labels
enhancement New feature or request

Comments

@Akshmit11
Copy link

Akshmit11 commented Aug 6, 2024

Feature Description

I am asking users to enter some text and submit it and I am using vercel ai sdk to generate response from chatgpt to that text, but I also want to check if the text contains any profanity or not. How can I achieve this?

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';



const checkProfanity = async (text: string) => {
  try {
// **what to do about this..->-> open.moderation.create**
    const response = await openai.moderation.create({
      input: text,
    });
    const { results } = response.data;
    return results[0].flagged;
  } catch (error) {
    console.error("Error checking profanity:", error);
    return false;
  }
};


const isProfane = await checkProfanity(text);

    if (isProfane) {
      throw new Error("The text contains inappropriate content. Please modify your text and try again.");
    }

const aiResponse = await generateText({
      model: openai('gpt-3.5-turbo'),
      prompt: `my prompt comes here....

Is there any way of achieving this functionality?

Use Case

No response

Additional context

No response

@lgrammel lgrammel added the enhancement New feature or request label Aug 6, 2024
@lgrammel
Copy link
Collaborator

lgrammel commented Aug 6, 2024

OpenAI moderations are currently not supported by the AI SDK.

@ThalusA
Copy link

ThalusA commented Aug 8, 2024

Would be awesome to have it implemented

@williamlmao
Copy link
Contributor

+1 on moderations being added

@sivayapps
Copy link

+1

1 similar comment
@massimobrivio
Copy link

+1

@olivermontes
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants