From 3b6a307dcc904f7f88ce4c5a5ea6e6a2130a2ade Mon Sep 17 00:00:00 2001 From: Andrew Charneski Date: Tue, 21 Nov 2023 23:15:03 -0500 Subject: [PATCH] reorg --- .../skyenet/{ => core}/OutputInterceptor.java | 222 ++++----- .../simiacryptus/skyenet/{ => core}/Brain.kt | 430 +++++++++--------- .../simiacryptus/skyenet/{ => core}/Ears.kt | 4 +- .../simiacryptus/skyenet/{ => core}/Heart.kt | 78 ++-- .../simiacryptus/skyenet/{ => core}/Mouth.kt | 2 +- .../skyenet/{ => core}/actors/ActorSystem.kt | 16 +- .../skyenet/{ => core}/actors/BaseActor.kt | 8 +- .../skyenet/{ => core}/actors/CodingActor.kt | 20 +- .../skyenet/{ => core}/actors/ParsedActor.kt | 2 +- .../{ => core}/actors/ParsedResponse.kt | 2 +- .../skyenet/{ => core}/actors/SimpleActor.kt | 2 +- .../actors/opt/ActorOptimization.kt | 6 +- .../{ => core}/actors/opt/Expectation.kt | 2 +- .../actors/record/CodingActorInterceptor.kt | 8 +- .../actors/record/ParsedActorInterceptor.kt | 8 +- .../actors/record/SimpleActorInterceptor.kt | 6 +- .../{ => core}/actors/test/ActorTestBase.kt | 6 +- .../actors/test/CodingActorTestBase.kt | 10 +- .../actors/test/ParsedActorTestBase.kt | 8 +- .../platform/ApplicationServices.kt | 2 +- .../platform/AuthenticationManager.kt | 4 +- .../platform/AuthorizationManager.kt | 2 +- .../{ => core}/platform/ClientManager.kt | 2 +- .../{ => core}/platform/DataStorage.kt | 2 +- .../skyenet/{ => core}/platform/Session.kt | 4 +- .../{ => core}/platform/UsageManager.kt | 2 +- .../skyenet/{ => core}/platform/User.kt | 2 +- .../platform/UserSettingsManager.kt | 6 +- .../skyenet/{ => core}/util/AwsUtil.kt | 2 +- .../{ => core}/util/FunctionWrapper.kt | 2 +- .../skyenet/{ => core}/util/HeartTestBase.kt | 4 +- .../{ => core}/util/LoggingInterceptor.kt | 2 +- .../skyenet/{ => core}/DataStorageTest.kt | 4 +- .../OutputInterceptorThreadedTest.java | 104 ++--- .../skyenet/core/actors}/ActorOptTest.kt | 7 +- .../{heart => groovy}/GroovyInterpreter.kt | 86 ++-- .../{ => groovy}/GroovyInterpreterTest.kt | 5 +- java/build.gradle.kts | 153 ------- .../{heart => kotlin}/KotlinInterpreter.kt | 4 +- .../{ => kotlin}/KotlinInterpreterTest.kt | 4 +- .../ScalaLocalInterpreter.scala | 6 +- .../ScalaLocalInterpreterTest.scala | 27 +- settings.gradle.kts | 1 - skyenet.svg | 10 +- .../application/ApplicationDirectory.kt | 19 +- .../application/ApplicationInterface.kt | 4 +- .../application/ApplicationServer.kt | 25 +- .../application/ApplicationSocketManager.kt | 11 +- .../skyenet/{ => webui}/chat/ChatServer.kt | 14 +- .../skyenet/{ => webui}/chat/ChatSocket.kt | 4 +- .../{ => webui}/chat/ChatSocketManager.kt | 12 +- .../{ => webui}/chat/CodeChatServer.kt | 12 +- .../{ => webui}/servlet/AppInfoServlet.kt | 2 +- .../servlet/AuthenticatedWebsite.kt | 10 +- .../skyenet/{ => webui}/servlet/CorsFilter.kt | 2 +- .../{ => webui}/servlet/FileServlet.kt | 12 +- .../{ => webui}/servlet/NewSessionServlet.kt | 4 +- .../{ => webui}/servlet/ProxyHttpServlet.kt | 2 +- .../{ => webui}/servlet/SessionListServlet.kt | 10 +- .../servlet/SessionSettingsServlet.kt | 10 +- .../{ => webui}/servlet/UsageServlet.kt | 8 +- .../{ => webui}/servlet/UserInfoServlet.kt | 8 +- .../servlet/UserSettingsServlet.kt | 8 +- .../{ => webui}/servlet/WelcomeServlet.kt | 14 +- .../skyenet/{ => webui}/servlet/ZipServlet.kt | 10 +- .../{ => webui}/session/SessionMessage.kt | 4 +- .../{ => webui}/session/SocketManager.kt | 4 +- .../{ => webui}/session/SocketManagerBase.kt | 10 +- .../{ => webui}/test/CodingActorTestApp.kt | 17 +- .../{ => webui}/test/ParsedActorTestApp.kt | 16 +- .../{ => webui}/test/SimpleActorTestApp.kt | 16 +- .../{ => webui}/util/ClasspathResource.kt | 2 +- .../{ => webui}/util/EmbeddingVisualizer.kt | 10 +- .../skyenet/{ => webui}/util/MarkdownUtil.kt | 2 +- .../{ => webui}/util/MutableSessionHandler.kt | 6 +- webui/src/main/resources/codeChat/favicon.svg | 2 +- .../main/resources/simpleSession/favicon.svg | 2 +- webui/src/main/resources/welcome/favicon.svg | 2 +- .../skyenet/{ => webui}/ActorTestAppServer.kt | 33 +- 79 files changed, 732 insertions(+), 882 deletions(-) rename core/src/main/java/com/simiacryptus/skyenet/{ => core}/OutputInterceptor.java (96%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/Brain.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/Ears.kt (99%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/Heart.kt (94%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/Mouth.kt (98%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/ActorSystem.kt (65%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/BaseActor.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/CodingActor.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/ParsedActor.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/ParsedResponse.kt (79%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/SimpleActor.kt (94%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/opt/ActorOptimization.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/opt/Expectation.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/record/CodingActorInterceptor.kt (93%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/record/ParsedActorInterceptor.kt (89%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/record/SimpleActorInterceptor.kt (88%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/test/ActorTestBase.kt (89%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/test/CodingActorTestBase.kt (65%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/actors/test/ParsedActorTestBase.kt (68%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/ApplicationServices.kt (96%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/AuthenticationManager.kt (86%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/AuthorizationManager.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/ClientManager.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/DataStorage.kt (99%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/Session.kt (53%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/UsageManager.kt (99%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/User.kt (93%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/platform/UserSettingsManager.kt (83%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/util/AwsUtil.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/util/FunctionWrapper.kt (98%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/util/HeartTestBase.kt (97%) rename core/src/main/kotlin/com/simiacryptus/skyenet/{ => core}/util/LoggingInterceptor.kt (98%) rename core/src/test/java/com/simiacryptus/skyenet/{ => core}/DataStorageTest.kt (91%) rename core/src/test/java/com/simiacryptus/skyenet/{ => core}/OutputInterceptorThreadedTest.java (95%) rename {webui/src/test/kotlin/com/simiacryptus/skyenet => core/src/test/java/com/simiacryptus/skyenet/core/actors}/ActorOptTest.kt (92%) rename groovy/src/main/kotlin/com/simiacryptus/skyenet/{heart => groovy}/GroovyInterpreter.kt (89%) rename groovy/src/test/kotlin/com/simiacryptus/skyenet/{ => groovy}/GroovyInterpreterTest.kt (56%) delete mode 100644 java/build.gradle.kts rename kotlin/src/main/kotlin/com/simiacryptus/skyenet/{heart => kotlin}/KotlinInterpreter.kt (99%) rename kotlin/src/test/kotlin/com/simiacryptus/skyenet/{ => kotlin}/KotlinInterpreterTest.kt (90%) rename scala/src/main/scala/com/simiacryptus/skyenet/{heart => scala}/ScalaLocalInterpreter.scala (97%) rename scala/src/test/scala/com/simiacryptus/skyenet/{heart => scala}/ScalaLocalInterpreterTest.scala (51%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/application/ApplicationDirectory.kt (89%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/application/ApplicationInterface.kt (83%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/application/ApplicationServer.kt (86%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/application/ApplicationSocketManager.kt (87%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/chat/ChatServer.kt (84%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/chat/ChatSocket.kt (90%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/chat/ChatSocketManager.kt (91%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/chat/CodeChatServer.kt (86%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/AppInfoServlet.kt (93%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/AuthenticatedWebsite.kt (94%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/CorsFilter.kt (95%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/FileServlet.kt (93%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/NewSessionServlet.kt (81%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/ProxyHttpServlet.kt (98%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/SessionListServlet.kt (85%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/SessionSettingsServlet.kt (88%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/UsageServlet.kt (93%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/UserInfoServlet.kt (72%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/UserSettingsServlet.kt (88%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/WelcomeServlet.kt (88%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/servlet/ZipServlet.kt (84%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/session/SessionMessage.kt (64%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/session/SocketManager.kt (66%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/session/SocketManagerBase.kt (95%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/test/CodingActorTestApp.kt (75%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/test/ParsedActorTestApp.kt (72%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/test/SimpleActorTestApp.kt (74%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/util/ClasspathResource.kt (98%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/util/EmbeddingVisualizer.kt (91%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/util/MarkdownUtil.kt (94%) rename webui/src/main/kotlin/com/simiacryptus/skyenet/{ => webui}/util/MutableSessionHandler.kt (87%) rename webui/src/test/kotlin/com/simiacryptus/skyenet/{ => webui}/ActorTestAppServer.kt (65%) diff --git a/core/src/main/java/com/simiacryptus/skyenet/OutputInterceptor.java b/core/src/main/java/com/simiacryptus/skyenet/core/OutputInterceptor.java similarity index 96% rename from core/src/main/java/com/simiacryptus/skyenet/OutputInterceptor.java rename to core/src/main/java/com/simiacryptus/skyenet/core/OutputInterceptor.java index 6fe7ef38..1dac9ad2 100644 --- a/core/src/main/java/com/simiacryptus/skyenet/OutputInterceptor.java +++ b/core/src/main/java/com/simiacryptus/skyenet/core/OutputInterceptor.java @@ -1,111 +1,111 @@ -package com.simiacryptus.skyenet; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.Map; -import java.util.WeakHashMap; -import java.util.concurrent.atomic.AtomicBoolean; - -public class OutputInterceptor { - - private OutputInterceptor() { - // Prevent instantiation of the utility class - } - - private static final PrintStream originalOut = System.out; - private static final PrintStream originalErr = System.err; - private static final AtomicBoolean isSetup = new AtomicBoolean(false); - private static final Object globalStreamLock = new Object(); - - public static void setupInterceptor() { - if (isSetup.getAndSet(true)) return; - System.setOut(new PrintStream(new OutputStreamRouter(originalOut))); - System.setErr(new PrintStream(new OutputStreamRouter(originalErr))); - } - - private static final ByteArrayOutputStream globalStream = new ByteArrayOutputStream(); - - private static final Map threadLocalBuffer = new WeakHashMap<>(); - - private static ByteArrayOutputStream getThreadOutputStream() { - Thread currentThread = Thread.currentThread(); - ByteArrayOutputStream outputStream; - synchronized (threadLocalBuffer) { - if ((outputStream = threadLocalBuffer.get(currentThread)) != null) return outputStream; - outputStream = new ByteArrayOutputStream(); - threadLocalBuffer.put(currentThread, outputStream); - } - return outputStream; - } - - public static String getThreadOutput() { - ByteArrayOutputStream outputStream = getThreadOutputStream(); - try { - outputStream.flush(); - } catch (IOException e) { - throw new RuntimeException(e); - } - return outputStream.toString(); - } - - public static void clearThreadOutput() { - getThreadOutputStream().reset(); - } - - public static String getGlobalOutput() { - synchronized (globalStreamLock) { - return globalStream.toString(); - } - } - - public static void clearGlobalOutput() { - synchronized (globalStreamLock) { - globalStream.reset(); - } - } - - private static class OutputStreamRouter extends ByteArrayOutputStream { - private final PrintStream originalStream; - int maxGlobalBuffer = 8 * 1024 * 1024; - int maxThreadBuffer = 1024 * 1024; - - public OutputStreamRouter(PrintStream originalStream) { - this.originalStream = originalStream; - } - - @Override - public void write(int b) { - originalStream.write(b); - synchronized (globalStreamLock) { - if (globalStream.size() > maxGlobalBuffer) { - globalStream.reset(); - } - globalStream.write(b); - } - ByteArrayOutputStream threadOutputStream = getThreadOutputStream(); - if (threadOutputStream.size() > maxThreadBuffer) { - threadOutputStream.reset(); - } - threadOutputStream.write(b); - } - - @Override - public void write(byte[] b, int off, int len) { - originalStream.write(b, off, len); - synchronized (globalStreamLock) { - if (globalStream.size() > maxGlobalBuffer) { - globalStream.reset(); - } - globalStream.write(b, off, len); - } - ByteArrayOutputStream threadOutputStream = getThreadOutputStream(); - if (threadOutputStream.size() > maxThreadBuffer) { - threadOutputStream.reset(); - } - threadOutputStream.write(b, off, len); - } - } -} - - +package com.simiacryptus.skyenet.core; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Map; +import java.util.WeakHashMap; +import java.util.concurrent.atomic.AtomicBoolean; + +public class OutputInterceptor { + + private OutputInterceptor() { + // Prevent instantiation of the utility class + } + + private static final PrintStream originalOut = System.out; + private static final PrintStream originalErr = System.err; + private static final AtomicBoolean isSetup = new AtomicBoolean(false); + private static final Object globalStreamLock = new Object(); + + public static void setupInterceptor() { + if (isSetup.getAndSet(true)) return; + System.setOut(new PrintStream(new OutputStreamRouter(originalOut))); + System.setErr(new PrintStream(new OutputStreamRouter(originalErr))); + } + + private static final ByteArrayOutputStream globalStream = new ByteArrayOutputStream(); + + private static final Map threadLocalBuffer = new WeakHashMap<>(); + + private static ByteArrayOutputStream getThreadOutputStream() { + Thread currentThread = Thread.currentThread(); + ByteArrayOutputStream outputStream; + synchronized (threadLocalBuffer) { + if ((outputStream = threadLocalBuffer.get(currentThread)) != null) return outputStream; + outputStream = new ByteArrayOutputStream(); + threadLocalBuffer.put(currentThread, outputStream); + } + return outputStream; + } + + public static String getThreadOutput() { + ByteArrayOutputStream outputStream = getThreadOutputStream(); + try { + outputStream.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } + return outputStream.toString(); + } + + public static void clearThreadOutput() { + getThreadOutputStream().reset(); + } + + public static String getGlobalOutput() { + synchronized (globalStreamLock) { + return globalStream.toString(); + } + } + + public static void clearGlobalOutput() { + synchronized (globalStreamLock) { + globalStream.reset(); + } + } + + private static class OutputStreamRouter extends ByteArrayOutputStream { + private final PrintStream originalStream; + int maxGlobalBuffer = 8 * 1024 * 1024; + int maxThreadBuffer = 1024 * 1024; + + public OutputStreamRouter(PrintStream originalStream) { + this.originalStream = originalStream; + } + + @Override + public void write(int b) { + originalStream.write(b); + synchronized (globalStreamLock) { + if (globalStream.size() > maxGlobalBuffer) { + globalStream.reset(); + } + globalStream.write(b); + } + ByteArrayOutputStream threadOutputStream = getThreadOutputStream(); + if (threadOutputStream.size() > maxThreadBuffer) { + threadOutputStream.reset(); + } + threadOutputStream.write(b); + } + + @Override + public void write(byte[] b, int off, int len) { + originalStream.write(b, off, len); + synchronized (globalStreamLock) { + if (globalStream.size() > maxGlobalBuffer) { + globalStream.reset(); + } + globalStream.write(b, off, len); + } + ByteArrayOutputStream threadOutputStream = getThreadOutputStream(); + if (threadOutputStream.size() > maxThreadBuffer) { + threadOutputStream.reset(); + } + threadOutputStream.write(b, off, len); + } + } +} + + diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Brain.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/Brain.kt index 20501709..dcf10300 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Brain.kt @@ -1,216 +1,216 @@ -@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") - -package com.simiacryptus.skyenet - -import com.simiacryptus.jopenai.models.ChatModels -import com.simiacryptus.jopenai.OpenAIClient -import com.simiacryptus.jopenai.ApiModel.* -import com.simiacryptus.jopenai.ClientUtil.toContentList -import com.simiacryptus.jopenai.models.OpenAITextModel -import com.simiacryptus.jopenai.util.JsonUtil.toJson -import com.simiacryptus.jopenai.describe.TypeDescriber -import com.simiacryptus.jopenai.describe.YamlDescriber -import org.intellij.lang.annotations.Language -import java.lang.reflect.Method -import java.lang.reflect.Modifier -import java.util.concurrent.atomic.AtomicInteger - -open class Brain( - val api: OpenAIClient, - val symbols: java.util.Map = java.util.HashMap() as java.util.Map, - val model: OpenAITextModel = ChatModels.GPT35Turbo, - private val verbose: Boolean = false, - val temperature: Double = 0.3, - val describer: TypeDescriber = YamlDescriber(), - val language: String = "Kotlin", - private val moderated: Boolean = true, - private val apiDescription: String = apiDescription(symbols, describer), -) { - private val totalInputLength = AtomicInteger(0) - private val totalOutputLength = AtomicInteger(0) - private val totalApiDescriptionLength: AtomicInteger = AtomicInteger(0) - - open fun implement(vararg prompt: String): String { - if (verbose) log.info("Prompt: \n\t" + prompt.joinToString("\n\t")) - return implement(*(getChatSystemMessages(apiDescription) + - prompt.map { ChatMessage(Role.user, it.toContentList()) }).toTypedArray() - ) - } - - fun implement( - vararg messages: ChatMessage - ): String { - var request = ChatRequest() - request = request.copy(messages = ArrayList(messages.toList())) - totalApiDescriptionLength.addAndGet(apiDescription.length) - return chat(request) - } - - @Language("TEXT") - open fun getChatSystemMessages(apiDescription: String): List = listOf( - ChatMessage( - Role.system, """ - |You will translate natural language instructions into - |an implementation using $language and the script context. - |Use ``` code blocks labeled with $language where appropriate. - |Defined symbols include ${symbols.keySet().joinToString(", ")}. - |The runtime context is described below: - | - |$apiDescription - |""".trimMargin().trim().toContentList() - ) - ) - - fun fixCommand( - previousCode: String, - error: Throwable, - output: String, - vararg promptMessages: ChatMessage - ): Pair>> { - val request = ChatRequest( - messages = ArrayList( - promptMessages.toList() + listOf( - ChatMessage( - Role.assistant, - """ - |```${language.lowercase()} - |${previousCode} - |``` - |""".trimMargin().trim().toContentList() - ), - ChatMessage( - Role.system, - """ - |The previous code failed with the following error: - | - |``` - |${error.message?.trim() ?: ""} - |``` - | - |Output: - |``` - |${output.trim()} - |``` - | - |Correct the code and try again. - |""".trimMargin().trim().toContentList() - ) - )) - ) - totalApiDescriptionLength.addAndGet(apiDescription.length) - val response = chat(request) - val codeBlocks = extractCodeBlocks(response) - return Pair(response, codeBlocks) - } - - private fun chat(_request: ChatRequest): String { - val request = _request.copy(model = model.modelName, temperature = temperature) - val json = toJson(request) - if (moderated) api.moderate(json) - totalInputLength.addAndGet(json.length) - val chatResponse = api.chat(request, model) - var response = chatResponse.choices.first().message?.content.orEmpty() - if (verbose) log.info(response) - totalOutputLength.addAndGet(response.length) - response = response.trim() - return response - } - - companion object { - private val log = org.slf4j.LoggerFactory.getLogger(Brain::class.java) - fun String.indent(indent: String = " ") = this.replace("\n", "\n$indent") - private fun joinYamlList(typeDescriptions: List) = typeDescriptions.joinToString("\n") { - "- " + it.indent() - } - - private fun Method.superMethod(): Method? { - val superMethod = declaringClass.superclasses.flatMap { it.methods.toList() } - .find { it.name == name && it.parameters.size == parameters.size } - return superMethod?.superMethod() ?: superMethod - } - - private val Class.superclasses: List> - get() { - val superclass = superclass - val supers = if (superclass == null) listOf() - else superclass.superclasses + listOf(superclass) - return (interfaces.toList() + supers).distinct() - } - - fun apiDescription(hands: java.util.Map, yamlDescriber: TypeDescriber): String { - val types = ArrayList>() - - val apiobjs = hands.entrySet().map { (name, utilityObj) -> - val clazz = Class.forName(utilityObj.javaClass.typeName) - val methods = clazz.methods - .filter { Modifier.isPublic(it.modifiers) } - .filter { it.declaringClass == clazz } - .filter { !it.isSynthetic } - .map { it.superMethod() ?: it } - .filter { it.declaringClass != Object::class.java } - types.addAll(methods.flatMap { (listOf(it.returnType) + it.parameters.map { it.type }).filter { it != clazz } }) - types.addAll(clazz.declaredClasses.filter { Modifier.isPublic(it.modifiers) }) - """ - |$name: - | operations: - | ${joinYamlList(methods.map { yamlDescriber.describe(it) }).indent().indent()} - |""".trimMargin().trim() - }.toTypedArray() - val typeDescriptions = types - .filter { !it.isPrimitive } - .filter { !it.isSynthetic } - .filter { !it.name.startsWith("java.") } - .filter { !setOf("void").contains(it.name) } - .distinct().map { - """ - |${it.simpleName}: - | ${yamlDescriber.describe(it).indent()} - """.trimMargin().trim() - }.toTypedArray() - return """ - |api_objects: - | ${apiobjs.joinToString("\n").indent()} - |components: - | schemas: - | ${typeDescriptions.joinToString("\n").indent().indent()} - """.trimMargin() - } - - fun extractCodeBlocks(response: String): List> { - val codeBlockRegex = Regex("(?s)```(.*?)\\n(.*?)```") - val languageRegex = Regex("([a-zA-Z0-9-_]+)") - - val result = mutableListOf>() - var startIndex = 0 - - val matches = codeBlockRegex.findAll(response) - if (matches.count() == 0) return listOf(Pair("text", response)) - for (match in matches) { - // Add non-code block before the current match as "text" - if (startIndex < match.range.first) { - result.add(Pair("text", response.substring(startIndex, match.range.first))) - } - - // Extract language and code - val languageMatch = languageRegex.find(match.groupValues[1]) - val language = languageMatch?.groupValues?.get(0) ?: "code" - val code = match.groupValues[2] - - // Add code block to the result - result.add(Pair(language, code)) - - // Update the start index - startIndex = match.range.last + 1 - } - - // Add any remaining non-code text after the last code block as "text" - if (startIndex < response.length) { - result.add(Pair("text", response.substring(startIndex))) - } - - return result - } - - } - +@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") + +package com.simiacryptus.skyenet.core + +import com.simiacryptus.jopenai.ApiModel.* +import com.simiacryptus.jopenai.ClientUtil.toContentList +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.jopenai.describe.TypeDescriber +import com.simiacryptus.jopenai.describe.YamlDescriber +import com.simiacryptus.jopenai.models.ChatModels +import com.simiacryptus.jopenai.models.OpenAITextModel +import com.simiacryptus.jopenai.util.JsonUtil.toJson +import org.intellij.lang.annotations.Language +import java.lang.reflect.Method +import java.lang.reflect.Modifier +import java.util.concurrent.atomic.AtomicInteger + +open class Brain( + val api: OpenAIClient, + val symbols: java.util.Map = java.util.HashMap() as java.util.Map, + val model: OpenAITextModel = ChatModels.GPT35Turbo, + private val verbose: Boolean = false, + val temperature: Double = 0.3, + val describer: TypeDescriber = YamlDescriber(), + val language: String = "Kotlin", + private val moderated: Boolean = true, + private val apiDescription: String = apiDescription(symbols, describer), +) { + private val totalInputLength = AtomicInteger(0) + private val totalOutputLength = AtomicInteger(0) + private val totalApiDescriptionLength: AtomicInteger = AtomicInteger(0) + + open fun implement(vararg prompt: String): String { + if (verbose) log.info("Prompt: \n\t" + prompt.joinToString("\n\t")) + return implement(*(getChatSystemMessages(apiDescription) + + prompt.map { ChatMessage(Role.user, it.toContentList()) }).toTypedArray() + ) + } + + fun implement( + vararg messages: ChatMessage + ): String { + var request = ChatRequest() + request = request.copy(messages = ArrayList(messages.toList())) + totalApiDescriptionLength.addAndGet(apiDescription.length) + return chat(request) + } + + @Language("TEXT") + open fun getChatSystemMessages(apiDescription: String): List = listOf( + ChatMessage( + Role.system, """ + |You will translate natural language instructions into + |an implementation using $language and the script context. + |Use ``` code blocks labeled with $language where appropriate. + |Defined symbols include ${symbols.keySet().joinToString(", ")}. + |The runtime context is described below: + | + |$apiDescription + |""".trimMargin().trim().toContentList() + ) + ) + + fun fixCommand( + previousCode: String, + error: Throwable, + output: String, + vararg promptMessages: ChatMessage + ): Pair>> { + val request = ChatRequest( + messages = ArrayList( + promptMessages.toList() + listOf( + ChatMessage( + Role.assistant, + """ + |```${language.lowercase()} + |${previousCode} + |``` + |""".trimMargin().trim().toContentList() + ), + ChatMessage( + Role.system, + """ + |The previous code failed with the following error: + | + |``` + |${error.message?.trim() ?: ""} + |``` + | + |Output: + |``` + |${output.trim()} + |``` + | + |Correct the code and try again. + |""".trimMargin().trim().toContentList() + ) + )) + ) + totalApiDescriptionLength.addAndGet(apiDescription.length) + val response = chat(request) + val codeBlocks = extractCodeBlocks(response) + return Pair(response, codeBlocks) + } + + private fun chat(_request: ChatRequest): String { + val request = _request.copy(model = model.modelName, temperature = temperature) + val json = toJson(request) + if (moderated) api.moderate(json) + totalInputLength.addAndGet(json.length) + val chatResponse = api.chat(request, model) + var response = chatResponse.choices.first().message?.content.orEmpty() + if (verbose) log.info(response) + totalOutputLength.addAndGet(response.length) + response = response.trim() + return response + } + + companion object { + private val log = org.slf4j.LoggerFactory.getLogger(Brain::class.java) + fun String.indent(indent: String = " ") = this.replace("\n", "\n$indent") + private fun joinYamlList(typeDescriptions: List) = typeDescriptions.joinToString("\n") { + "- " + it.indent() + } + + private fun Method.superMethod(): Method? { + val superMethod = declaringClass.superclasses.flatMap { it.methods.toList() } + .find { it.name == name && it.parameters.size == parameters.size } + return superMethod?.superMethod() ?: superMethod + } + + private val Class.superclasses: List> + get() { + val superclass = superclass + val supers = if (superclass == null) listOf() + else superclass.superclasses + listOf(superclass) + return (interfaces.toList() + supers).distinct() + } + + fun apiDescription(hands: java.util.Map, yamlDescriber: TypeDescriber): String { + val types = ArrayList>() + + val apiobjs = hands.entrySet().map { (name, utilityObj) -> + val clazz = Class.forName(utilityObj.javaClass.typeName) + val methods = clazz.methods + .filter { Modifier.isPublic(it.modifiers) } + .filter { it.declaringClass == clazz } + .filter { !it.isSynthetic } + .map { it.superMethod() ?: it } + .filter { it.declaringClass != Object::class.java } + types.addAll(methods.flatMap { (listOf(it.returnType) + it.parameters.map { it.type }).filter { it != clazz } }) + types.addAll(clazz.declaredClasses.filter { Modifier.isPublic(it.modifiers) }) + """ + |$name: + | operations: + | ${joinYamlList(methods.map { yamlDescriber.describe(it) }).indent().indent()} + |""".trimMargin().trim() + }.toTypedArray() + val typeDescriptions = types + .filter { !it.isPrimitive } + .filter { !it.isSynthetic } + .filter { !it.name.startsWith("java.") } + .filter { !setOf("void").contains(it.name) } + .distinct().map { + """ + |${it.simpleName}: + | ${yamlDescriber.describe(it).indent()} + """.trimMargin().trim() + }.toTypedArray() + return """ + |api_objects: + | ${apiobjs.joinToString("\n").indent()} + |components: + | schemas: + | ${typeDescriptions.joinToString("\n").indent().indent()} + """.trimMargin() + } + + fun extractCodeBlocks(response: String): List> { + val codeBlockRegex = Regex("(?s)```(.*?)\\n(.*?)```") + val languageRegex = Regex("([a-zA-Z0-9-_]+)") + + val result = mutableListOf>() + var startIndex = 0 + + val matches = codeBlockRegex.findAll(response) + if (matches.count() == 0) return listOf(Pair("text", response)) + for (match in matches) { + // Add non-code block before the current match as "text" + if (startIndex < match.range.first) { + result.add(Pair("text", response.substring(startIndex, match.range.first))) + } + + // Extract language and code + val languageMatch = languageRegex.find(match.groupValues[1]) + val language = languageMatch?.groupValues?.get(0) ?: "code" + val code = match.groupValues[2] + + // Add code block to the result + result.add(Pair(language, code)) + + // Update the start index + startIndex = match.range.last + 1 + } + + // Add any remaining non-code text after the last code block as "text" + if (startIndex < response.length) { + result.add(Pair("text", response.substring(startIndex))) + } + + return result + } + + } + } \ No newline at end of file diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/Ears.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Ears.kt similarity index 99% rename from core/src/main/kotlin/com/simiacryptus/skyenet/Ears.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/Ears.kt index 5dd9f096..680b455b 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/Ears.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Ears.kt @@ -1,10 +1,10 @@ -package com.simiacryptus.skyenet +package com.simiacryptus.skyenet.core import com.simiacryptus.jopenai.OpenAIClient -import com.simiacryptus.jopenai.proxy.ChatProxy import com.simiacryptus.jopenai.audio.AudioRecorder import com.simiacryptus.jopenai.audio.LookbackLoudnessWindowBuffer import com.simiacryptus.jopenai.audio.TranscriptionProcessor +import com.simiacryptus.jopenai.proxy.ChatProxy import org.slf4j.LoggerFactory import java.util.* import java.util.concurrent.ConcurrentLinkedDeque diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/Heart.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Heart.kt similarity index 94% rename from core/src/main/kotlin/com/simiacryptus/skyenet/Heart.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/Heart.kt index 21713d03..68877dc4 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/Heart.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Heart.kt @@ -1,40 +1,40 @@ -package com.simiacryptus.skyenet - -interface Heart { - - fun getLanguage(): String - fun run(code: String): Any? - fun validate(code: String): Throwable? - - fun wrapCode(code: String): String = code - fun wrapExecution(fn: java.util.function.Supplier): T? = fn.get() - - companion object { - private class TestObject { - @Suppress("unused") - fun square(x: Int): Int = x * x - } - private interface TestInterface { - fun square(x: Int): Int - } - @JvmStatic - fun test(factory: java.util.function.Function, Heart>) { - val testImpl = object : TestInterface { - override fun square(x: Int): Int = x * x - } - with(factory.apply(mapOf("message" to "hello"))) { - test("hello", run("message")) - } - with(factory.apply(mapOf("function" to TestObject()))) { - test(25, run("function.square(5)")) - } - with(factory.apply(mapOf("function" to testImpl))) { - test(25, run("function.square(5)")) - } - } - - private fun test(expected: T, actual: T?) { - require(expected == actual) { actual.toString() } - } - } +package com.simiacryptus.skyenet.core + +interface Heart { + + fun getLanguage(): String + fun run(code: String): Any? + fun validate(code: String): Throwable? + + fun wrapCode(code: String): String = code + fun wrapExecution(fn: java.util.function.Supplier): T? = fn.get() + + companion object { + private class TestObject { + @Suppress("unused") + fun square(x: Int): Int = x * x + } + private interface TestInterface { + fun square(x: Int): Int + } + @JvmStatic + fun test(factory: java.util.function.Function, Heart>) { + val testImpl = object : TestInterface { + override fun square(x: Int): Int = x * x + } + with(factory.apply(mapOf("message" to "hello"))) { + test("hello", run("message")) + } + with(factory.apply(mapOf("function" to TestObject()))) { + test(25, run("function.square(5)")) + } + with(factory.apply(mapOf("function" to testImpl))) { + test(25, run("function.square(5)")) + } + } + + private fun test(expected: T, actual: T?) { + require(expected == actual) { actual.toString() } + } + } } \ No newline at end of file diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/Mouth.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Mouth.kt similarity index 98% rename from core/src/main/kotlin/com/simiacryptus/skyenet/Mouth.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/Mouth.kt index 4218ea99..e1b9d6d9 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/Mouth.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/Mouth.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet +package com.simiacryptus.skyenet.core import com.google.auth.oauth2.GoogleCredentials import com.google.cloud.texttospeech.v1.* diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ActorSystem.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ActorSystem.kt similarity index 65% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/ActorSystem.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ActorSystem.kt index 18de29fa..6bd1a647 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ActorSystem.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ActorSystem.kt @@ -1,11 +1,13 @@ -package com.simiacryptus.skyenet.actors +package com.simiacryptus.skyenet.core.actors -import com.simiacryptus.skyenet.actors.record.* -import com.simiacryptus.skyenet.platform.DataStorage -import com.simiacryptus.skyenet.platform.Session -import com.simiacryptus.skyenet.platform.User -import com.simiacryptus.skyenet.util.FunctionWrapper -import com.simiacryptus.skyenet.util.JsonFunctionRecorder +import com.simiacryptus.skyenet.core.actors.record.CodingActorInterceptor +import com.simiacryptus.skyenet.core.actors.record.ParsedActorInterceptor +import com.simiacryptus.skyenet.core.actors.record.SimpleActorInterceptor +import com.simiacryptus.skyenet.core.platform.DataStorage +import com.simiacryptus.skyenet.core.platform.Session +import com.simiacryptus.skyenet.core.platform.User +import com.simiacryptus.skyenet.core.util.FunctionWrapper +import com.simiacryptus.skyenet.core.util.JsonFunctionRecorder import java.io.File open class ActorSystem>( diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/BaseActor.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/BaseActor.kt index cc78414b..c3785710 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/BaseActor.kt @@ -1,10 +1,10 @@ -package com.simiacryptus.skyenet.actors +package com.simiacryptus.skyenet.core.actors import com.simiacryptus.jopenai.API -import com.simiacryptus.jopenai.models.OpenAIModel -import com.simiacryptus.jopenai.models.ChatModels -import com.simiacryptus.jopenai.OpenAIClient import com.simiacryptus.jopenai.ClientUtil.toContentList +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.jopenai.models.ChatModels +import com.simiacryptus.jopenai.models.OpenAIModel import com.simiacryptus.jopenai.models.OpenAITextModel abstract class BaseActor( diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/CodingActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/CodingActor.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/CodingActor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/CodingActor.kt index bcf43cb2..943cbff0 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/CodingActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/CodingActor.kt @@ -1,17 +1,17 @@ -package com.simiacryptus.skyenet.actors +package com.simiacryptus.skyenet.core.actors import com.fasterxml.jackson.annotation.JsonIgnore import com.simiacryptus.jopenai.API -import com.simiacryptus.jopenai.OpenAIClient import com.simiacryptus.jopenai.ClientUtil.toContentList -import com.simiacryptus.jopenai.models.ChatModels -import com.simiacryptus.jopenai.models.OpenAITextModel -import com.simiacryptus.skyenet.Brain -import com.simiacryptus.skyenet.Brain.Companion.indent -import com.simiacryptus.skyenet.Heart -import com.simiacryptus.skyenet.OutputInterceptor +import com.simiacryptus.jopenai.OpenAIClient import com.simiacryptus.jopenai.describe.AbbrevWhitelistYamlDescriber import com.simiacryptus.jopenai.describe.TypeDescriber +import com.simiacryptus.jopenai.models.ChatModels +import com.simiacryptus.jopenai.models.OpenAITextModel +import com.simiacryptus.skyenet.core.Brain +import com.simiacryptus.skyenet.core.Brain.Companion.indent +import com.simiacryptus.skyenet.core.Heart +import com.simiacryptus.skyenet.core.OutputInterceptor import kotlin.reflect.KClass @Suppress("unused", "MemberVisibilityCanBePrivate") @@ -126,9 +126,9 @@ open class CodingActor( private fun fix( api: OpenAIClient, messages: Array, - result: CodingActor.CodeResultImpl, + result: CodeResultImpl, ex: Throwable - ): CodingActor.CodeResultImpl { + ): CodeResultImpl { val respondWithCode = brain(api, model).fixCommand(result.getCode(), ex, "", *messages) val renderedResponse = getRenderedResponse(respondWithCode.second) val codedInstruction = getCode(interpreter.getLanguage(), respondWithCode.second) diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ParsedActor.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedActor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ParsedActor.kt index 2f2eda40..85449fb9 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ParsedActor.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.actors +package com.simiacryptus.skyenet.core.actors import com.simiacryptus.jopenai.API import com.simiacryptus.jopenai.OpenAIClient diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedResponse.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ParsedResponse.kt similarity index 79% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedResponse.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ParsedResponse.kt index fb19ebc8..a3eef2ae 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedResponse.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/ParsedResponse.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.actors +package com.simiacryptus.skyenet.core.actors abstract class ParsedResponse(val clazz: Class) { abstract fun getText(): String diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/SimpleActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/SimpleActor.kt similarity index 94% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/SimpleActor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/SimpleActor.kt index 58397e67..cb4b786e 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/SimpleActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/SimpleActor.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.actors +package com.simiacryptus.skyenet.core.actors import com.simiacryptus.jopenai.API import com.simiacryptus.jopenai.models.ChatModels diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/ActorOptimization.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/opt/ActorOptimization.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/ActorOptimization.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/opt/ActorOptimization.kt index 4a1cb1bf..da515d3b 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/ActorOptimization.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/opt/ActorOptimization.kt @@ -1,12 +1,12 @@ -package com.simiacryptus.skyenet.actors.opt +package com.simiacryptus.skyenet.core.actors.opt import com.simiacryptus.jopenai.OpenAIClient import com.simiacryptus.jopenai.describe.Description import com.simiacryptus.jopenai.models.ChatModels import com.simiacryptus.jopenai.models.OpenAITextModel import com.simiacryptus.jopenai.proxy.ChatProxy -import com.simiacryptus.skyenet.actors.BaseActor -import com.simiacryptus.skyenet.actors.opt.ActorOptimization.GeneticApi.Prompt +import com.simiacryptus.skyenet.core.actors.BaseActor +import com.simiacryptus.skyenet.core.actors.opt.ActorOptimization.GeneticApi.Prompt import org.slf4j.LoggerFactory import kotlin.math.ceil import kotlin.math.ln diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/Expectation.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/opt/Expectation.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/Expectation.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/opt/Expectation.kt index 92b98ae9..655f039d 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/Expectation.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/opt/Expectation.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.actors.opt +package com.simiacryptus.skyenet.core.actors.opt import com.simiacryptus.jopenai.OpenAIClient import com.simiacryptus.jopenai.models.EmbeddingModels diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/CodingActorInterceptor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/CodingActorInterceptor.kt similarity index 93% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/CodingActorInterceptor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/CodingActorInterceptor.kt index 9b23a7e1..975f83e2 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/CodingActorInterceptor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/CodingActorInterceptor.kt @@ -1,11 +1,11 @@ -package com.simiacryptus.skyenet.actors.record +package com.simiacryptus.skyenet.core.actors.record import com.simiacryptus.jopenai.API import com.simiacryptus.jopenai.OpenAIClient import com.simiacryptus.jopenai.models.OpenAIModel -import com.simiacryptus.skyenet.actors.CodeResult -import com.simiacryptus.skyenet.actors.CodingActor -import com.simiacryptus.skyenet.util.FunctionWrapper +import com.simiacryptus.skyenet.core.actors.CodeResult +import com.simiacryptus.skyenet.core.actors.CodingActor +import com.simiacryptus.skyenet.core.util.FunctionWrapper class CodingActorInterceptor( val inner: CodingActor, diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/ParsedActorInterceptor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/ParsedActorInterceptor.kt similarity index 89% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/ParsedActorInterceptor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/ParsedActorInterceptor.kt index 1c46efbf..004f223a 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/ParsedActorInterceptor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/ParsedActorInterceptor.kt @@ -1,10 +1,10 @@ -package com.simiacryptus.skyenet.actors.record +package com.simiacryptus.skyenet.core.actors.record import com.simiacryptus.jopenai.API import com.simiacryptus.jopenai.models.OpenAIModel -import com.simiacryptus.skyenet.actors.ParsedActor -import com.simiacryptus.skyenet.actors.ParsedResponse -import com.simiacryptus.skyenet.util.FunctionWrapper +import com.simiacryptus.skyenet.core.actors.ParsedActor +import com.simiacryptus.skyenet.core.actors.ParsedResponse +import com.simiacryptus.skyenet.core.util.FunctionWrapper class ParsedActorInterceptor( val inner: ParsedActor, diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/SimpleActorInterceptor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/SimpleActorInterceptor.kt similarity index 88% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/SimpleActorInterceptor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/SimpleActorInterceptor.kt index 707fca29..dca8af85 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/SimpleActorInterceptor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/record/SimpleActorInterceptor.kt @@ -1,9 +1,9 @@ -package com.simiacryptus.skyenet.actors.record +package com.simiacryptus.skyenet.core.actors.record import com.simiacryptus.jopenai.API import com.simiacryptus.jopenai.models.OpenAIModel -import com.simiacryptus.skyenet.actors.SimpleActor -import com.simiacryptus.skyenet.util.FunctionWrapper +import com.simiacryptus.skyenet.core.actors.SimpleActor +import com.simiacryptus.skyenet.core.util.FunctionWrapper class SimpleActorInterceptor( val inner: SimpleActor, diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ActorTestBase.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/ActorTestBase.kt similarity index 89% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ActorTestBase.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/ActorTestBase.kt index dd88b4a8..d1182000 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ActorTestBase.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/ActorTestBase.kt @@ -1,8 +1,8 @@ -package com.simiacryptus.skyenet.actors.test +package com.simiacryptus.skyenet.core.actors.test import com.simiacryptus.jopenai.OpenAIClient -import com.simiacryptus.skyenet.actors.BaseActor -import com.simiacryptus.skyenet.actors.opt.ActorOptimization +import com.simiacryptus.skyenet.core.actors.BaseActor +import com.simiacryptus.skyenet.core.actors.opt.ActorOptimization import org.slf4j.LoggerFactory import org.slf4j.event.Level diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/CodingActorTestBase.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/CodingActorTestBase.kt similarity index 65% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/CodingActorTestBase.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/CodingActorTestBase.kt index 33392132..41c6cdba 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/CodingActorTestBase.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/CodingActorTestBase.kt @@ -1,9 +1,9 @@ -package com.simiacryptus.skyenet.actors.test +package com.simiacryptus.skyenet.core.actors.test -import com.simiacryptus.skyenet.Heart -import com.simiacryptus.skyenet.actors.BaseActor -import com.simiacryptus.skyenet.actors.CodeResult -import com.simiacryptus.skyenet.actors.CodingActor +import com.simiacryptus.skyenet.core.Heart +import com.simiacryptus.skyenet.core.actors.BaseActor +import com.simiacryptus.skyenet.core.actors.CodeResult +import com.simiacryptus.skyenet.core.actors.CodingActor import kotlin.reflect.KClass abstract class CodingActorTestBase : ActorTestBase() { diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ParsedActorTestBase.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/ParsedActorTestBase.kt similarity index 68% rename from core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ParsedActorTestBase.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/ParsedActorTestBase.kt index f271fd7d..a6ed1558 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ParsedActorTestBase.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/actors/test/ParsedActorTestBase.kt @@ -1,8 +1,8 @@ -package com.simiacryptus.skyenet.actors.test +package com.simiacryptus.skyenet.core.actors.test -import com.simiacryptus.skyenet.actors.BaseActor -import com.simiacryptus.skyenet.actors.ParsedActor -import com.simiacryptus.skyenet.actors.ParsedResponse +import com.simiacryptus.skyenet.core.actors.BaseActor +import com.simiacryptus.skyenet.core.actors.ParsedActor +import com.simiacryptus.skyenet.core.actors.ParsedResponse import java.util.function.Function abstract class ParsedActorTestBase( diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ApplicationServices.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/ApplicationServices.kt similarity index 96% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/ApplicationServices.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/ApplicationServices.kt index 156dffde..7fdd863d 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ApplicationServices.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/ApplicationServices.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform import java.io.File diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/AuthenticationManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/AuthenticationManager.kt similarity index 86% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/AuthenticationManager.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/AuthenticationManager.kt index 7c3df51f..6ff7b109 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/AuthenticationManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/AuthenticationManager.kt @@ -1,6 +1,4 @@ -package com.simiacryptus.skyenet.platform - -import java.util.HashMap +package com.simiacryptus.skyenet.core.platform open class AuthenticationManager { diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/AuthorizationManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/AuthorizationManager.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/AuthorizationManager.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/AuthorizationManager.kt index a89723e8..0e5d8b58 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/AuthorizationManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/AuthorizationManager.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform import java.util.* diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/ClientManager.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/ClientManager.kt index 77b686dc..398fdb41 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/ClientManager.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform import com.simiacryptus.jopenai.ApiModel import com.simiacryptus.jopenai.ClientUtil diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/DataStorage.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/DataStorage.kt similarity index 99% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/DataStorage.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/DataStorage.kt index d8f31357..3dfe7dd1 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/DataStorage.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/DataStorage.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform import com.simiacryptus.jopenai.util.JsonUtil import java.io.File diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/Session.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/Session.kt similarity index 53% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/Session.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/Session.kt index 871f7645..ec2e1bce 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/Session.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/Session.kt @@ -1,6 +1,6 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform -import com.simiacryptus.skyenet.platform.DataStorage.Companion.validateSessionId +import com.simiacryptus.skyenet.core.platform.DataStorage.Companion.validateSessionId data class Session( internal val sessionId: String diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UsageManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/UsageManager.kt similarity index 99% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/UsageManager.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/UsageManager.kt index a193c468..a51147f2 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UsageManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/UsageManager.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform import com.simiacryptus.jopenai.models.* import com.simiacryptus.jopenai.util.JsonUtil diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/User.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/User.kt similarity index 93% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/User.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/User.kt index 6959a0ec..a601effe 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/User.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/User.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform import com.fasterxml.jackson.annotation.JsonProperty diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UserSettingsManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/UserSettingsManager.kt similarity index 83% rename from core/src/main/kotlin/com/simiacryptus/skyenet/platform/UserSettingsManager.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/UserSettingsManager.kt index 8b8447fa..47423e07 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UserSettingsManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/platform/UserSettingsManager.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.platform +package com.simiacryptus.skyenet.core.platform import com.simiacryptus.jopenai.util.JsonUtil import java.io.File @@ -15,10 +15,10 @@ open class UserSettingsManager { return userSettings.getOrPut(user) { val file = File(userConfigDirectory, "$user.json") if (file.exists()) { - Companion.log.info("Loading user settings for $user from $file") + log.info("Loading user settings for $user from $file") JsonUtil.fromJson(file.readText(), UserSettings::class.java) } else { - Companion.log.info("Creating new user settings for $user at $file") + log.info("Creating new user settings for $user at $file") UserSettings() } } diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/util/AwsUtil.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/AwsUtil.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/util/AwsUtil.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/util/AwsUtil.kt index 1e068cdc..67c5505a 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/util/AwsUtil.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/AwsUtil.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.util +package com.simiacryptus.skyenet.core.util import com.amazonaws.services.kms.AWSKMSClientBuilder import com.amazonaws.services.kms.model.DecryptRequest diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/util/FunctionWrapper.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/FunctionWrapper.kt similarity index 98% rename from core/src/main/kotlin/com/simiacryptus/skyenet/util/FunctionWrapper.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/util/FunctionWrapper.kt index 09bbb361..ba0d3c3c 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/util/FunctionWrapper.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/FunctionWrapper.kt @@ -1,6 +1,6 @@ @file:Suppress("unused") -package com.simiacryptus.skyenet.util +package com.simiacryptus.skyenet.core.util import com.simiacryptus.jopenai.util.JsonUtil import java.io.Closeable diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/util/HeartTestBase.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/HeartTestBase.kt similarity index 97% rename from core/src/main/kotlin/com/simiacryptus/skyenet/util/HeartTestBase.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/util/HeartTestBase.kt index a0a4209c..9c5cf44d 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/util/HeartTestBase.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/HeartTestBase.kt @@ -1,6 +1,6 @@ -package com.simiacryptus.skyenet.util +package com.simiacryptus.skyenet.core.util -import com.simiacryptus.skyenet.Heart +import com.simiacryptus.skyenet.core.Heart import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/util/LoggingInterceptor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/LoggingInterceptor.kt similarity index 98% rename from core/src/main/kotlin/com/simiacryptus/skyenet/util/LoggingInterceptor.kt rename to core/src/main/kotlin/com/simiacryptus/skyenet/core/util/LoggingInterceptor.kt index f7bd634e..37310c00 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/util/LoggingInterceptor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/core/util/LoggingInterceptor.kt @@ -1,4 +1,4 @@ -package com.simiacryptus.skyenet.util +package com.simiacryptus.skyenet.core.util import ch.qos.logback.classic.Logger import ch.qos.logback.classic.LoggerContext diff --git a/core/src/test/java/com/simiacryptus/skyenet/DataStorageTest.kt b/core/src/test/java/com/simiacryptus/skyenet/core/DataStorageTest.kt similarity index 91% rename from core/src/test/java/com/simiacryptus/skyenet/DataStorageTest.kt rename to core/src/test/java/com/simiacryptus/skyenet/core/DataStorageTest.kt index 3e663e4e..b9e2d228 100644 --- a/core/src/test/java/com/simiacryptus/skyenet/DataStorageTest.kt +++ b/core/src/test/java/com/simiacryptus/skyenet/core/DataStorageTest.kt @@ -1,6 +1,6 @@ -package com.simiacryptus.skyenet +package com.simiacryptus.skyenet.core -import com.simiacryptus.skyenet.platform.DataStorage +import com.simiacryptus.skyenet.core.platform.DataStorage import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue diff --git a/core/src/test/java/com/simiacryptus/skyenet/OutputInterceptorThreadedTest.java b/core/src/test/java/com/simiacryptus/skyenet/core/OutputInterceptorThreadedTest.java similarity index 95% rename from core/src/test/java/com/simiacryptus/skyenet/OutputInterceptorThreadedTest.java rename to core/src/test/java/com/simiacryptus/skyenet/core/OutputInterceptorThreadedTest.java index 2ae5bd5d..85e451cc 100644 --- a/core/src/test/java/com/simiacryptus/skyenet/OutputInterceptorThreadedTest.java +++ b/core/src/test/java/com/simiacryptus/skyenet/core/OutputInterceptorThreadedTest.java @@ -1,52 +1,52 @@ -package com.simiacryptus.skyenet; - -import org.junit.jupiter.api.Test; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class OutputInterceptorThreadedTest { - - @Test - public void testThreadedInterceptor() throws InterruptedException { - OutputInterceptor.setupInterceptor(); - AtomicInteger successCounter = new AtomicInteger(0); - ExecutorService executorService = Executors.newFixedThreadPool(5); - Object lock = new Object(); - Runnable task = () -> { - OutputInterceptor.clearThreadOutput(); - String threadName = Thread.currentThread().getName(); - System.out.println("Thread: " + threadName + " output"); - System.err.println("Thread: " + threadName + " error"); - try { - Thread.sleep(1); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - String expectedOutput = ("Thread: " + threadName + " output\nThread: " + threadName + " error\n").trim(); - String threadOutput = OutputInterceptor.getThreadOutput().replace("\r", "").trim(); - if (threadOutput.trim().equals(expectedOutput.trim())) { - successCounter.incrementAndGet(); - } else { - synchronized (lock) { - System.out.println("Expected:\n " + expectedOutput.replaceAll("\n", "\n ")); - System.out.println("Actual:\n " + threadOutput.replaceAll("\n", "\n ")); - System.out.flush(); - } - } - }; - - for (int i = 0; i < 10; i++) { - executorService.submit(task); - } - - executorService.shutdown(); - executorService.awaitTermination(10, TimeUnit.SECONDS); - - assertEquals(10, successCounter.get()); - } -} +package com.simiacryptus.skyenet.core; + +import org.junit.jupiter.api.Test; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class OutputInterceptorThreadedTest { + + @Test + public void testThreadedInterceptor() throws InterruptedException { + OutputInterceptor.setupInterceptor(); + AtomicInteger successCounter = new AtomicInteger(0); + ExecutorService executorService = Executors.newFixedThreadPool(5); + Object lock = new Object(); + Runnable task = () -> { + OutputInterceptor.clearThreadOutput(); + String threadName = Thread.currentThread().getName(); + System.out.println("Thread: " + threadName + " output"); + System.err.println("Thread: " + threadName + " error"); + try { + Thread.sleep(1); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + String expectedOutput = ("Thread: " + threadName + " output\nThread: " + threadName + " error\n").trim(); + String threadOutput = OutputInterceptor.getThreadOutput().replace("\r", "").trim(); + if (threadOutput.trim().equals(expectedOutput.trim())) { + successCounter.incrementAndGet(); + } else { + synchronized (lock) { + System.out.println("Expected:\n " + expectedOutput.replaceAll("\n", "\n ")); + System.out.println("Actual:\n " + threadOutput.replaceAll("\n", "\n ")); + System.out.flush(); + } + } + }; + + for (int i = 0; i < 10; i++) { + executorService.submit(task); + } + + executorService.shutdown(); + executorService.awaitTermination(10, TimeUnit.SECONDS); + + assertEquals(10, successCounter.get()); + } +} diff --git a/webui/src/test/kotlin/com/simiacryptus/skyenet/ActorOptTest.kt b/core/src/test/java/com/simiacryptus/skyenet/core/actors/ActorOptTest.kt similarity index 92% rename from webui/src/test/kotlin/com/simiacryptus/skyenet/ActorOptTest.kt rename to core/src/test/java/com/simiacryptus/skyenet/core/actors/ActorOptTest.kt index c1db7071..81dc424d 100644 --- a/webui/src/test/kotlin/com/simiacryptus/skyenet/ActorOptTest.kt +++ b/core/src/test/java/com/simiacryptus/skyenet/core/actors/ActorOptTest.kt @@ -1,9 +1,8 @@ -package com.simiacryptus.skyenet +package com.simiacryptus.skyenet.core.actors import com.simiacryptus.jopenai.OpenAIClient -import com.simiacryptus.skyenet.actors.SimpleActor -import com.simiacryptus.skyenet.actors.opt.ActorOptimization -import com.simiacryptus.skyenet.actors.opt.Expectation +import com.simiacryptus.skyenet.core.actors.opt.ActorOptimization +import com.simiacryptus.skyenet.core.actors.opt.Expectation import org.slf4j.LoggerFactory import org.slf4j.event.Level import kotlin.system.exitProcess diff --git a/groovy/src/main/kotlin/com/simiacryptus/skyenet/heart/GroovyInterpreter.kt b/groovy/src/main/kotlin/com/simiacryptus/skyenet/groovy/GroovyInterpreter.kt similarity index 89% rename from groovy/src/main/kotlin/com/simiacryptus/skyenet/heart/GroovyInterpreter.kt rename to groovy/src/main/kotlin/com/simiacryptus/skyenet/groovy/GroovyInterpreter.kt index 9e51d5f2..1b897667 100644 --- a/groovy/src/main/kotlin/com/simiacryptus/skyenet/heart/GroovyInterpreter.kt +++ b/groovy/src/main/kotlin/com/simiacryptus/skyenet/groovy/GroovyInterpreter.kt @@ -1,43 +1,43 @@ -package com.simiacryptus.skyenet.heart - -import com.simiacryptus.skyenet.Heart -import groovy.lang.GroovyShell -import groovy.lang.Script -import org.codehaus.groovy.control.CompilationFailedException -import org.codehaus.groovy.control.CompilerConfiguration - -open class GroovyInterpreter(defs: java.util.Map) : Heart { - - private val shell: GroovyShell - - init { - val compilerConfiguration = CompilerConfiguration() - shell = GroovyShell(compilerConfiguration) - defs.forEach { key, value -> - shell.setVariable(key, value) - } - } - - override fun getLanguage(): String { - return "groovy" - } - - - override fun run(code: String): Any? { - val wrapExecution = wrapExecution { - try { - val script: Script = shell.parse(wrapCode(code)) - script.run() - } catch (e: CompilationFailedException) { - throw e - } - } - return wrapExecution - } - - override fun validate(code: String): Exception? { - shell.parse(wrapCode(code)) - return null - } -} - +package com.simiacryptus.skyenet.groovy + +import com.simiacryptus.skyenet.core.Heart +import groovy.lang.GroovyShell +import groovy.lang.Script +import org.codehaus.groovy.control.CompilationFailedException +import org.codehaus.groovy.control.CompilerConfiguration + +open class GroovyInterpreter(defs: java.util.Map) : Heart { + + private val shell: GroovyShell + + init { + val compilerConfiguration = CompilerConfiguration() + shell = GroovyShell(compilerConfiguration) + defs.forEach { key, value -> + shell.setVariable(key, value) + } + } + + override fun getLanguage(): String { + return "groovy" + } + + + override fun run(code: String): Any? { + val wrapExecution = wrapExecution { + try { + val script: Script = shell.parse(wrapCode(code)) + script.run() + } catch (e: CompilationFailedException) { + throw e + } + } + return wrapExecution + } + + override fun validate(code: String): Exception? { + shell.parse(wrapCode(code)) + return null + } +} + diff --git a/groovy/src/test/kotlin/com/simiacryptus/skyenet/GroovyInterpreterTest.kt b/groovy/src/test/kotlin/com/simiacryptus/skyenet/groovy/GroovyInterpreterTest.kt similarity index 56% rename from groovy/src/test/kotlin/com/simiacryptus/skyenet/GroovyInterpreterTest.kt rename to groovy/src/test/kotlin/com/simiacryptus/skyenet/groovy/GroovyInterpreterTest.kt index e394f18f..a2e38cdc 100644 --- a/groovy/src/test/kotlin/com/simiacryptus/skyenet/GroovyInterpreterTest.kt +++ b/groovy/src/test/kotlin/com/simiacryptus/skyenet/groovy/GroovyInterpreterTest.kt @@ -1,9 +1,8 @@ @file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") -package com.simiacryptus.skyenet.heart.test +package com.simiacryptus.skyenet.groovy -import com.simiacryptus.skyenet.util.HeartTestBase -import com.simiacryptus.skyenet.heart.GroovyInterpreter +import com.simiacryptus.skyenet.core.util.HeartTestBase class GroovyInterpreterTest : HeartTestBase() { override fun newInterpreter(map: java.util.Map) = GroovyInterpreter(map) diff --git a/java/build.gradle.kts b/java/build.gradle.kts deleted file mode 100644 index 973244a3..00000000 --- a/java/build.gradle.kts +++ /dev/null @@ -1,153 +0,0 @@ -import org.gradle.api.tasks.testing.logging.TestLogEvent -import java.net.URI - -fun properties(key: String) = project.findProperty(key).toString() -group = properties("libraryGroup") -version = properties("libraryVersion") - -plugins { - java - `java-library` - id("org.jetbrains.kotlin.jvm") version "1.9.20" - `maven-publish` - id("signing") -} - -repositories { - mavenCentral { - metadataSources { - mavenPom() - artifact() - } - } -} - -kotlin { - jvmToolchain(11) -} - -val kotlin_version = "1.9.20" -dependencies { - - implementation(project(":core")) - - implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.7.3") - implementation(kotlin("stdlib-jdk8")) - - implementation(group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version = kotlin_version) - implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.9") - implementation(group = "commons-io", name = "commons-io", version = "2.15.0") - - testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-api", version = "5.10.1") - testRuntimeOnly(group = "org.junit.jupiter", name = "junit-jupiter-engine", version = "5.10.1") - testImplementation(group = "org.jetbrains.kotlin", name = "kotlin-script-runtime", version = kotlin_version) - -} - -tasks { - - compileKotlin { - kotlinOptions { - javaParameters = true - } - } - compileTestKotlin { - kotlinOptions { - javaParameters = true - } - } - test { - useJUnitPlatform() - systemProperty("surefire.useManifestOnlyJar", "false") - testLogging { - events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) - exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL - } - jvmArgs( - "--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED", - "--add-opens", "java.base/java.util=ALL-UNNAMED", - "--add-opens", "java.base/java.lang=ALL-UNNAMED" - ) - } -} - - - -val javadocJar by tasks.registering(Jar::class) { - archiveClassifier.set("javadoc") - from(tasks.javadoc) -} - -val sourcesJar by tasks.registering(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets.main.get().allSource) -} - -publishing { - - publications { - create("mavenJava") { - artifactId = "java" - from(components["java"]) - artifact(sourcesJar.get()) - artifact(javadocJar.get()) - versionMapping { - usage("java-api") { - fromResolutionOf("runtimeClasspath") - } - usage("java-runtime") { - fromResolutionResult() - } - } - pom { - name.set("SkyeNet Java Interpreter") - description.set("A very helpful puppy") - url.set("https://github.com/SimiaCryptus/SkyeNet") - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("acharneski") - name.set("Andrew Charneski") - email.set("acharneski@gmail.com") - } - } - scm { - connection.set("scm:git:git://git@github.com/SimiaCryptus/SkyeNet.git") - developerConnection.set("scm:git:ssh://git@github.com/SimiaCryptus/SkyeNet.git") - url.set("https://github.com/SimiaCryptus/SkyeNet") - } - } - } - } - repositories { - maven { - val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" - val snapshotsRepoUrl = "https://oss.sonatype.org/mask/repositories/snapshots" - url = URI(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl) - credentials { - username = System.getenv("OSSRH_USERNAME") ?: System.getProperty("ossrhUsername") - ?: properties("ossrhUsername") - password = System.getenv("OSSRH_PASSWORD") ?: System.getProperty("ossrhPassword") - ?: properties("ossrhPassword") - } - } - } - if (System.getenv("GPG_PRIVATE_KEY") != null && System.getenv("GPG_PASSPHRASE") != null) afterEvaluate { - signing { - sign(publications["mavenJava"]) - } - } -} - -if (System.getenv("GPG_PRIVATE_KEY") != null && System.getenv("GPG_PASSPHRASE") != null) { - apply() - configure { - useInMemoryPgpKeys(System.getenv("GPG_PRIVATE_KEY"), System.getenv("GPG_PASSPHRASE")) - sign(configurations.archives.get()) - } -} diff --git a/kotlin/src/main/kotlin/com/simiacryptus/skyenet/heart/KotlinInterpreter.kt b/kotlin/src/main/kotlin/com/simiacryptus/skyenet/kotlin/KotlinInterpreter.kt similarity index 99% rename from kotlin/src/main/kotlin/com/simiacryptus/skyenet/heart/KotlinInterpreter.kt rename to kotlin/src/main/kotlin/com/simiacryptus/skyenet/kotlin/KotlinInterpreter.kt index ac634bf5..edd94d26 100644 --- a/kotlin/src/main/kotlin/com/simiacryptus/skyenet/heart/KotlinInterpreter.kt +++ b/kotlin/src/main/kotlin/com/simiacryptus/skyenet/kotlin/KotlinInterpreter.kt @@ -1,8 +1,8 @@ @file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") -package com.simiacryptus.skyenet.heart +package com.simiacryptus.skyenet.kotlin -import com.simiacryptus.skyenet.Heart +import com.simiacryptus.skyenet.core.Heart import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity diff --git a/kotlin/src/test/kotlin/com/simiacryptus/skyenet/KotlinInterpreterTest.kt b/kotlin/src/test/kotlin/com/simiacryptus/skyenet/kotlin/KotlinInterpreterTest.kt similarity index 90% rename from kotlin/src/test/kotlin/com/simiacryptus/skyenet/KotlinInterpreterTest.kt rename to kotlin/src/test/kotlin/com/simiacryptus/skyenet/kotlin/KotlinInterpreterTest.kt index 4f44a3cf..8272e748 100644 --- a/kotlin/src/test/kotlin/com/simiacryptus/skyenet/KotlinInterpreterTest.kt +++ b/kotlin/src/test/kotlin/com/simiacryptus/skyenet/kotlin/KotlinInterpreterTest.kt @@ -1,8 +1,8 @@ @file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") -package com.simiacryptus.skyenet.heart +package com.simiacryptus.skyenet.kotlin -import com.simiacryptus.skyenet.util.HeartTestBase +import com.simiacryptus.skyenet.core.util.HeartTestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import java.util.Map diff --git a/scala/src/main/scala/com/simiacryptus/skyenet/heart/ScalaLocalInterpreter.scala b/scala/src/main/scala/com/simiacryptus/skyenet/scala/ScalaLocalInterpreter.scala similarity index 97% rename from scala/src/main/scala/com/simiacryptus/skyenet/heart/ScalaLocalInterpreter.scala rename to scala/src/main/scala/com/simiacryptus/skyenet/scala/ScalaLocalInterpreter.scala index 2f00613c..535e47a7 100644 --- a/scala/src/main/scala/com/simiacryptus/skyenet/heart/ScalaLocalInterpreter.scala +++ b/scala/src/main/scala/com/simiacryptus/skyenet/scala/ScalaLocalInterpreter.scala @@ -1,7 +1,7 @@ -package com.simiacryptus.skyenet.heart +package com.simiacryptus.skyenet.scala -import com.simiacryptus.skyenet.Heart -import com.simiacryptus.skyenet.heart.ScalaLocalInterpreter.log +import com.simiacryptus.skyenet.core.Heart +import com.simiacryptus.skyenet.scala.ScalaLocalInterpreter.log import java.nio.file.Paths import java.util.function.Supplier diff --git a/scala/src/test/scala/com/simiacryptus/skyenet/heart/ScalaLocalInterpreterTest.scala b/scala/src/test/scala/com/simiacryptus/skyenet/scala/ScalaLocalInterpreterTest.scala similarity index 51% rename from scala/src/test/scala/com/simiacryptus/skyenet/heart/ScalaLocalInterpreterTest.scala rename to scala/src/test/scala/com/simiacryptus/skyenet/scala/ScalaLocalInterpreterTest.scala index f425c2a1..443afb6c 100644 --- a/scala/src/test/scala/com/simiacryptus/skyenet/heart/ScalaLocalInterpreterTest.scala +++ b/scala/src/test/scala/com/simiacryptus/skyenet/scala/ScalaLocalInterpreterTest.scala @@ -1,14 +1,13 @@ -package com.test - -import com.simiacryptus.skyenet.heart.ScalaLocalInterpreter -import com.simiacryptus.skyenet.Heart -import com.simiacryptus.skyenet.util.HeartTestBase - -import java.util - - -class ScalaLocalInterpreterTest extends HeartTestBase { - override def newInterpreter(map: util.Map[String, AnyRef]): Heart = { - new ScalaLocalInterpreter(map) - } -} +package com.simiacryptus.skyenet.scala + +import com.simiacryptus.skyenet.core.Heart +import com.simiacryptus.skyenet.core.util.HeartTestBase + +import java.util + + +class ScalaLocalInterpreterTest extends HeartTestBase { + override def newInterpreter(map: util.Map[String, AnyRef]): Heart = { + new ScalaLocalInterpreter(map) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 4d15adb6..ff8d96db 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,7 +2,6 @@ rootProject.name = "SkyeNet" include("core") include("groovy") -include("java") include("scala") include("kotlin") include("webui") diff --git a/skyenet.svg b/skyenet.svg index c252e0ad..52fa3b90 100644 --- a/skyenet.svg +++ b/skyenet.svg @@ -1,10 +1,10 @@ -