Skip to content

Commit

Permalink
1.0.21 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski authored Nov 8, 2023
1 parent 40e3df7 commit d87f490
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 115 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.20</version>
<version>1.0.21</version>
</dependency>
```

Gradle:

```groovy
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.20'
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.21'
```

```kotlin
implementation("com.simiacryptus:skyenet:1.0.20")
implementation("com.simiacryptus:skyenet:1.0.21")
```

### 🌟 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.23")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.24")

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

Expand Down
1 change: 0 additions & 1 deletion core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ open class Brain(

private fun run(request: ChatRequest): String {
request.model = model.modelName
request.max_tokens = model.maxTokens
request.temperature = temperature
val json = toJson(request)
if (moderated) api.moderate(json)
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.20
libraryVersion = 1.0.21
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
2 changes: 1 addition & 1 deletion util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val logback_version = "1.2.12"

dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.23")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.24")

implementation(project(":core"))
implementation(project(":webui"))
Expand Down
2 changes: 1 addition & 1 deletion webui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ val jetty_version = "11.0.17"
val jackson_version = "2.15.2"
dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.23")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.24")

implementation(project(":core"))
testImplementation(project(":groovy"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ abstract class ChatSession(
get() {
val chatRequest = OpenAIClient.ChatRequest()
chatRequest.model = model.modelName
chatRequest.max_tokens = model.maxTokens
chatRequest.temperature = parent.temperature
chatRequest.messages = messages.toTypedArray()
return chatRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.simiacryptus.skyenet.body

import java.util.concurrent.Semaphore
import java.util.function.Consumer

class MacroChatSession(
val parent : SkyenetMacroChat,
sessionId: String,
sessionDataStorage: SessionDataStorage = parent.sessionDataStorage
) : PersistentSessionBase(
sessionId = sessionId,
sessionDataStorage = 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 sessionDiv = newSessionDiv(operationID, SkyenetSessionServerBase.spinner)
val thread = Thread {
playSempaphores[operationID] = Semaphore(0)
try {
parent.processMessage(sessionId, userMessage, session, object :
SkyenetMacroChat.SessionUI {
override val spinner: String get() = """<div>${SkyenetSessionServerBase.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 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()
}

}, sessionDiv)
} catch (e: Throwable) {
e.printStackTrace()
} finally {
}
}
threads[operationID] = thread
thread.start()
}

override fun onCmd(id: String, code: String) {
if(code=="run") {
playSempaphores[id]?.release()
}
if(code=="cancel") {
threads[id]?.interrupt()
}
if(code=="regen") {
regenTriggers[id]?.accept(Unit)
}
if(code.startsWith("link")) {
linkTriggers[id]?.accept(Unit)
}
if(code.startsWith("userTxt,")) {
txtTriggers[id]?.accept(code.substring("userTxt,".length))
}
super.onCmd(id, code)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class PersistentSessionBase(
override fun getReplay(): List<String> {
return messageStates.entries.map {
"${it.key},${
messageVersions.computeIfAbsent(it.key) { AtomicInteger(0) }.get()
messageVersions.computeIfAbsent(it.key) { AtomicInteger(1) }.get()
},${it.value}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ open class SessionDataStorage(

return messages
}

protected open fun getOperationDir(sessionId: String): File {
val sessionDir = getSessionInstanceDir(sessionId)
val operationDir = File(sessionDir, "operations")
Expand All @@ -70,12 +71,14 @@ open class SessionDataStorage(
open fun listSessions(): List<String> {
// For all sessions, return the session id
// Filter out sessions which have no operations
return dataDir.listFiles()?.filter { sessionDir ->
val operationDir = File(sessionDir, "operations")
operationDir.exists() && operationDir.listFiles()?.isNotEmpty() ?: false
}?.map { sessionDir ->
sessionDir.name
} ?: listOf()
val files = dataDir.listFiles()?.flatMap { it.listFiles().toList() }?.filter { sessionDir ->
val operationDir = File(sessionDir, "messages")
if (!operationDir.exists()) false else {
val listFiles = operationDir.listFiles()
(listFiles?.size ?: 0) > 2
}
}
return files?.map { it.parentFile.name + "-" + it.name } ?: listOf()
}

open fun getSessionName(sessionId: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ open class SkyenetBasicChat(
get() = OpenAIClient()

override fun newSession(sessionId: String): SessionInterface {
val handler = MutableSessionHandler(null)
val basicChatSession = BasicChatSession(
parent = this@SkyenetBasicChat,
model = model,
sessionId = sessionId
)
val handler = MutableSessionHandler(null)
handler.setDelegate(basicChatSession)
return handler
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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

abstract class SkyenetMacroChat(
Expand All @@ -28,75 +27,7 @@ abstract class SkyenetMacroChat(

override fun newSession(sessionId: String): SessionInterface {
val handler = MutableSessionHandler(null)

val basicChatSession = object : PersistentSessionBase(
sessionId = sessionId,
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 sessionDiv = newSessionDiv(operationID, SkyenetSessionServerBase.spinner)
val thread = Thread {
playSempaphores[operationID] = Semaphore(0)
try {
processMessage(sessionId, userMessage, session, object : SessionUI {
override val spinner: String get() = """<div>${SkyenetSessionServerBase.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 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()
}

}, sessionDiv)
} catch (e: Throwable) {
e.printStackTrace()
} finally {
}
}
threads[operationID] = thread
thread.start()
}

override fun onCmd(id: String, code: String) {
if(code=="run") {
playSempaphores[id]?.release()
}
if(code=="cancel") {
threads[id]?.interrupt()
}
if(code=="regen") {
regenTriggers[id]?.accept(Unit)
}
if(code.startsWith("link")) {
linkTriggers[id]?.accept(Unit)
}
if(code.startsWith("userTxt,")) {
txtTriggers[id]?.accept(code.substring("userTxt,".length))
}
super.onCmd(id, code)
}
}
handler.setDelegate(basicChatSession)
handler.setDelegate(MacroChatSession(this,sessionId))
return handler
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,18 @@ abstract class SkyenetSessionServerBase(
}
})

protected open val sessionList = ServletHolder(
"sessionList",
object : HttpServlet() {
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
resp.contentType = "text/html"
resp.status = HttpServletResponse.SC_OK
val links = sessionDataStorage.listSessions().joinToString("<br/>") {
"""<a href="javascript:void(0)" onclick="window.location.href='/#$it';window.location.reload();">
inner class SessionServlet : HttpServlet() {
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
resp.contentType = "text/html"
resp.status = HttpServletResponse.SC_OK
val sessions = sessionDataStorage.listSessions()
val links = sessions.joinToString("<br/>") {
"""<a href="javascript:void(0)" onclick="window.location.href='#$it';window.location.reload();">
|${sessionDataStorage.getSessionName(it)}
|</a><br/>""".trimMargin()
}
resp.writer.write(
"""
}
resp.writer.write(
"""
|<html>
|<head>
|<title>Sessions</title>
Expand All @@ -167,26 +166,32 @@ abstract class SkyenetSessionServerBase(
|</body>
|</html>
""".trimMargin()
)
}
}
protected open val sessionList = ServletHolder(
"sessionList",
SessionServlet()
)


inner class AppInfoServlet : HttpServlet() {
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
resp.contentType = "text/json"
resp.status = HttpServletResponse.SC_OK
resp.writer.write(
JsonUtil.objectMapper().writeValueAsString(
mapOf(
"applicationName" to applicationName
)
)
}
})


)
}
}
protected open val appInfo = ServletHolder(
"appInfo",
object : HttpServlet() {
override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
resp.contentType = "text/json"
resp.status = HttpServletResponse.SC_OK
resp.writer.write(
JsonUtil.objectMapper().writeValueAsString(
mapOf(
"applicationName" to applicationName
)
)
)
}
})
AppInfoServlet()
)

companion object {
val logger = org.slf4j.LoggerFactory.getLogger(SkyenetSessionServerBase::class.java)
Expand Down

0 comments on commit d87f490

Please sign in to comment.