[PYTHON/OPENAI] OpenAI 클래스 : moderations 변수를 사용해 OpenAI 컨텐츠 정책 준수 여부 구하기
■ OpenAI 클래스의 moderations 변수를 사용해 OpenAI 컨텐츠 정책 준수 여부를 구하는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import os from openai import OpenAI os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>" openAI = OpenAI() moderationCreateResponse = openAI.moderations.create(input = "I'll kill you!") print(moderationCreateResponse) """ ModerationCreateResponse( id = 'modr-9X9dQsBVH63SgTbyBI2o56XUtmtHo', model = 'text-moderation-007', results = [ Moderation( categories = Categories( harassment = False, harassment_threatening = True, hate = False, hate_threatening = False, self_harm = False, self_harm_instructions = False, self_harm_intent = False, sexual = False, sexual_minors = False, violence = True, violence_graphic = False, self-harm = False, sexual/minors = False, hate/threatening = False, violence/graphic = False, self-harm/intent = False, self-harm/instructions = False, harassment/threatening = True ), category_scores = CategoryScores( harassment = 0.4298153519630432, harassment_threatening = 0.46343883872032166, hate = 0.0015633032890036702, hate_threatening = 0.00034259181120432913, self_harm = 1.1563445696083363e-05, self_harm_instructions = 1.1326376636588975e-07, self_harm_intent = 1.9825013168883743e-06, sexual = 6.320562533801422e-05, sexual_minors = 5.082089842289861e-07, violence = 0.998465895652771, violence_graphic = 0.0001357548899250105, self-harm = 1.1563445696083363e-05, sexual/minors = 5.082089842289861e-07, hate/threatening = 0.00034259181120432913, violence/graphic = 0.0001357548899250105, self-harm/intent = 1.9825013168883743e-06, self-harm/instructions = 1.1326376636588975e-07, harassment/threatening = 0.46343883872032166 ), flagged = True ) ] ) """ |
▶ requirements.txt —————————————————————————————————- annotated-types==0.7.0 anyio==4.4.0