diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 653536d1..97fb7303 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -31,7 +31,7 @@ val logback_version = "1.4.11" dependencies { - implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.33") + implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.34") implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.9") implementation(group = "commons-io", name = "commons-io", version = "2.15.0") diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt index 0e026ef4..20501709 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt @@ -2,14 +2,14 @@ package com.simiacryptus.skyenet -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.OpenAIClient.* -import com.simiacryptus.openai.OpenAIClientBase.Companion.toContentList -import com.simiacryptus.openai.models.OpenAITextModel -import com.simiacryptus.util.JsonUtil.toJson -import com.simiacryptus.util.describe.TypeDescriber -import com.simiacryptus.util.describe.YamlDescriber +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 diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/Ears.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/Ears.kt index 6b671950..5dd9f096 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/Ears.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/Ears.kt @@ -1,10 +1,10 @@ package com.simiacryptus.skyenet -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.proxy.ChatProxy -import com.simiacryptus.util.audio.AudioRecorder -import com.simiacryptus.util.audio.LookbackLoudnessWindowBuffer -import com.simiacryptus.util.audio.TranscriptionProcessor +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 org.slf4j.LoggerFactory import java.util.* import java.util.concurrent.ConcurrentLinkedDeque diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt index 6eb601cd..cc78414b 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt @@ -1,11 +1,11 @@ package com.simiacryptus.skyenet.actors -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.models.OpenAIModel -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.OpenAIClientBase.Companion.toContentList -import com.simiacryptus.openai.models.OpenAITextModel +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.models.OpenAITextModel abstract class BaseActor( open val prompt: String, @@ -13,25 +13,25 @@ abstract class BaseActor( val model: OpenAITextModel = ChatModels.GPT35Turbo, val temperature: Double = 0.3, ) { - abstract fun answer(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI): T - open fun response(vararg messages: OpenAIClient.ChatMessage, model: OpenAIModel = this.model, api: OpenAIAPI) = (api as OpenAIClient).chat( - OpenAIClient.ChatRequest( + abstract fun answer(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API): T + open fun response(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, model: OpenAIModel = this.model, api: API) = (api as OpenAIClient).chat( + com.simiacryptus.jopenai.ApiModel.ChatRequest( messages = ArrayList(messages.toList()), temperature = temperature, model = this.model.modelName, ), model = this.model ) - open fun answer(vararg questions: String, api: OpenAIAPI): T = answer(*chatMessages(*questions), api = api) + open fun answer(vararg questions: String, api: API): T = answer(*chatMessages(*questions), api = api) open fun chatMessages(vararg questions: String) = arrayOf( - OpenAIClient.ChatMessage( - role = OpenAIClient.Role.system, + com.simiacryptus.jopenai.ApiModel.ChatMessage( + role = com.simiacryptus.jopenai.ApiModel.Role.system, content = prompt.toContentList() ), ) + questions.map { - OpenAIClient.ChatMessage( - role = OpenAIClient.Role.user, + com.simiacryptus.jopenai.ApiModel.ChatMessage( + role = com.simiacryptus.jopenai.ApiModel.Role.user, content = it.toContentList() ) } diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/CodingActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/CodingActor.kt index f8b8e1bf..bcf43cb2 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/CodingActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/CodingActor.kt @@ -1,17 +1,17 @@ package com.simiacryptus.skyenet.actors import com.fasterxml.jackson.annotation.JsonIgnore -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.OpenAIClientBase.Companion.toContentList -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.models.OpenAITextModel +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.util.describe.AbbrevWhitelistYamlDescriber -import com.simiacryptus.util.describe.TypeDescriber +import com.simiacryptus.jopenai.describe.AbbrevWhitelistYamlDescriber +import com.simiacryptus.jopenai.describe.TypeDescriber import kotlin.reflect.KClass @Suppress("unused", "MemberVisibilityCanBePrivate") @@ -67,31 +67,31 @@ open class CodingActor( open val interpreter by lazy { interpreterClass.java.getConstructor(Map::class.java).newInstance(symbols) } - override fun answer(vararg questions: String, api: OpenAIAPI): CodeResult = + override fun answer(vararg questions: String, api: API): CodeResult = if (!autoEvaluate) answer(*chatMessages(*questions), api = api) else answerWithAutoEval(*chatMessages(*questions), api = api).first - override fun answer(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI): CodeResult = + override fun answer(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API): CodeResult = if (!autoEvaluate) CodeResultImpl(*messages, api = (api as OpenAIClient)) else answerWithAutoEval(*messages, api = api).first open fun answerWithPrefix( codePrefix: String, - vararg messages: OpenAIClient.ChatMessage, - api: OpenAIAPI + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, + api: API ): CodeResult = if (!autoEvaluate) CodeResultImpl(*injectCodePrefix(messages, codePrefix), api = (api as OpenAIClient)) else answerWithAutoEval(*injectCodePrefix(messages, codePrefix), api = api).first open fun answerWithAutoEval( vararg messages: String, - api: OpenAIAPI, + api: API, codePrefix: String = "" ) = answerWithAutoEval(*injectCodePrefix(chatMessages(*messages), codePrefix), api = api) open fun answerWithAutoEval( - vararg messages: OpenAIClient.ChatMessage, - api: OpenAIAPI + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, + api: API ): Pair { var result = CodeResultImpl(*messages, api = (api as OpenAIClient)) var lastError: Throwable? = null @@ -117,15 +117,15 @@ open class CodingActor( } private fun injectCodePrefix( - messages: Array, + messages: Array, codePrefix: String ) = (messages.dropLast(1) + if (codePrefix.isBlank()) listOf() else listOf( - OpenAIClient.ChatMessage(OpenAIClient.Role.assistant, codePrefix.toContentList()) + com.simiacryptus.jopenai.ApiModel.ChatMessage(com.simiacryptus.jopenai.ApiModel.Role.assistant, codePrefix.toContentList()) ) + messages.last()).toTypedArray() private fun fix( api: OpenAIClient, - messages: Array, + messages: Array, result: CodingActor.CodeResultImpl, ex: Throwable ): CodingActor.CodeResultImpl { @@ -147,7 +147,7 @@ open class CodingActor( ) private inner class CodeResultImpl( - vararg messages: OpenAIClient.ChatMessage, + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, codePrefix: String = "", api: OpenAIClient, ) : CodeResult { @@ -175,7 +175,7 @@ open class CodingActor( fun implement( brain: Brain, - vararg messages: OpenAIClient.ChatMessage, + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, codePrefix: String = "", ): String { val response = brain.implement(*messages) @@ -194,7 +194,7 @@ open class CodingActor( brain: Brain, codePrefix: String, initialCode: String, - messages: Array + messages: Array ): String? { var workingCode = initialCode for (fixAttempt in 0..fixIterations) { diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedActor.kt index 1ac6097b..2f2eda40 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/ParsedActor.kt @@ -1,10 +1,10 @@ package com.simiacryptus.skyenet.actors -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.models.OpenAITextModel -import com.simiacryptus.openai.proxy.ChatProxy +import com.simiacryptus.jopenai.API +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.jopenai.models.ChatModels +import com.simiacryptus.jopenai.models.OpenAITextModel +import com.simiacryptus.jopenai.proxy.ChatProxy import java.util.function.Function open class ParsedActor( @@ -21,7 +21,7 @@ open class ParsedActor( ) { val resultClass: Class by lazy { parserClass.getMethod("apply", String::class.java).returnType as Class } - private inner class ParsedResponseImpl(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI) : ParsedResponse(resultClass) { + private inner class ParsedResponseImpl(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API) : ParsedResponse(resultClass) { private val parser: Function = ChatProxy( clazz = parserClass, api = (api as OpenAIClient), @@ -34,7 +34,7 @@ open class ParsedActor( override fun getObj(clazz: Class): T = _obj } - override fun answer(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI): ParsedResponse { + override fun answer(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API): ParsedResponse { return ParsedResponseImpl(*messages, api = api) } } diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/SimpleActor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/SimpleActor.kt index 825143a4..58397e67 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/SimpleActor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/SimpleActor.kt @@ -1,9 +1,8 @@ package com.simiacryptus.skyenet.actors -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.models.OpenAITextModel +import com.simiacryptus.jopenai.API +import com.simiacryptus.jopenai.models.ChatModels +import com.simiacryptus.jopenai.models.OpenAITextModel open class SimpleActor( prompt: String, @@ -17,7 +16,7 @@ open class SimpleActor( temperature = temperature, ) { - override fun answer(vararg questions: String, api: OpenAIAPI): String = answer(*chatMessages(*questions), api = api) + override fun answer(vararg questions: String, api: API): String = answer(*chatMessages(*questions), api = api) - override fun answer(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI): String = response(*messages, api = api).choices.first().message?.content ?: throw RuntimeException("No response") + override fun answer(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API): String = response(*messages, api = api).choices.first().message?.content ?: throw RuntimeException("No response") } diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/ActorOptimization.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/ActorOptimization.kt index 49eb36aa..4a1cb1bf 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/ActorOptimization.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/ActorOptimization.kt @@ -1,13 +1,12 @@ package com.simiacryptus.skyenet.actors.opt -import com.simiacryptus.openai.models.OpenAIModel -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.OpenAITextModel -import com.simiacryptus.skyenet.actors.opt.ActorOptimization.GeneticApi.Prompt -import com.simiacryptus.openai.proxy.ChatProxy +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.util.describe.Description +import com.simiacryptus.skyenet.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/actors/opt/Expectation.kt index 6e4e6ef6..92b98ae9 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/Expectation.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/opt/Expectation.kt @@ -1,9 +1,8 @@ package com.simiacryptus.skyenet.actors.opt -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.EmbeddingModels -import com.simiacryptus.openai.opt.DistanceType +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.jopenai.models.EmbeddingModels +import com.simiacryptus.jopenai.opt.DistanceType import org.slf4j.LoggerFactory abstract class Expectation { @@ -30,7 +29,7 @@ abstract class Expectation { } private fun createEmbedding(api: OpenAIClient, str: String) = api.createEmbedding( - OpenAIClient.EmbeddingRequest( + com.simiacryptus.jopenai.ApiModel.EmbeddingRequest( model = EmbeddingModels.AdaEmbedding.modelName, input = str ) ).data.first().embedding!! diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/CodingActorInterceptor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/CodingActorInterceptor.kt index ea52e26d..9b23a7e1 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/CodingActorInterceptor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/CodingActorInterceptor.kt @@ -1,8 +1,8 @@ package com.simiacryptus.skyenet.actors.record -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.OpenAIModel +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 @@ -21,15 +21,15 @@ class CodingActorInterceptor( temperature = inner.temperature, autoEvaluate = inner.autoEvaluate, ) { - override fun answer(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI): CodeResult { + override fun answer(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API): CodeResult { return functionInterceptor.wrap(messages.toList().toTypedArray()) { - messages: Array -> + messages: Array -> CodingResultInterceptor(*messages, api = (api as OpenAIClient), inner = inner.answer(*messages, api = api)) } } private inner class CodingResultInterceptor( - vararg messages: OpenAIClient.ChatMessage, + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, private val inner: CodeResult, api: OpenAIClient, ) : CodeResult { @@ -40,11 +40,11 @@ class CodingActorInterceptor( } override fun response( - vararg messages: OpenAIClient.ChatMessage, + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, model: OpenAIModel, - api: OpenAIAPI + api: API ) = functionInterceptor.wrap(messages.toList().toTypedArray(), model) { - messages: Array, + messages: Array, model: OpenAIModel -> inner.response(*messages, model = model, api = api) } @@ -53,23 +53,23 @@ class CodingActorInterceptor( inner.chatMessages(*it) } - override fun answer(vararg questions: String, api: OpenAIAPI) = functionInterceptor.wrap(questions) { + override fun answer(vararg questions: String, api: API) = functionInterceptor.wrap(questions) { inner.answer(*it, api = api) } override fun answerWithPrefix( codePrefix: String, - vararg messages: OpenAIClient.ChatMessage, - api: OpenAIAPI + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, + api: API ) = functionInterceptor.wrap(messages.toList().toTypedArray(), codePrefix) { - messages: Array, + messages: Array, codePrefix: String -> inner.answerWithPrefix(codePrefix, *messages, api = api) } override fun answerWithAutoEval( vararg messages: String, - api: OpenAIAPI, + api: API, codePrefix: String ) = functionInterceptor.wrap(messages.toList().toTypedArray(), codePrefix) { messages: Array, @@ -78,8 +78,8 @@ class CodingActorInterceptor( } override fun answerWithAutoEval( - vararg messages: OpenAIClient.ChatMessage, - api: OpenAIAPI + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, + api: API ) = functionInterceptor.wrap(messages.toList().toTypedArray()) { inner.answerWithAutoEval(*messages, api = api) } diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/ParsedActorInterceptor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/ParsedActorInterceptor.kt index d3619907..1c46efbf 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/ParsedActorInterceptor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/ParsedActorInterceptor.kt @@ -1,8 +1,7 @@ package com.simiacryptus.skyenet.actors.record -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.OpenAIModel +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 @@ -17,30 +16,30 @@ class ParsedActorInterceptor( model = inner.model, temperature = inner.temperature, ) { - private inner class ParsedResponseInterceptor(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI, private val inner: ParsedResponse) : + private inner class ParsedResponseInterceptor(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API, private val inner: ParsedResponse) : ParsedResponse(this@ParsedActorInterceptor.inner.resultClass) { override fun getText() = functionInterceptor.wrap { inner.getText() } override fun getObj(clazz: Class) = functionInterceptor.intercept(clazz) { inner.getObj(clazz) } // <-- Cannot use 'T' as reified type parameter. Use a class instead. } - override fun answer(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI): ParsedResponse { + override fun answer(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API): ParsedResponse { return functionInterceptor.wrap(messages.toList().toTypedArray()) { - messages: Array -> + messages: Array -> ParsedResponseInterceptor(*messages, api = api, inner = inner.answer(*messages, api = api)) } } override fun response( - vararg messages: OpenAIClient.ChatMessage, + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, model: OpenAIModel, - api: OpenAIAPI + api: API ) = functionInterceptor.wrap(messages.toList().toTypedArray(), model) { - messages: Array, + messages: Array, model: OpenAIModel -> inner.response(*messages, model = model, api = api) } - override fun answer(vararg questions: String, api: OpenAIAPI) = functionInterceptor.wrap(questions) { + override fun answer(vararg questions: String, api: API) = functionInterceptor.wrap(questions) { inner.answer(*it, api = api) } diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/SimpleActorInterceptor.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/SimpleActorInterceptor.kt index 4e90f18e..707fca29 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/SimpleActorInterceptor.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/record/SimpleActorInterceptor.kt @@ -1,8 +1,7 @@ package com.simiacryptus.skyenet.actors.record -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.OpenAIModel +import com.simiacryptus.jopenai.API +import com.simiacryptus.jopenai.models.OpenAIModel import com.simiacryptus.skyenet.actors.SimpleActor import com.simiacryptus.skyenet.util.FunctionWrapper @@ -16,18 +15,18 @@ class SimpleActorInterceptor( temperature = inner.temperature, ) { - override fun answer(vararg messages: OpenAIClient.ChatMessage, api: OpenAIAPI) = + override fun answer(vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, api: API) = functionInterceptor.wrap(messages.toList().toTypedArray()) { - messages: Array -> + messages: Array -> inner.answer(*messages, api = api) } override fun response( - vararg messages: OpenAIClient.ChatMessage, + vararg messages: com.simiacryptus.jopenai.ApiModel.ChatMessage, model: OpenAIModel, - api: OpenAIAPI + api: API ) = functionInterceptor.wrap(messages.toList().toTypedArray(), model) { - messages: Array, + messages: Array, model: OpenAIModel -> inner.response(*messages, model = model, api = api) } @@ -36,7 +35,7 @@ class SimpleActorInterceptor( inner.chatMessages(*it) } - override fun answer(vararg questions: String, api: OpenAIAPI) = functionInterceptor.wrap(questions) { + override fun answer(vararg questions: String, api: API) = functionInterceptor.wrap(questions) { inner.answer(*it, api = api) } } \ No newline at end of file diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ActorTestBase.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ActorTestBase.kt index 2475b24e..dd88b4a8 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ActorTestBase.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/actors/test/ActorTestBase.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.actors.test -import com.simiacryptus.openai.OpenAIClient +import com.simiacryptus.jopenai.OpenAIClient import com.simiacryptus.skyenet.actors.BaseActor import com.simiacryptus.skyenet.actors.opt.ActorOptimization import org.slf4j.LoggerFactory diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt index 47fe80d3..77b686dc 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/ClientManager.kt @@ -1,8 +1,10 @@ package com.simiacryptus.skyenet.platform -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.OpenAIClientBase -import com.simiacryptus.openai.models.OpenAIModel +import com.simiacryptus.jopenai.ApiModel +import com.simiacryptus.jopenai.ClientUtil +import com.simiacryptus.jopenai.OpenAIClient + +import com.simiacryptus.jopenai.models.OpenAIModel import org.slf4j.event.Level import java.io.File @@ -20,8 +22,8 @@ open class ClientManager { val userApi = createClient(session, user, logfile, userSettings.apiKey) if (userApi != null) return userApi } - val canUseGlobalKey = ApplicationServices.authorizationManager.isAuthorized(null, user, - AuthorizationManager.OperationType.GlobalKey + val canUseGlobalKey = ApplicationServices.authorizationManager.isAuthorized( + null, user, AuthorizationManager.OperationType.GlobalKey ) if (!canUseGlobalKey) throw RuntimeException("No API key") val logfile = dataStorage.getSessionDir(user, session).resolve(".sys/openai.log") @@ -29,19 +31,16 @@ open class ClientManager { return createClient(session, user, logfile)!! } - open protected fun createClient( - session: Session, - user: User?, - logfile: File, - key: String? = OpenAIClientBase.keyTxt + protected open fun createClient( + session: Session, user: User?, logfile: File, key: String? = ClientUtil.keyTxt ): OpenAIClient? = if (key.isNullOrBlank()) null else object : OpenAIClient( key = key, logLevel = Level.DEBUG, logStreams = mutableListOf( - logfile?.outputStream()?.buffered() + logfile.outputStream()?.buffered() ).filterNotNull().toMutableList(), ) { - override fun incrementTokens(model: OpenAIModel?, tokens: Usage) { + override fun incrementTokens(model: OpenAIModel?, tokens: ApiModel.Usage) { ApplicationServices.usageManager.incrementUsage(session, user, model!!, tokens) super.incrementTokens(model, tokens) } diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/DataStorage.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/DataStorage.kt index e966adf5..d8f31357 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/DataStorage.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/DataStorage.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.platform -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import java.io.File import java.util.* diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UsageManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UsageManager.kt index 99c663c5..a193c468 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UsageManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UsageManager.kt @@ -1,8 +1,7 @@ package com.simiacryptus.skyenet.platform -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.* -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.models.* +import com.simiacryptus.jopenai.util.JsonUtil import java.io.File import java.io.FileWriter import java.util.concurrent.ConcurrentHashMap @@ -44,14 +43,14 @@ open class UsageManager { Session(sessionId), User(email=user), modelEnum, - OpenAIClient.Usage(prompt_tokens = tokens.toInt()) + com.simiacryptus.jopenai.ApiModel.Usage(prompt_tokens = tokens.toInt()) ) "output" -> incrementUsage( Session(sessionId), User(email=user), modelEnum, - OpenAIClient.Usage(completion_tokens = tokens.toInt()) + com.simiacryptus.jopenai.ApiModel.Usage(completion_tokens = tokens.toInt()) ) else -> throw RuntimeException("Unknown direction $direction") @@ -108,7 +107,7 @@ open class UsageManager { File(".skyenet/usage/counters.json").writeText(JsonUtil.toJson(usagePerSession)) } - open fun incrementUsage(session: Session, user: User?, model: OpenAIModel, tokens: OpenAIClient.Usage) { + open fun incrementUsage(session: Session, user: User?, model: OpenAIModel, tokens: com.simiacryptus.jopenai.ApiModel.Usage) { @Suppress("NAME_SHADOWING") val user = if (null == user) null else User(email = user.email) // Hack usagePerSession.computeIfAbsent(session) { UsageCounters() } .tokensPerModel.computeIfAbsent(UsageKey(session, user, model)) { UsageValues() } @@ -130,7 +129,7 @@ open class UsageManager { } } - open fun getUserUsageSummary(user: User): Map { + open fun getUserUsageSummary(user: User): Map { @Suppress("NAME_SHADOWING") val user = if(null == user) null else User(email= user.email) // Hack return sessionsByUser[user]?.flatMap { sessionId -> val usage = usagePerSession[sessionId] @@ -139,7 +138,7 @@ open class UsageManager { } ?: emptyList() }?.groupBy { it.first }?.mapValues { it.value.map { it.second }.reduce { a, b -> - OpenAIClient.Usage( + com.simiacryptus.jopenai.ApiModel.Usage( prompt_tokens = a.prompt_tokens + b.prompt_tokens, completion_tokens = a.completion_tokens + b.completion_tokens ) @@ -147,11 +146,11 @@ open class UsageManager { } ?: emptyMap() } - open fun getSessionUsageSummary(session: Session): Map = + open fun getSessionUsageSummary(session: Session): Map = usagePerSession[session]?.tokensPerModel?.entries?.map { (model, counter) -> model.model to counter.toUsage() }?.groupBy { it.first }?.mapValues { it.value.map { it.second }.reduce { a, b -> - OpenAIClient.Usage( + com.simiacryptus.jopenai.ApiModel.Usage( prompt_tokens = a.prompt_tokens + b.prompt_tokens, completion_tokens = a.completion_tokens + b.completion_tokens ) @@ -167,12 +166,12 @@ open class UsageManager { val inputTokens: AtomicInteger = AtomicInteger(), val outputTokens: AtomicInteger = AtomicInteger(), ) { - fun addAndGet(tokens: OpenAIClient.Usage) { + fun addAndGet(tokens: com.simiacryptus.jopenai.ApiModel.Usage) { inputTokens.addAndGet(tokens.prompt_tokens) outputTokens.addAndGet(tokens.completion_tokens) } - fun toUsage() = OpenAIClient.Usage( + fun toUsage() = com.simiacryptus.jopenai.ApiModel.Usage( prompt_tokens = inputTokens.get(), completion_tokens = outputTokens.get() ) diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UserSettingsManager.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UserSettingsManager.kt index e15a8054..8b8447fa 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UserSettingsManager.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/platform/UserSettingsManager.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.platform -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import java.io.File open class UserSettingsManager { diff --git a/core/src/main/kotlin/com/simiacryptus/skyenet/util/FunctionWrapper.kt b/core/src/main/kotlin/com/simiacryptus/skyenet/util/FunctionWrapper.kt index 1bbfe387..09bbb361 100644 --- a/core/src/main/kotlin/com/simiacryptus/skyenet/util/FunctionWrapper.kt +++ b/core/src/main/kotlin/com/simiacryptus/skyenet/util/FunctionWrapper.kt @@ -2,7 +2,7 @@ package com.simiacryptus.skyenet.util -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import java.io.Closeable import java.io.File import java.util.concurrent.atomic.AtomicInteger diff --git a/settings.gradle.kts b/settings.gradle.kts index cce729ee..4d15adb6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,4 +8,4 @@ include("kotlin") include("webui") //include("util") -//includeBuild("../joe-penai/") +//includeBuild("../jo-penai/") diff --git a/webui/build.gradle.kts b/webui/build.gradle.kts index 55657fce..fbed1caf 100644 --- a/webui/build.gradle.kts +++ b/webui/build.gradle.kts @@ -32,7 +32,7 @@ val jetty_version = "11.0.18" val jackson_version = "2.15.3" dependencies { - implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.33") + implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.34") implementation(project(":core")) testImplementation(project(":groovy")) diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationDirectory.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationDirectory.kt index b53706e3..16dd5096 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationDirectory.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationDirectory.kt @@ -1,7 +1,8 @@ package com.simiacryptus.skyenet.application -import com.simiacryptus.openai.OpenAIClientBase +import com.simiacryptus.jopenai.ClientUtil + import com.simiacryptus.skyenet.OutputInterceptor import com.simiacryptus.skyenet.chat.ChatServer import com.simiacryptus.skyenet.platform.ApplicationServices @@ -55,7 +56,7 @@ abstract class ApplicationDirectory( protected open fun _main(args: Array) { try { init(args.contains("--server")) - OpenAIClientBase.keyTxt = decryptResource("openai.key.kms", javaClass.classLoader) + ClientUtil.keyTxt = decryptResource("openai.key.kms", javaClass.classLoader) ApplicationServices.isLocked = true val welcomeContext = newWebAppContext("/", welcomeResources, welcomeServlet) val server = start( diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationServer.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationServer.kt index 3df7ce17..00261689 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationServer.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationServer.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.application -import com.simiacryptus.openai.OpenAIAPI +import com.simiacryptus.jopenai.API import com.simiacryptus.skyenet.servlet.AppInfoServlet import com.simiacryptus.skyenet.chat.ChatServer import com.simiacryptus.skyenet.platform.ApplicationServices.authenticationManager @@ -47,7 +47,7 @@ abstract class ApplicationServer( user: User?, userMessage: String, socketManager: ApplicationSocketManager, - api: OpenAIAPI + api: API ) = this@ApplicationServer.newSession( session = session, user = user, @@ -63,7 +63,7 @@ abstract class ApplicationServer( user: User?, userMessage: String, ui: ApplicationInterface, - api: OpenAIAPI + api: API ) open val settingsClass: Class<*> get() = Map::class.java diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationSocketManager.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationSocketManager.kt index e5c0747f..7f9d13ad 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationSocketManager.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/application/ApplicationSocketManager.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.application -import com.simiacryptus.openai.OpenAIAPI +import com.simiacryptus.jopenai.API import com.simiacryptus.skyenet.chat.ChatSocket import com.simiacryptus.skyenet.platform.* import com.simiacryptus.skyenet.session.SocketManagerBase @@ -68,7 +68,7 @@ abstract class ApplicationSocketManager( user: User?, userMessage: String, socketManager: ApplicationSocketManager, - api: OpenAIAPI + api: API ) companion object { diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/ChatSocketManager.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/ChatSocketManager.kt index a992e408..159e2559 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/ChatSocketManager.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/ChatSocketManager.kt @@ -1,9 +1,9 @@ package com.simiacryptus.skyenet.chat -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.OpenAIClientBase.Companion.toContentList -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.models.OpenAITextModel +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.application.ApplicationServer import com.simiacryptus.skyenet.platform.Session import com.simiacryptus.skyenet.session.SocketManagerBase @@ -29,9 +29,9 @@ open class ChatSocketManager( protected val messages by lazy { val list = listOf( - OpenAIClient.ChatMessage(OpenAIClient.Role.system, systemPrompt.toContentList()), + com.simiacryptus.jopenai.ApiModel.ChatMessage(com.simiacryptus.jopenai.ApiModel.Role.system, systemPrompt.toContentList()), ).toMutableList() - if(initialAssistantPrompt.isNotBlank()) list += OpenAIClient.ChatMessage(OpenAIClient.Role.assistant, initialAssistantPrompt.toContentList()) + if(initialAssistantPrompt.isNotBlank()) list += com.simiacryptus.jopenai.ApiModel.ChatMessage(com.simiacryptus.jopenai.ApiModel.Role.assistant, initialAssistantPrompt.toContentList()) list } @@ -49,9 +49,9 @@ open class ChatSocketManager( } open fun handleMessage(userMessage: String, responseContents: String): String? { - messages += OpenAIClient.ChatMessage(OpenAIClient.Role.user, userMessage.toContentList()) + messages += com.simiacryptus.jopenai.ApiModel.ChatMessage(com.simiacryptus.jopenai.ApiModel.Role.user, userMessage.toContentList()) val response = getResponse() - messages += OpenAIClient.ChatMessage(OpenAIClient.Role.assistant, response.toContentList()) + messages += com.simiacryptus.jopenai.ApiModel.ChatMessage(com.simiacryptus.jopenai.ApiModel.Role.assistant, response.toContentList()) return response } @@ -61,8 +61,8 @@ open class ChatSocketManager( open fun onResponse(response: String, responseContents: String) {} - open val newChatRequest: OpenAIClient.ChatRequest - get() = OpenAIClient.ChatRequest( + open val newChatRequest: com.simiacryptus.jopenai.ApiModel.ChatRequest + get() = com.simiacryptus.jopenai.ApiModel.ChatRequest( messages = ArrayList(messages), temperature = temperature, model = model.modelName, diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/CodeChatServer.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/CodeChatServer.kt index 2f4fe461..96d5676d 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/CodeChatServer.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/chat/CodeChatServer.kt @@ -1,8 +1,8 @@ package com.simiacryptus.skyenet.chat -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.ChatModels -import com.simiacryptus.openai.models.OpenAITextModel +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.jopenai.models.ChatModels +import com.simiacryptus.jopenai.models.OpenAITextModel import com.simiacryptus.skyenet.application.ApplicationServer import com.simiacryptus.skyenet.platform.Session import com.simiacryptus.skyenet.platform.User diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/AppInfoServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/AppInfoServlet.kt index 0a6a690f..80a5034e 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/AppInfoServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/AppInfoServlet.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.servlet -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionSettingsServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionSettingsServlet.kt index a0b1a071..77c94a00 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionSettingsServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/SessionSettingsServlet.kt @@ -4,7 +4,7 @@ import com.simiacryptus.skyenet.application.ApplicationServer import com.simiacryptus.skyenet.application.ApplicationServer.Companion.getCookie import com.simiacryptus.skyenet.platform.ApplicationServices import com.simiacryptus.skyenet.platform.Session -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UsageServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UsageServlet.kt index c4c46493..9b74c336 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UsageServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UsageServlet.kt @@ -1,8 +1,7 @@ package com.simiacryptus.skyenet.servlet -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.OpenAIModel -import com.simiacryptus.openai.models.OpenAITextModel +import com.simiacryptus.jopenai.models.OpenAIModel +import com.simiacryptus.jopenai.models.OpenAITextModel import com.simiacryptus.skyenet.application.ApplicationServer.Companion.getCookie import com.simiacryptus.skyenet.platform.ApplicationServices import com.simiacryptus.skyenet.platform.Session @@ -31,7 +30,7 @@ class UsageServlet : HttpServlet() { private fun serve( resp: HttpServletResponse, - usage: Map + usage: Map ) { val totalPromptTokens = usage.values.sumOf { it.prompt_tokens } val totalCompletionTokens = usage.values.sumOf { it.completion_tokens } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserInfoServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserInfoServlet.kt index 77be0760..4366c4f1 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserInfoServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserInfoServlet.kt @@ -3,7 +3,7 @@ package com.simiacryptus.skyenet.servlet import com.simiacryptus.skyenet.application.ApplicationServer.Companion.getCookie import com.simiacryptus.skyenet.platform.ApplicationServices import com.simiacryptus.skyenet.platform.User -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserSettingsServlet.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserSettingsServlet.kt index ce6105c1..8cb17cab 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserSettingsServlet.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/servlet/UserSettingsServlet.kt @@ -3,7 +3,7 @@ package com.simiacryptus.skyenet.servlet import com.simiacryptus.skyenet.application.ApplicationServer.Companion.getCookie import com.simiacryptus.skyenet.platform.ApplicationServices import com.simiacryptus.skyenet.platform.UserSettingsManager.UserSettings -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import jakarta.servlet.http.HttpServlet import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/test/CodingActorTestApp.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/test/CodingActorTestApp.kt index 73fe9f33..13de66e6 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/test/CodingActorTestApp.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/test/CodingActorTestApp.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.test -import com.simiacryptus.openai.OpenAIAPI +import com.simiacryptus.jopenai.API import com.simiacryptus.skyenet.application.ApplicationServer import com.simiacryptus.skyenet.actors.CodingActor import com.simiacryptus.skyenet.application.ApplicationInterface @@ -23,9 +23,9 @@ open class CodingActorTestApp( user: User?, userMessage: String, ui: ApplicationInterface, - api: OpenAIAPI + api: API ) { - val sessionMessage = ui.newMessage(SocketManagerBase.randomID(), ApplicationServer.spinner, false) + val sessionMessage = ui.newMessage(SocketManagerBase.randomID(), spinner, false) sessionMessage.append("""
${renderMarkdown(userMessage)}
""", true) val response = actor.answer(userMessage, api = api) val canPlay = ApplicationServices.authorizationManager.isAuthorized( diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/test/ParsedActorTestApp.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/test/ParsedActorTestApp.kt index 5b30bd5d..cf9903ec 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/test/ParsedActorTestApp.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/test/ParsedActorTestApp.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.test -import com.simiacryptus.openai.OpenAIAPI +import com.simiacryptus.jopenai.API import com.simiacryptus.skyenet.application.ApplicationServer import com.simiacryptus.skyenet.actors.ParsedActor import com.simiacryptus.skyenet.application.ApplicationInterface @@ -8,7 +8,7 @@ import com.simiacryptus.skyenet.platform.Session import com.simiacryptus.skyenet.platform.User import com.simiacryptus.skyenet.session.SocketManagerBase import com.simiacryptus.skyenet.util.MarkdownUtil.renderMarkdown -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil import org.slf4j.LoggerFactory open class ParsedActorTestApp( @@ -24,9 +24,9 @@ open class ParsedActorTestApp( user: User?, userMessage: String, ui: ApplicationInterface, - api: OpenAIAPI + api: API ) { - val sessionMessage = ui.newMessage(SocketManagerBase.randomID(), ApplicationServer.spinner, false) + val sessionMessage = ui.newMessage(SocketManagerBase.randomID(), spinner, false) sessionMessage.append("""
${renderMarkdown(userMessage)}
""", true) val response = actor.answer(userMessage, api = api) sessionMessage.append( diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/test/SimpleActorTestApp.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/test/SimpleActorTestApp.kt index b7f32d89..d8fb27ca 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/test/SimpleActorTestApp.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/test/SimpleActorTestApp.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet.test -import com.simiacryptus.openai.OpenAIAPI +import com.simiacryptus.jopenai.API import com.simiacryptus.skyenet.application.ApplicationServer import com.simiacryptus.skyenet.actors.SimpleActor import com.simiacryptus.skyenet.application.ApplicationInterface @@ -30,9 +30,9 @@ open class SimpleActorTestApp( user: User?, userMessage: String, ui: ApplicationInterface, - api: OpenAIAPI + api: API ) { - val sessionMessage = ui.newMessage(SocketManagerBase.randomID(), ApplicationServer.spinner, false) + val sessionMessage = ui.newMessage(SocketManagerBase.randomID(), spinner, false) val actor = getSettings(session, user)?.actor ?: actor sessionMessage.append("""
${MarkdownUtil.renderMarkdown(userMessage)}
""", true) val moderatorResponse = actor.answer(userMessage, api = api) diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/util/EmbeddingVisualizer.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/util/EmbeddingVisualizer.kt index ae0359d0..21e74add 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/util/EmbeddingVisualizer.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/util/EmbeddingVisualizer.kt @@ -1,16 +1,16 @@ package com.simiacryptus.skyenet.util -import com.simiacryptus.openai.OpenAIAPI -import com.simiacryptus.openai.OpenAIClient -import com.simiacryptus.openai.models.EmbeddingModels +import com.simiacryptus.jopenai.API +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.jopenai.models.EmbeddingModels import com.simiacryptus.skyenet.application.ApplicationInterface import com.simiacryptus.skyenet.platform.DataStorage import com.simiacryptus.skyenet.platform.Session import com.simiacryptus.skyenet.platform.User -import com.simiacryptus.util.JsonUtil +import com.simiacryptus.jopenai.util.JsonUtil class EmbeddingVisualizer( - val api: OpenAIAPI, + val api: API, val dataStorage: DataStorage, val sessionID: Session, val appPath: String, @@ -22,7 +22,7 @@ class EmbeddingVisualizer( private fun toVectorMap(vararg words: String): Map { val vectors = words.map {word -> word to (api as OpenAIClient).createEmbedding( - OpenAIClient.EmbeddingRequest( + com.simiacryptus.jopenai.ApiModel.EmbeddingRequest( model = EmbeddingModels.AdaEmbedding.modelName, input = word, ) diff --git a/webui/src/test/kotlin/com/simiacryptus/skyenet/ActorOptTest.kt b/webui/src/test/kotlin/com/simiacryptus/skyenet/ActorOptTest.kt index eba9a7b3..c1db7071 100644 --- a/webui/src/test/kotlin/com/simiacryptus/skyenet/ActorOptTest.kt +++ b/webui/src/test/kotlin/com/simiacryptus/skyenet/ActorOptTest.kt @@ -1,6 +1,6 @@ package com.simiacryptus.skyenet -import com.simiacryptus.openai.OpenAIClient +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