Skip to content

Commit 6fa2dfc

Browse files
refactor: configure OpenAI client with API key from AiModerationConfig and update config with new field
1 parent 25f0810 commit 6fa2dfc

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

surf-chat-bukkit/src/main/kotlin/dev/slne/surf/chat/bukkit/ai/OpenAiService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.openai.client.okhttp.OpenAIOkHttpClientAsync
55
import com.openai.models.moderations.Moderation
66
import com.openai.models.moderations.ModerationCreateParams
77
import com.sksamuel.aedile.core.asLoadingCache
8+
import dev.slne.surf.chat.bukkit.config.aiModerationConfig
89
import dev.slne.surf.surfapi.core.api.util.emptyObject2DoubleMap
910
import it.unimi.dsi.fastutil.objects.Object2DoubleMap
1011
import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap
@@ -16,7 +17,7 @@ import kotlin.time.toJavaDuration
1617
val openAiService = OpenAiService()
1718

1819
class OpenAiService {
19-
private val client = OpenAIOkHttpClientAsync.fromEnv()
20+
private val client = OpenAIOkHttpClientAsync.builder().apiKey(aiModerationConfig.apiKey).build()
2021

2122
val resultCache = Caffeine
2223
.newBuilder()

surf-chat-bukkit/src/main/kotlin/dev/slne/surf/chat/bukkit/config/AiModerationConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ data class AiModerationConfig(
1212
val webhookUrl: String = "",
1313
val webhookAvatarUrl: String = "https://i.imgur.com/4vEeYfH.png",
1414
val userPanelPrefix: String = "https://support.castcrafter.de/cloud/cloud-players/",
15+
val apiKey: String = ""
1516
) {
1617

1718
companion object {

0 commit comments

Comments
 (0)