I’m trying to run the moderations lessons locally, but since they openai api has changed it is very difficult, (for me) to get an json output
response = openai.Moderation.create(
input=“”"
Here’s the plan. We get the warhead,
and we hold the world ransom…
…FOR ONE MILLION DOLLARS!
“”"
)
moderation_output = response[“results”][0]
print(moderation_output)
Would become something like this:
response = client.moderations.create(input=“Sample text goes here.”)
response.results[0]
this gives you something back, but no json.
I found a solution here: Moderations.create - how to save and parse output? - API - OpenAI Developer Forum
And I tried it with a system (give me json back (please!) and client role, but no json back.
I liked the previous openai api better!
Any help to get me a json?
import os
import openai
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai.api_key = os.environ['OPENAI_API_KEY']
def get_completion_from_messages(messages,model="gpt-3.5-turbo",temperature=0,max_tokens=500):
response = openai.chat.completions.create(
model=mode,
message=messages,
temperature=temperature,
max_tokens=max_tokens,
)
return response.choices[0].message.content
response = openai.moderations.create(
model="omni-moderation-latest",
input = """ Here's the plan. We get the warhead, and we hodl the world ransom...FOR ONE MILLION DOLLARS!!""",
)
print(response)
Hi every one, I got the error here. If anyone can explain and help me here, I would appreciate it very much. I try replace the code with the new update on OpenAI platform but still got the error this is the original one
same problem for me on the Third script execution concerning the ‘moderation’ topic, looks like a problem in the method call, maybe a change in the ChatGPT api object?