diff --git a/README.md b/README.md index df9f156d..4878e072 100644 --- a/README.md +++ b/README.md @@ -76,18 +76,18 @@ Maven: com.simiacryptus skyenet-webui - 1.0.20 + 1.0.21 ``` 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 diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 41ff14ff..12aef6f7 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -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") diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt index 3f223458..380487ec 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt @@ -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) diff --git a/gradle.properties b/gradle.properties index 7e5d6c12..3287e7db 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/util/build.gradle.kts b/util/build.gradle.kts index 2466eab9..c01dd4e1 100644 --- a/util/build.gradle.kts +++ b/util/build.gradle.kts @@ -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")) diff --git a/webui/build.gradle.kts b/webui/build.gradle.kts index b350096b..814a5144 100644 --- a/webui/build.gradle.kts +++ b/webui/build.gradle.kts @@ -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")) diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/ChatSession.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/ChatSession.kt index 59127a84..73bfb4af 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/ChatSession.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/ChatSession.kt @@ -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 diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/MacroChatSession.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/MacroChatSession.kt new file mode 100644 index 00000000..09a3957c --- /dev/null +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/MacroChatSession.kt @@ -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() + val threads = mutableMapOf() + val regenTriggers = mutableMapOf>() + val linkTriggers = mutableMapOf>() + val txtTriggers = mutableMapOf>() + 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() = """
${SkyenetSessionServerBase.spinner}
""" + override val playButton: String get() = """""" + override val cancelButton: String get() = """""" + override val regenButton: String get() = """""" + + override fun hrefLink(handler: Consumer): String { + val operationID = ChatSession.randomID() + linkTriggers[operationID] = handler + return """""" + } + + override fun textInput(handler: Consumer): String { + val operationID = ChatSession.randomID() + txtTriggers[operationID] = handler + //language=HTML + return """
+ + +
""".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) + } +} \ No newline at end of file diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/PersistentSessionBase.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/PersistentSessionBase.kt index 9360da75..1e057be3 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/PersistentSessionBase.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/PersistentSessionBase.kt @@ -37,7 +37,7 @@ abstract class PersistentSessionBase( override fun getReplay(): List { return messageStates.entries.map { "${it.key},${ - messageVersions.computeIfAbsent(it.key) { AtomicInteger(0) }.get() + messageVersions.computeIfAbsent(it.key) { AtomicInteger(1) }.get() },${it.value}" } } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SessionDataStorage.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SessionDataStorage.kt index f59f4c2d..57b234d2 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SessionDataStorage.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SessionDataStorage.kt @@ -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") @@ -70,12 +71,14 @@ open class SessionDataStorage( open fun listSessions(): List { // 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 { diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetBasicChat.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetBasicChat.kt index f5483af4..b2d15138 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetBasicChat.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetBasicChat.kt @@ -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 } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt index df889d7e..7668f415 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetMacroChat.kt @@ -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( @@ -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() - val threads = mutableMapOf() - val regenTriggers = mutableMapOf>() - val linkTriggers = mutableMapOf>() - val txtTriggers = mutableMapOf>() - 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() = """
${SkyenetSessionServerBase.spinner}
""" - override val playButton: String get() = """""" - override val cancelButton: String get() = """""" - override val regenButton: String get() = """""" - - override fun hrefLink(handler:Consumer): String { - val operationID = ChatSession.randomID() - linkTriggers[operationID] = handler - return """
""" - } - - override fun textInput(handler:Consumer): String { - val operationID = ChatSession.randomID() - txtTriggers[operationID] = handler - //language=HTML - return """
- - -
""".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 } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt index 04c2c1bb..51ea27b3 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/body/SkyenetSessionServerBase.kt @@ -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("
") { - """
+ 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("
") { + """
|${sessionDataStorage.getSessionName(it)} |
""".trimMargin() - } - resp.writer.write( - """ + } + resp.writer.write( + """ | | |Sessions @@ -167,26 +166,32 @@ abstract class SkyenetSessionServerBase( | | """.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)