Skip to content

Commit

Permalink
1.0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Oct 14, 2023
1 parent 3105708 commit a72345a
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 49 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ Maven:
<dependency>
<groupId>com.simiacryptus</groupId>
<artifactId>skyenet-webui</artifactId>
<version>1.0.16</version>
<version>1.0.17</version>
</dependency>
```

Gradle:

```groovy
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.16'
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.17'
```

```kotlin
implementation("com.simiacryptus:skyenet:1.0.16")
implementation("com.simiacryptus:skyenet:1.0.17")
```

### 🌟 To Use
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ val kotlin_version = "1.7.22"
val junit_version = "5.9.2"
dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.18")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.19")

implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.5")

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gradle Releases -> https://github.com/gradle/gradle/releases
libraryGroup = com.simiacryptus.skyenet
libraryVersion = 1.0.16
libraryVersion = 1.0.17
gradleVersion = 7.6.1

# Opt-out flag for bundling Kotlin standard library -> https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
Expand Down
25 changes: 14 additions & 11 deletions util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,32 @@ kotlin {
}

val kotlin_version = "1.7.22"
val jetty_version = "11.0.15"
dependencies {
val jetty_version = "11.0.17"
val logback_version = "1.2.12"

dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.18")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.19")

implementation(project(":core"))
implementation(project(":webui"))

implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.7.1")
implementation(kotlin("stdlib-jdk8"))

implementation(group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version = kotlin_version)
implementation(group = "com.google.cloud", name = "google-cloud-texttospeech", version = "2.0.0")
implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.7.1")

compileOnly(group = "commons-io", name = "commons-io", version = "2.11.0")
compileOnly(group = "org.eclipse.jetty", name = "jetty-server", version = jetty_version)
compileOnly(group = "com.google.cloud", name = "google-cloud-texttospeech", version = "2.28.0")
compileOnly(group = "com.amazonaws", name = "aws-java-sdk", version = "1.12.454")

implementation(group = "org.eclipse.jetty", name = "jetty-server", version = jetty_version)
implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.5")
implementation(group = "ch.qos.logback", name = "logback-classic", version = "1.4.7")
implementation(group = "ch.qos.logback", name = "logback-core", version = "1.4.7")
implementation(group = "commons-io", name = "commons-io", version = "2.11.0")
implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.9")
compileOnly(group = "ch.qos.logback", name = "logback-classic", version = logback_version)
compileOnly(group = "ch.qos.logback", name = "logback-core", version = logback_version)

testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-api", version = "5.9.2")
testRuntimeOnly(group = "org.junit.jupiter", name = "junit-jupiter-engine", version = "5.9.2")

testImplementation(kotlin("script-runtime"))

}
Expand Down
40 changes: 40 additions & 0 deletions util/src/main/kotlin/com/simiacryptus/skyenet/util/AwsUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.simiacryptus.skyenet.util

import com.amazonaws.services.kms.AWSKMSClientBuilder
import com.amazonaws.services.kms.model.DecryptRequest
import com.amazonaws.services.kms.model.EncryptRequest
import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*

object AwsUtil {

fun encryptFile(inputFilePath: String, outputFilePath: String) {
val filePath = Paths.get(inputFilePath)
val fileBytes = Files.readAllBytes(filePath)
val kmsClient = AWSKMSClientBuilder.standard().build()
val encryptRequest =
EncryptRequest().withKeyId("arn:aws:kms:us-east-1:470240306861:key/a1340b89-64e6-480c-a44c-e7bc0c70dcb1")
.withPlaintext(ByteBuffer.wrap(fileBytes))
val result = kmsClient.encrypt(encryptRequest)
val cipherTextBlob = result.ciphertextBlob
val encryptedData = Base64.getEncoder().encodeToString(cipherTextBlob.array())
val outputPath = Paths.get(outputFilePath)
Files.write(outputPath, encryptedData.toByteArray())
}

fun decryptResource(resourceFile: String): String {
val encryptedData = javaClass.classLoader.getResourceAsStream(resourceFile)?.readAllBytes()
if (null == encryptedData) {
throw RuntimeException("Unable to load resource: $resourceFile")
}
val decodedData = Base64.getDecoder().decode(encryptedData)
val kmsClient = AWSKMSClientBuilder.defaultClient()
val decryptRequest = DecryptRequest().withCiphertextBlob(ByteBuffer.wrap(decodedData))
val decryptResult = kmsClient.decrypt(decryptRequest)
val decryptedData = decryptResult.plaintext.array()
return String(decryptedData, StandardCharsets.UTF_8)
}
}
7 changes: 4 additions & 3 deletions webui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ kotlin {
}

val kotlin_version = "1.7.22"
val jetty_version = "11.0.15"
val jackson_version = "2.15.0"
val jetty_version = "11.0.17"
val jackson_version = "2.15.2"
dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.18")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.19")

implementation(project(":core"))
testImplementation(project(":groovy"))
Expand Down Expand Up @@ -61,6 +61,7 @@ dependencies {
implementation(group = "com.google.oauth-client", name = "google-oauth-client-jetty", version = "1.34.1")
implementation(group = "com.google.apis", name = "google-api-services-oauth2", version = "v2-rev157-1.25.0")
implementation(group = "commons-io", name = "commons-io", version = "2.11.0")
implementation(group = "commons-codec", name = "commons-codec", version = "1.16.0")

implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.5")
testImplementation(group = "org.slf4j", name = "slf4j-simple", version = "2.0.5")
Expand Down
15 changes: 15 additions & 0 deletions webui/src/main/kotlin/com/simiacryptus/skyenet/body/SessionBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ abstract class SessionBase(val sessionId: String) : SessionInterface {
override fun getReplay(): List<String> {
return sentMessages
}

fun newUpdate(
operationID: String, spinner: String
): (String, Boolean) -> Unit {
var responseContents = ChatSession.divInitializer(operationID)
val sendUpdate: (String, Boolean) -> Unit = { message, showProgress ->
if (message.isNotBlank()) {
responseContents += """<div>$message</div>"""
}
val spinner = if (showProgress) """<div>$spinner</div>""" else ""
send("""$responseContents$spinner""")
}
send(responseContents)
return sendUpdate
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.simiacryptus.skyenet.body

import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.util.JsonUtil
import java.util.concurrent.Semaphore
import java.util.function.Consumer

Expand Down Expand Up @@ -29,56 +30,49 @@ abstract class SkyenetMacroChat(

override fun newSession(sessionId: String): SessionInterface {
val handler = MutableSessionHandler(null)
val parent = this@SkyenetMacroChat

val basicChatSession = object : PersistentSessionBase(
sessionId = sessionId,
parent.sessionDataStorage
this@SkyenetMacroChat.sessionDataStorage
) {
val playSempaphores = mutableMapOf<String, Semaphore>()
val threads = mutableMapOf<String, Thread>()
val regenTriggers = mutableMapOf<String, Consumer<Unit>>()
val linkTriggers = mutableMapOf<String, Consumer<Unit>>()
val txtTriggers = mutableMapOf<String, Consumer<String>>()
val session : PersistentSessionBase = this
override fun run(userMessage: String) {
val operationID = ChatSession.randomID()
val sendUpdate = newUpdate(operationID, spinner)
val thread = Thread {
playSempaphores[operationID] = Semaphore(0)
var responseContents = ChatSession.divInitializer(operationID)
try {
processMessage(sessionId, userMessage, object : SessionUI {
override val spinner: String get() = """<div>${parent.spinner}</div>"""
override val playButton: String get() = """<button class="play-button" data-id="$operationID">▶</button>"""
override val cancelButton: String get() = """<button class="cancel-button" data-id="$operationID">&times;</button>"""
override val regenButton: String get() = """<button class="regen-button" data-id="$operationID">♲</button>"""
processMessage(sessionId, userMessage, session, object : SessionUI {
override val spinner: String get() = """<div>${this@SkyenetMacroChat.spinner}</div>"""
override val playButton: String get() = """<button class="play-button" data-id="$operationID">▶</button>"""
override val cancelButton: String get() = """<button class="cancel-button" data-id="$operationID">&times;</button>"""
override val regenButton: String get() = """<button class="regen-button" data-id="$operationID">♲</button>"""

override fun hrefLink(handler:Consumer<Unit>): String {
val operationID = ChatSession.randomID()
linkTriggers[operationID] = handler
return """<a class="href-link" data-id="$operationID">"""
}
override fun hrefLink(handler:Consumer<Unit>): String {
val operationID = ChatSession.randomID()
linkTriggers[operationID] = handler
return """<a class="href-link" data-id="$operationID">"""
}

override fun textInput(handler:Consumer<String>): String {
val operationID = ChatSession.randomID()
txtTriggers[operationID] = handler
//language=HTML
return """<form class="reply-form">
<textarea class="reply-input" data-id="$operationID" rows="3" placeholder="Type a message"></textarea>
<button class="text-submit-button" data-id="$operationID">Send</button>
</form>""".trimIndent()
}
override fun textInput(handler:Consumer<String>): String {
val operationID = ChatSession.randomID()
txtTriggers[operationID] = handler
//language=HTML
return """<form class="reply-form">
<textarea class="reply-input" data-id="$operationID" rows="3" placeholder="Type a message"></textarea>
<button class="text-submit-button" data-id="$operationID">Send</button>
</form>""".trimIndent()
}

}) { message, showProgress ->
if (message.isNotBlank()) {
responseContents += """<div>$message</div>"""
}
val spinner = if (showProgress) """<div>${parent.spinner}</div>""" else ""
send("""$responseContents$spinner""")
}
}, sendUpdate)
} catch (e: Throwable) {
e.printStackTrace()
} finally {
send(responseContents)
}
}
threads[operationID] = thread
Expand Down Expand Up @@ -111,9 +105,34 @@ abstract class SkyenetMacroChat(
abstract fun processMessage(
sessionId: String,
userMessage: String,
session: PersistentSessionBase,
sessionUI: SessionUI,
sendUpdate: (String, Boolean) -> Unit
)

companion object {
fun iterate(
sessionUI: SessionUI,
parameters: Any,
sendUpdate: (String, Boolean) -> Unit,
feedbackFn: (t: String) -> Unit,
selectLabel: String = "Execute",
selectFn: (t: Unit) -> Unit
) {
sendUpdate(
"""
<pre>${JsonUtil.toJson(parameters)}</pre>
<br/>
${sessionUI.textInput(feedbackFn)}
<br/>
${
sessionUI.hrefLink(
selectFn
)
}$selectLabel</a>""", false
)
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.simiacryptus.skyenet
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.proxy.ChatProxy
import com.simiacryptus.skyenet.body.ChatSessionFlexmark
import com.simiacryptus.skyenet.body.PersistentSessionBase
import com.simiacryptus.skyenet.body.SkyenetMacroChat
import com.simiacryptus.util.JsonUtil
import com.simiacryptus.util.describe.Description
Expand Down Expand Up @@ -116,6 +117,7 @@ class CookbookGenerator(
override fun processMessage(
sessionId: String,
userMessage: String,
session: PersistentSessionBase,
sessionUI: SessionUI,
sendUpdate: (String, Boolean) -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.simiacryptus.skyenet
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.proxy.ChatProxy
import com.simiacryptus.skyenet.body.ChatSessionFlexmark
import com.simiacryptus.skyenet.body.PersistentSessionBase
import com.simiacryptus.skyenet.body.SkyenetMacroChat
import com.simiacryptus.util.JsonUtil
import com.simiacryptus.util.describe.Description
Expand Down Expand Up @@ -116,6 +117,7 @@ class SkyenetScienceBook(
override fun processMessage(
sessionId: String,
userMessage: String,
session: PersistentSessionBase,
sessionUI: SessionUI,
sendUpdate: (String, Boolean) -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.simiacryptus.skyenet
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.proxy.ChatProxy
import com.simiacryptus.skyenet.body.ChatSessionFlexmark
import com.simiacryptus.skyenet.body.PersistentSessionBase
import com.simiacryptus.skyenet.body.SkyenetMacroChat
import com.simiacryptus.util.JsonUtil
import java.awt.Desktop
Expand Down Expand Up @@ -60,6 +61,7 @@ class SoftwareProjectGenerator(
override fun processMessage(
sessionId: String,
userMessage: String,
session: PersistentSessionBase,
sessionUI: SessionUI,
sendUpdate: (String, Boolean) -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.simiacryptus.skyenet
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.proxy.ChatProxy
import com.simiacryptus.skyenet.body.ChatSessionFlexmark
import com.simiacryptus.skyenet.body.PersistentSessionBase
import com.simiacryptus.skyenet.body.SkyenetMacroChat
import com.simiacryptus.util.describe.Description
import java.awt.Desktop
Expand Down Expand Up @@ -79,6 +80,7 @@ class StoryGenerator(
override fun processMessage(
sessionId: String,
userMessage: String,
session: PersistentSessionBase,
sessionUI: SessionUI,
sendUpdate: (String, Boolean) -> Unit
) {
Expand Down

0 comments on commit a72345a

Please sign in to comment.