File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
src/main/kotlin/com/cjcrafter/openai/moderations Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 88import java .util .Comparator ;
99import java .util .Scanner ;
1010
11- public class CreateModerations {
11+ public class ModerationsExample {
1212
1313 // To use dotenv, you need to add the "io.github.cdimascio:dotenv-kotlin:version"
1414 // dependency. Then you can add a .env file in your project directory.
Original file line number Diff line number Diff line change 1+ package moderations
2+
3+ import com.cjcrafter.openai.moderations.create
4+ import com.cjcrafter.openai.openAI
5+ import io.github.cdimascio.dotenv.dotenv
6+
7+
8+ fun main () {
9+
10+ // To use dotenv, you need to add the "io.github.cdimascio:dotenv-kotlin:version"
11+ // dependency. Then you can add a .env file in your project directory.
12+ val key = dotenv()[" OPENAI_TOKEN" ]
13+ val openai = openAI { apiKey(key) }
14+
15+ while (true ) {
16+ print (" Input: " )
17+ val input = readln()
18+ val moderation = openai.moderations.create {
19+ input(input)
20+ }
21+
22+ val max = moderation.results[0 ].categoryScores.entries.maxBy { it.value }
23+ println (" Highest category: ${max.key} with a score of ${max.value} " )
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ package com.cjcrafter.openai.moderations
2+
3+ fun createModerationRequest (block : CreateModerationRequest .Builder .() -> Unit ): CreateModerationRequest {
4+ return CreateModerationRequest .builder().apply (block).build()
5+ }
6+
7+ fun ModerationHandler.create (block : CreateModerationRequest .Builder .() -> Unit ): Moderation {
8+ val request = createModerationRequest(block)
9+ return create(request)
10+ }
You can’t perform that action at this time.
0 commit comments