Skip to content

Commit

Permalink
Add-scalafix (#15)
Browse files Browse the repository at this point in the history
* βž• add scalafix plugin

* πŸ”§ Enabled semanticDb for scalafix.

* πŸ”§ removedUnused not supported in Scala 3.3.1

* 🎨 Ran OrganizeImports via Scalafix

* πŸ“ Added instructions for scalafix

* ♻️ Remove unused imports in some files.

* ♻️ Refactored build.sbt

* πŸ‘· Added more settings to build.sbt

* πŸ‘· Run organiseImports check in github workflow

* πŸ‘· Added distribution value for java

* πŸ‘· Added zulu java distrobution

* πŸ‘· Replaced jvm with java-version

* πŸ‘· Fixed scalafix rule for the check

* πŸ§ͺ Ensure scalafix is enforced

* πŸ‘· Add --check flag to scalafix workflow

* πŸ‘· Ran OrganizeImports so workfow check will pass

* πŸ‘· Try to switch to scalafmt

* 🚚 Moved tests to folder that sbt checks

* βž• Added test dependency

* πŸ‘· Switched to sbt for running tests

* βž• add scalafmt plugin

* 🎨

* πŸ‘· Try workflow without extra java setup step.

* πŸ‘· Removed quotes for sbt test command.

---------

Co-authored-by: ff137 <[email protected]>
  • Loading branch information
Laderlappen and ff137 authored Dec 7, 2023
1 parent b30b9e0 commit a378594
Show file tree
Hide file tree
Showing 27 changed files with 191 additions and 179 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ jobs:
with:
jvm: 21
- run: scala-cli fmt --check .
- run: scala-cli --power test .
- run: sbt test
- run: sbt "scalafix --check OrganizeImports"

build:
name: Build and push Docker
Expand Down
1 change: 1 addition & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OrganizeImports.removeUnused = false
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ docker run -it --rm \
-e OPENAI_TOKEN='oai_key' \
ghcr.io/didx-xyz/dawn-patrol
```

## Scalafix

To organise imports, while in sbt run: scalafix OrganizeImports
88 changes: 56 additions & 32 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,37 +1,61 @@
scalaVersion := "3.3.1"

scalacOptions ++= Seq("-Xmax-inlines", "50")
lazy val circeVersion = "0.14.6"
lazy val pureconfigVersion = "0.17.4"
lazy val redis4CatsVersion = "1.5.2"
lazy val sttpClient3Version = "3.9.1"
lazy val langchain4jVersion = "0.23.0"
lazy val xefVersion = "0.0.3"

val circeVersion = "0.14.6"
val pureconfigVersion = "0.17.4"
val redis4CatsVersion = "1.5.2"
val sttpClient3Version = "3.9.1"
val langchain4jVersion = "0.23.0"
val xefVersion = "0.0.3"
lazy val root = (project in file("."))
.settings(
settings,
libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"com.github.pureconfig" %% "pureconfig-core" % pureconfigVersion,
"com.github.pureconfig" %% "pureconfig-cats-effect" % pureconfigVersion,
"dev.profunktor" %% "redis4cats-effects" % redis4CatsVersion,
"dev.profunktor" %% "redis4cats-log4cats" % redis4CatsVersion,
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M6",
"com.softwaremill.sttp.client3" %% "core" % sttpClient3Version,
"com.softwaremill.sttp.client3" %% "circe" % sttpClient3Version,
"com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpClient3Version,
"de.brendamour" % "jpasskit" % "0.3.3",
"com.outr" %% "scribe" % "3.12.2",
"com.lihaoyi" %% "upickle" % "3.1.3",
"dev.langchain4j" % "langchain4j" % langchain4jVersion,
"dev.langchain4j" % "langchain4j-hugging-face" % langchain4jVersion,
"com.xebia" %% "xef-scala" % xefVersion,
"com.xebia" % "xef-pdf" % xefVersion,
"com.xebia" % "xef-reasoning-jvm" % xefVersion,
"com.xebia" % "xef-openai" % xefVersion,
"ch.qos.logback" % "logback-classic" % "1.4.11",
"org.apache.logging.log4j" % "log4j-core" % "2.21.1",
"org.typelevel" %% "log4cats-slf4j" % "2.6.0",
"co.fs2" %% "fs2-core" % "3.9.3",
"org.typelevel" %% "munit-cats-effect" % "2.0.0-M4" % "test"
)
)

libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"com.github.pureconfig" %% "pureconfig-core" % pureconfigVersion,
"com.github.pureconfig" %% "pureconfig-cats-effect" % pureconfigVersion,
"dev.profunktor" %% "redis4cats-effects" % redis4CatsVersion,
"dev.profunktor" %% "redis4cats-log4cats" % redis4CatsVersion,
"com.softwaremill.sttp.client4" %% "core" % "4.0.0-M6",
"com.softwaremill.sttp.client3" %% "core" % sttpClient3Version,
"com.softwaremill.sttp.client3" %% "circe" % sttpClient3Version,
"com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % sttpClient3Version,
"de.brendamour" % "jpasskit" % "0.3.3",
"com.outr" %% "scribe" % "3.12.2",
"com.lihaoyi" %% "upickle" % "3.1.3",
"dev.langchain4j" % "langchain4j" % langchain4jVersion,
"dev.langchain4j" % "langchain4j-hugging-face" % langchain4jVersion,
"com.xebia" %% "xef-scala" % xefVersion,
"com.xebia" % "xef-pdf" % xefVersion,
"com.xebia" % "xef-reasoning-jvm" % xefVersion,
"com.xebia" % "xef-openai" % xefVersion,
"ch.qos.logback" % "logback-classic" % "1.4.11",
"org.apache.logging.log4j" % "log4j-core" % "2.21.1",
"org.typelevel" %% "log4cats-slf4j" % "2.6.0",
"co.fs2" %% "fs2-core" % "3.9.3"
// Settings
lazy val compilerOptions = Seq(
"-Xmax-inlines",
"50",
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-language:postfixOps", // Allow postfix operator notation, such as 1 to 10 toList (not recommended)
"-deprecation"
)

lazy val commonSettings = Seq(
scalacOptions ++= compilerOptions
)

lazy val scalafixSettings = Seq(semanticdbEnabled := true)

lazy val settings = commonSettings ++ scalafixSettings
3 changes: 3 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")
35 changes: 13 additions & 22 deletions src/main/scala/xyz/didx/ConversationPollingHandler.scala
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
package xyz.didx

import scala.collection.mutable
//import io.circe._
import cats.data.EitherT
import cats.effect.FiberIO
import cats.effect.IO
import cats.effect.Ref
import cats.implicits.*
import io.circe.parser.*
import io.circe.syntax.*
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger
import sttp.client3.SttpBackend
import xyz.didx.ai.AiHandler
import xyz.didx.ai.model.ChatState
import xyz.didx.config.ConfigReaders.*
import xyz.didx.logging.LogWriter.*
import xyz.didx.didcomm.*
import xyz.didx.logging.LogWriter.*
import xyz.didx.messages.*
import xyz.didx.passkit.PasskitAgent
import xyz.didx.registry.*
import xyz.didx.signal.SignalBot

import java.net.URI
import xyz.didx.signal.SignalBot
import cats.effect.kernel.Resource
import xyz.didx.connection.RedisStorage
import xyz.didx.messages.*
import cats.data.EitherT
import cats.effect.IO
import cats.implicits.*
import cats.syntax.traverse.*
import scala.collection.mutable

import SignalMessageCodec.memberDecoder
import xyz.didx.registry.*
import RegistryResponseCodec.encodeRegistryRequest
import xyz.didx.didcomm.Service
import xyz.didx.didcomm.ServiceEndpointNodes
import xyz.didx.registry.RegistryClient
import xyz.didx.openai.OpenAIAgent
import xyz.didx.passkit.PasskitAgent
import xyz.didx.ai.AiHandler
import xyz.didx.ai.model.ChatState
import cats.effect.Ref
import cats.effect.FiberIO

class ConversationPollingHandler(using logger: Logger[IO]):
val appConf = getConf(using logger)
Expand Down
18 changes: 8 additions & 10 deletions src/main/scala/xyz/didx/DawnPatrol.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package xyz.didx
import cats.effect.*
import cats.effect.IOApp
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger

import cats.effect.IO
import cats.effect.IOApp
import cats.effect.std.Dispatcher
import fs2.Stream

import scala.concurrent.duration.*

import xyz.didx.ConversationPollingHandler
import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger
import sttp.client3.SttpBackend
import xyz.didx.config.ConfigReaders.getConf
import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend
import xyz.didx.ai.handler.Opportunities
import xyz.didx.config.ConfigReaders.getConf

import scala.concurrent.duration.*

object DawnPatrol extends IOApp.Simple:
// override protected def blockedThreadDetectionEnabled = true
Expand Down
24 changes: 11 additions & 13 deletions src/main/scala/xyz/didx/SignalBot.scala
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package xyz.didx.signal

import cats.data.EitherT
import cats.effect.FiberIO
import cats.effect.IO
import cats.effect.Ref
import cats.implicits.*
import fs2.Stream
import io.circe.syntax.*
import pureconfig.ConfigReader
import pureconfig.ConfigSource
import pureconfig.generic.derivation.default.*
import sttp.client3.*
import sttp.client3.circe.asJson
import sttp.model.StatusCode
import xyz.didx.messages.SignalMessage
import xyz.didx.messages.SignalMessageCodec.signalMessageDecoder
import xyz.didx.messages.SignalMessageCodec.signalSendMessage
import xyz.didx.messages.SignalSendMessage
import xyz.didx.messages.SignalSimpleMessage
import fs2.Stream
//import io.circe.*
import io.circe.parser.*
import io.circe.syntax.*
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger
import pureconfig.*
import pureconfig.generic.derivation.default.*
import sttp.client3.*
import sttp.client3.circe.*
import sttp.model.*

import scala.concurrent.duration._
import cats.effect.Ref
import cats.effect.FiberIO

case class SignalConfig(
signalUrl: String,
Expand Down
14 changes: 7 additions & 7 deletions src/main/scala/xyz/didx/ai/AiHandler.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package xyz.didx.ai

import scala.collection.mutable
import xyz.didx.ai.model.ChatState
import xyz.didx.ai.handler.OnboardingHandler
import xyz.didx.ai.handler.ConfirmOnboardingHandler
import cats.effect.IO
import dev.langchain4j.data.segment.TextSegment
import xyz.didx.ai.embedding.EmbeddingHandler
import dev.langchain4j.store.embedding.EmbeddingMatch
import xyz.didx.ai.embedding.EmbeddingHandler
import xyz.didx.ai.handler.ConfirmOnboardingHandler
import xyz.didx.ai.handler.OnboardingHandler
import xyz.didx.ai.model.ChatState
import xyz.didx.ai.model.OnboardingResult
import xyz.didx.ai.model.ConfirmedOnboardingResult
import cats.effect.IO

import scala.collection.mutable
import scala.util.Try

object AiHandler {
Expand Down
16 changes: 8 additions & 8 deletions src/main/scala/xyz/didx/ai/embedding/EmbeddingHandler.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package xyz.didx.ai.embedding

import scala.collection.JavaConverters._
import dev.langchain4j.data.document.Metadata
import dev.langchain4j.data.embedding.Embedding
import dev.langchain4j.data.segment.TextSegment
import dev.langchain4j.store.embedding.{EmbeddingMatch, EmbeddingStore}
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore
import dev.langchain4j.model.huggingface.HuggingFaceEmbeddingModel;

import dev.langchain4j.model.embedding.EmbeddingModel
import dev.langchain4j.data.segment.TextSegment
import dev.langchain4j.data.document.Metadata
import dev.langchain4j.model.huggingface.HuggingFaceEmbeddingModel
import dev.langchain4j.model.output.Response
import dev.langchain4j.store.embedding.EmbeddingMatch
import dev.langchain4j.store.embedding.EmbeddingStore
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore
import xyz.didx.ai.model.Opportunity

import java.time.Duration
import dev.langchain4j.model.output.Response
import scala.collection.JavaConverters._

object EmbeddingHandler {
private val embeddingModel: EmbeddingModel = HuggingFaceEmbeddingModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package xyz.didx.ai.handler

import scala.collection.mutable
import com.xebia.functional.xef.prompt.PromptBuilder
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.prompt.PromptBuilder
import com.xebia.functional.xef.scala.conversation.*
import com.xebia.functional.xef.store.ConversationId
import xyz.didx.ai.model.AgentScript
import xyz.didx.ai.model.ConfirmedOnboardingResult
import xyz.didx.ai.model.OnboardingResult
import xyz.didx.ai.model.AgentScript

import scala.collection.mutable

object ConfirmOnboardingHandler {
def getConfirmation(
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/xyz/didx/ai/handler/Onboarding.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package xyz.didx.ai.handler

import scala.collection.mutable
import com.xebia.functional.xef.prompt.PromptBuilder
import com.xebia.functional.xef.prompt.Prompt
import com.xebia.functional.xef.prompt.PromptBuilder
import com.xebia.functional.xef.scala.conversation.*
import com.xebia.functional.xef.store.ConversationId
import xyz.didx.ai.model.OnboardingResult
import xyz.didx.ai.model.AgentScript
import xyz.didx.ai.model.OnboardingResult

import scala.collection.mutable
import scala.util.Random

object OnboardingHandler {
Expand Down
21 changes: 12 additions & 9 deletions src/main/scala/xyz/didx/ai/handler/Opportunities.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package xyz.didx.ai.handler

import java.util.Base64
import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import java.util.zip.{GZIPInputStream, GZIPOutputStream}
import sttp.client4.*
import cats.data.EitherT
import cats.effect.IO
import io.circe
import io.circe.generic.auto._
import io.circe.parser.decode
import sttp.client4.*
import ujson.Value.Value
import xyz.didx.ai.embedding.EmbeddingHandler
import xyz.didx.ai.model.Opportunity

import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.util.Base64
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import scala.util.Try
import scala.util.chaining.scalaUtilChainingOps
import io.circe.parser.decode
import io.circe.generic.auto._
import xyz.didx.ai.model.Opportunity
import io.circe
import xyz.didx.ai.embedding.EmbeddingHandler

object Opportunities {

Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/xyz/didx/ai/model/Opportunity.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package xyz.didx.ai.model

import io.circe.{Decoder, DecodingFailure, HCursor}
import io.circe.Decoder
import io.circe.DecodingFailure
import io.circe.HCursor

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/xyz/didx/ai/openai/OpenAIAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cats.effect.IO
import cats.effect.Sync
import cats.implicits._
import cats.implicits._
import xyz.didx.messages.SignalSimpleMessage
import io.circe.*
import io.circe.syntax.*
import org.typelevel.log4cats.Logger
Expand All @@ -14,6 +13,7 @@ import pureconfig.*
import pureconfig.generic.derivation.default.*
import sttp.client3.*
import sttp.client3.circe.*
import xyz.didx.messages.SignalSimpleMessage

case class APIConf(apiKey: String, orgId: String) derives ConfigReader:
override def toString: String =
Expand Down
Loading

0 comments on commit a378594

Please sign in to comment.