Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-scalafix #15

Merged
merged 25 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
71bd4ad
:heavy_plus_sign: add scalafix plugin
Laderlappen Dec 5, 2023
239b565
🔧 Enabled semanticDb for scalafix.
Laderlappen Dec 6, 2023
6582f4c
🔧 removedUnused not supported in Scala 3.3.1
Laderlappen Dec 6, 2023
40a1874
🎨 Ran OrganizeImports via Scalafix
Laderlappen Dec 6, 2023
74ac936
📝 Added instructions for scalafix
Laderlappen Dec 6, 2023
6dd90de
♻️ Remove unused imports in some files.
Laderlappen Dec 6, 2023
14db327
♻️ Refactored build.sbt
Laderlappen Dec 6, 2023
2afe406
👷 Added more settings to build.sbt
Laderlappen Dec 6, 2023
49c07fb
👷 Run organiseImports check in github workflow
Laderlappen Dec 6, 2023
9379b45
👷 Added distribution value for java
Laderlappen Dec 6, 2023
c2d3b54
👷 Added zulu java distrobution
Laderlappen Dec 6, 2023
3a33a9f
👷 Replaced jvm with java-version
Laderlappen Dec 6, 2023
158a9a4
👷 Fixed scalafix rule for the check
Laderlappen Dec 6, 2023
c138cd3
🧪 Ensure scalafix is enforced
Laderlappen Dec 6, 2023
0330d49
👷 Add --check flag to scalafix workflow
Laderlappen Dec 6, 2023
f4880c1
👷 Ran OrganizeImports so workfow check will pass
Laderlappen Dec 6, 2023
e82c395
👷 Try to switch to scalafmt
Laderlappen Dec 6, 2023
2b88e46
🚚 Moved tests to folder that sbt checks
Laderlappen Dec 6, 2023
138784e
➕ Added test dependency
Laderlappen Dec 6, 2023
c92aff8
👷 Switched to sbt for running tests
Laderlappen Dec 6, 2023
774bebb
:heavy_plus_sign: add scalafmt plugin
ff137 Dec 7, 2023
3da0c83
:art:
ff137 Dec 7, 2023
8af60d7
👷 Try workflow without extra java setup step.
Laderlappen Dec 7, 2023
7c24d81
Merge branch 'add-scalafix' of https://github.com/didx-xyz/dawn-patro…
Laderlappen Dec 7, 2023
72134b2
👷 Removed quotes for sbt test command.
Laderlappen Dec 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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