diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml index b9d7229..28175b0 100644 --- a/.github/workflows/bld.yml +++ b/.github/workflows/bld.yml @@ -15,12 +15,12 @@ jobs: steps: - name: Checkout source repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up JDK ${{ matrix.java-version }} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: "zulu" java-version: ${{ matrix.java-version }} diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml index 8b6e513..b20abc9 100644 --- a/config/detekt/baseline.xml +++ b/config/detekt/baseline.xml @@ -10,7 +10,6 @@ LongMethod:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List<Message> LongParameterList:Comment.kt$Comment$( channel: String, cmd: String, entry: EntryLink, entryIndex: Int, commentIndex: Int, event: GenericMessageEvent ) LongParameterList:EntryLink.kt$EntryLink$( // Link's comments val comments: MutableList<EntryComment> = mutableListOf(), // Tags/categories val tags: MutableList<SyndCategory> = mutableListOf(), // Channel var channel: String, // Creation date var date: Date = Calendar.getInstance().time, // Link's URL var link: String, // Author's login var login: String = "", // Author's nickname var nick: String, // Link's title var title: String ) - MagicNumber:ChatGpt.kt$ChatGpt$400 MagicNumber:ChatGpt.kt$ChatGpt.Companion$200 MagicNumber:ChatGpt.kt$ChatGpt.Companion$429 MagicNumber:Comment.kt$Comment$3 @@ -20,7 +19,6 @@ MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$4 MagicNumber:Cycle.kt$Cycle$10 MagicNumber:Cycle.kt$Cycle$1000L - MagicNumber:Gemini.kt$Gemini$400 MagicNumber:Ignore.kt$Ignore$8 MagicNumber:Info.kt$Info.Companion$30 MagicNumber:Info.kt$Info.Companion$365 diff --git a/config/pmd.xml b/config/pmd.xml deleted file mode 100644 index e23c3fa..0000000 --- a/config/pmd.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - Erik's Ruleset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ^ignore$ - - - - - - - - - - - - - - - - diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index 1b1e424..a0b841f 100644 Binary files a/lib/bld/bld-wrapper.jar and b/lib/bld/bld-wrapper.jar differ diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index c51811b..8911afc 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,9 +1,9 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true -bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.3 -bld.extensions=com.uwyn.rife2:bld-generated-version:0.9.5 +bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5 +bld.extensions=com.uwyn.rife2:bld-generated-version:0.9.6-SNAPSHOT bld.extensions-kotlin=com.uwyn.rife2:bld-kotlin:0.9.3 -bld.extensions-detekt=com.uwyn.rife2:bld-detekt:0.9.2 +bld.extensions-detekt=com.uwyn.rife2:bld-detekt:0.9.4-SNAPSHOT bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.downloadLocation= bld.sourceDirectories= diff --git a/src/bld/java/net/thauvin/erik/MobibotBuild.java b/src/bld/java/net/thauvin/erik/MobibotBuild.java index a3369d2..9426468 100644 --- a/src/bld/java/net/thauvin/erik/MobibotBuild.java +++ b/src/bld/java/net/thauvin/erik/MobibotBuild.java @@ -57,6 +57,8 @@ import static rife.bld.dependencies.Scope.compile; import static rife.bld.dependencies.Scope.test; public class MobibotBuild extends Project { + private static final String DETEKT_BASELINE = "config/detekt/baseline.xml"; + public MobibotBuild() { pkg = "net.thauvin.erik.mobibot"; name = "mobibot"; @@ -81,18 +83,18 @@ public class MobibotBuild extends Project { .include(dependency("com.github.pircbotx", "pircbotx", "2.3.1")) // Commons (mostly for PircBotX) .include(dependency("org.apache.commons", "commons-lang3", "3.14.0")) - .include(dependency("org.apache.commons", "commons-text", "1.11.0")) + .include(dependency("org.apache.commons", "commons-text", "1.12.0")) .include(dependency("commons-codec", "commons-codec", "1.16.1")) .include(dependency("commons-net", "commons-net", "3.10.0")) // Google .include(dependency("com.google.code.gson", "gson", "2.10.1")) .include(dependency("com.google.guava", "guava", "33.1.0-jre")) - .include(dependency("com.google.cloud", "google-cloud-vertexai", version(0, 7, 0))) + .include(dependency("com.google.cloud", "google-cloud-vertexai", "1.1.0")) // Kotlin .include(dependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.8.0")) .include(dependency("org.jetbrains.kotlinx", "kotlinx-cli-jvm", "0.3.6")) // Logging - .include(dependency("org.slf4j", "slf4j-api", "2.0.12")) + .include(dependency("org.slf4j", "slf4j-api", "2.0.13")) .include(dependency("org.apache.logging.log4j", "log4j-api", log4j)) .include(dependency("org.apache.logging.log4j", "log4j-core", log4j)) .include(dependency("org.apache.logging.log4j", "log4j-slf4j2-impl", log4j)) @@ -107,7 +109,7 @@ public class MobibotBuild extends Project { .include(dependency("net.thauvin.erik", "cryptoprice", "1.0.3-SNAPSHOT")) .include(dependency("net.thauvin.erik", "jokeapi", "0.9.2-SNAPSHOT")) .include(dependency("net.thauvin.erik", "pinboard-poster", "1.1.2-SNAPSHOT")) - .include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", "1.4.0")); + .include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", "1.5.0")); scope(test) .include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 28, 0))) .include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin)) @@ -162,7 +164,7 @@ public class MobibotBuild extends Project { public void detekt() throws ExitStatusException, IOException, InterruptedException { new DetektOperation() .fromProject(this) - .baseline("config/detekt/baseline.xml") + .baseline(DETEKT_BASELINE) .execute(); } @@ -170,7 +172,7 @@ public class MobibotBuild extends Project { public void detektBaseline() throws ExitStatusException, IOException, InterruptedException { new DetektOperation() .fromProject(this) - .baseline("config/detekt/baseline.xml") + .baseline(DETEKT_BASELINE) .createBaseline(true) .execute(); } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/ReleaseInfo.kt b/src/main/kotlin/net/thauvin/erik/mobibot/ReleaseInfo.kt index 6708558..8a95733 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/ReleaseInfo.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/ReleaseInfo.kt @@ -14,12 +14,12 @@ import java.time.ZoneId */ object ReleaseInfo { const val PROJECT = "mobibot" - const val VERSION = "0.8.0-rc+20240315212330" + const val VERSION = "0.8.0-rc+20240417230232" @JvmField @Suppress("MagicNumber") val BUILD_DATE: LocalDateTime = LocalDateTime.ofInstant( - Instant.ofEpochMilli(1710563010532L), ZoneId.systemDefault() + Instant.ofEpochMilli(1713420152538L), ZoneId.systemDefault() ) const val WEBSITE = "https://mobitopia.org/mobibot/" diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Gemini.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Gemini.kt index 80f3d13..c0faefa 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Gemini.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Gemini.kt @@ -33,6 +33,8 @@ package net.thauvin.erik.mobibot.modules import com.google.cloud.vertexai.VertexAI import com.google.cloud.vertexai.api.GenerationConfig +import com.google.cloud.vertexai.api.HarmCategory +import com.google.cloud.vertexai.api.SafetySetting import com.google.cloud.vertexai.generativeai.ChatSession import com.google.cloud.vertexai.generativeai.GenerativeModel import com.google.cloud.vertexai.generativeai.ResponseHandler @@ -41,6 +43,7 @@ import net.thauvin.erik.mobibot.Utils.sendMessage import org.pircbotx.hooks.types.GenericMessageEvent import org.slf4j.Logger import org.slf4j.LoggerFactory +import java.util.* class Gemini : AbstractModule() { @@ -109,9 +112,28 @@ class Gemini : AbstractModule() { try { VertexAI(projectId, location).use { vertexAI -> val generationConfig = GenerationConfig.newBuilder().setMaxOutputTokens(maxToken).build() + val safetySettings = Arrays.asList( + SafetySetting.newBuilder() + .setCategory(HarmCategory.HARM_CATEGORY_HATE_SPEECH) + .setThreshold(SafetySetting.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE) + .build(), + SafetySetting.newBuilder() + .setCategory(HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT) + .setThreshold(SafetySetting.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE) + .build(), + SafetySetting.newBuilder() + .setCategory(HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT) + .setThreshold(SafetySetting.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE) + .build(), + SafetySetting.newBuilder() + .setCategory(HarmCategory.HARM_CATEGORY_HARASSMENT) + .setThreshold(SafetySetting.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE) + .build() + ) val model = GenerativeModel.Builder().setModelName("gemini-pro-vision") .setGenerationConfig(generationConfig) .setVertexAi(vertexAI).build() + .withSafetySettings(safetySettings) val session = ChatSession(model) val response = session.sendMessage(query)