Skip to content

Commit

Permalink
1.2.0 (#98)
Browse files Browse the repository at this point in the history
* 1.2.0

* wip

* wip

* wip

* wip

* 1.2.0

* Update ActorTestAppServer.kt

* Update ActorTestAppServer.kt
  • Loading branch information
acharneski authored Sep 6, 2024
1 parent b7bc943 commit 375042b
Show file tree
Hide file tree
Showing 69 changed files with 989 additions and 1,424 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ Maven:
<dependency>
<groupId>com.simiacryptus</groupId>
<artifactId>skyenet-webui</artifactId>
<version>1.0.68</version>
<version>1.1.0</version>
</dependency>
```

Gradle:

```groovy
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.68'
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.1.0'
```

```kotlin
implementation("com.simiacryptus:skyenet:1.0.68")
implementation("com.simiacryptus:skyenet:1.1.0")
```

### 🌟 To Use
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val hsqldb_version = "2.7.2"

dependencies {

implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.68")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.1.0")
implementation(group = "org.hsqldb", name = "hsqldb", version = hsqldb_version)

implementation("org.apache.commons:commons-text:1.11.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.skyenet.core.actors.record.*
import com.simiacryptus.skyenet.core.platform.ApplicationServices
import com.simiacryptus.skyenet.core.platform.Session
import com.simiacryptus.skyenet.core.platform.StorageInterface
import com.simiacryptus.skyenet.core.platform.User
import com.simiacryptus.skyenet.core.util.FunctionWrapper
import com.simiacryptus.skyenet.core.util.JsonFunctionRecorder

open class ActorSystem<T : Enum<*>>(
val actors: Map<String, BaseActor<*, *>>,
Expand All @@ -16,61 +13,5 @@ open class ActorSystem<T : Enum<*>>(
) {
protected val pool by lazy { ApplicationServices.clientManager.getPool(session, user) }

private val actorMap = mutableMapOf<T, BaseActor<*, *>>()

fun getActor(actor: T): BaseActor<*, *> {
return synchronized(actorMap) {
actorMap.computeIfAbsent(actor) { innerActor ->
try {
val wrapper = getWrapper(actor.name)
when (val baseActor = actors[actor.name]) {
null -> throw RuntimeException("No actor for $actor")
is SimpleActor -> SimpleActorInterceptor(
inner = baseActor,
functionInterceptor = wrapper
)

is ParsedActor<*> -> ParsedActorInterceptor(
inner = baseActor,
functionInterceptor = wrapper
)

is CodingActor -> CodingActorInterceptor(
inner = baseActor,
functionInterceptor = wrapper
)

is ImageActor -> ImageActorInterceptor(
inner = baseActor,
functionInterceptor = wrapper
)

is TextToSpeechActor -> TextToSpeechActorInterceptor(
inner = baseActor,
functionInterceptor = wrapper
)

else -> throw RuntimeException("Unknown actor type: ${baseActor.javaClass}")
}
} catch (e: Throwable) {
val baseActor = actors[actor.name]!!
log.warn("Error creating actor $actor, returning $baseActor", e)
baseActor
}
}
}
}

private val wrapperMap = mutableMapOf<String, FunctionWrapper>()
private fun getWrapper(name: String) = synchronized(wrapperMap) {
wrapperMap.getOrPut(name) {
FunctionWrapper(JsonFunctionRecorder(
dataStorage.getDataDir(user, session).resolve("actors/$name").apply { mkdirs() }
))
}
}

companion object {
private val log = org.slf4j.LoggerFactory.getLogger(ActorSystem::class.java)
}
fun getActor(actor: T) = actors.get(actor.name)!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.ChatClient
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.models.ChatModels
import com.simiacryptus.jopenai.models.OpenAIModel
Expand All @@ -15,7 +16,7 @@ abstract class BaseActor<I, R>(
) {
abstract fun respond(input: I, api: API, vararg messages: ApiModel.ChatMessage): R
open fun response(vararg input: ApiModel.ChatMessage, model: OpenAIModel = this.model, api: API) =
(api as OpenAIClient).chat(
(api as ChatClient).chat(
ApiModel.ChatRequest(
messages = ArrayList(input.toList()),
temperature = temperature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel.*
import com.simiacryptus.jopenai.ChatClient
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.describe.AbbrevWhitelistYamlDescriber
import com.simiacryptus.jopenai.describe.TypeDescriber
Expand Down Expand Up @@ -136,7 +137,7 @@ open class CodingActor(
var result = CodeResultImpl(
*messages,
input = input,
api = (api as OpenAIClient)
api = (api as ChatClient)
)
if (!input.autoEvaluate) return result
for (i in 0..input.fixIterations) try {
Expand Down Expand Up @@ -206,7 +207,7 @@ open class CodingActor(
inner class CodeResultImpl(
vararg val messages: ChatMessage,
private val input: CodeRequest,
private val api: OpenAIClient,
private val api: ChatClient,
private val givenCode: String? = null,
private val givenResponse: String? = null,
) : CodeResult {
Expand Down Expand Up @@ -309,7 +310,7 @@ open class CodingActor(
}

private fun fixCommand(
api: OpenAIClient,
api: ChatClient,
previousCode: String,
error: Throwable,
vararg promptMessages: ChatMessage,
Expand Down Expand Up @@ -345,7 +346,7 @@ open class CodingActor(
model = model
)

private fun chat(api: OpenAIClient, request: ChatRequest, model: OpenAITextModel) =
private fun chat(api: ChatClient, request: ChatRequest, model: OpenAITextModel) =
api.chat(request.copy(model = model.modelName, temperature = temperature), model)
.choices.first().message?.content.orEmpty().trim()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.ChatClient
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.describe.AbbrevWhitelistYamlDescriber
import com.simiacryptus.jopenai.describe.TypeDescriber
Expand Down Expand Up @@ -76,7 +77,7 @@ open class ParsedActor<T : Any>(
""".trimMargin()
for (i in 0 until deserializerRetries) {
try {
val content = (api as OpenAIClient).chat(
val content = (api as ChatClient).chat(
ApiModel.ChatRequest(
messages = listOf(
ApiModel.ChatMessage(role = ApiModel.Role.system, content = prompt.toContentList()),
Expand Down

This file was deleted.

Loading

0 comments on commit 375042b

Please sign in to comment.