Skip to content

Commit

Permalink
1.0.63 (#68)
Browse files Browse the repository at this point in the history
* 1.0.63

* docs

* wip

* wip

* Update InterpreterTestBase.kt
  • Loading branch information
acharneski authored Apr 17, 2024
1 parent 74b7c54 commit 5b1ef56
Show file tree
Hide file tree
Showing 106 changed files with 8,802 additions and 8,728 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ val jackson_version = "2.15.3"

dependencies {

implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.51")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.52")

implementation("org.apache.commons:commons-text:1.11.0")

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/dev_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3450,7 +3450,7 @@ interface Selenium : AutoCloseable {
url: URL,
currentFilename: String?,
saveRoot: String
);
)
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ package com.github.simiacryptus.aicoder.actions.generic
import java.io.File
import java.nio.file.Path

fun Array<Path>.commonRoot() : Path = when {
isEmpty() -> error("No paths")
size == 1 && first().toFile().isFile -> first().parent
size == 1 -> first()
else -> this.reduce { a, b ->
when {
a.startsWith(b) -> b
b.startsWith(a) -> a
else -> when (val common = a.commonPrefixWith(b)) {
a -> a
b -> b
else -> common.toAbsolutePath()
}
fun Array<Path>.commonRoot(): Path = when {
isEmpty() -> error("No paths")
size == 1 && first().toFile().isFile -> first().parent
size == 1 -> first()
else -> this.reduce { a, b ->
when {
a.startsWith(b) -> b
b.startsWith(a) -> a
else -> when (val common = a.commonPrefixWith(b)) {
a -> a
b -> b
else -> common.toAbsolutePath()
}
}
}
}
}

private fun Path.commonPrefixWith(b: Path): Path {
val a = this
val aParts = a.toAbsolutePath().toString().split(File.separator)
val bParts = b.toAbsolutePath().toString().split(File.separator)
val common = aParts.zip(bParts).takeWhile { (a, b) -> a == b }.map { it.first }
return File(File.separator + common.joinToString(File.separator)).toPath()
val a = this
val aParts = a.toAbsolutePath().toString().split(File.separator)
val bParts = b.toAbsolutePath().toString().split(File.separator)
val common = aParts.zip(bParts).takeWhile { (a, b) -> a == b }.map { it.first }
return File(File.separator + common.joinToString(File.separator)).toPath()
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package com.github.simiacryptus.aicoder.actions.generic
import java.io.File

fun getModuleRootForFile(file: File): File {
var current = file
while (current.parentFile != null) {
if (current.resolve(".git").exists()) {
return current
var current = file
while (current.parentFile != null) {
if (current.resolve(".git").exists()) {
return current
}
current = current.parentFile
}
current = current.parentFile
}
return file
return file
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,66 @@ import com.simiacryptus.skyenet.core.util.JsonFunctionRecorder
import java.io.File

open class ActorSystem<T : Enum<*>>(
val actors: Map<String, BaseActor<*, *>>,
val dataStorage: StorageInterface,
val user: User?,
val session: Session
val actors: Map<String, BaseActor<*, *>>,
val dataStorage: StorageInterface,
val user: User?,
val session: Session
) {
private val sessionDir = dataStorage.getSessionDir(user, session)
protected val pool by lazy { ApplicationServices.clientManager.getPool(session, user, dataStorage) }
private val sessionDir = dataStorage.getSessionDir(user, session)
protected val pool by lazy { ApplicationServices.clientManager.getPool(session, user, dataStorage) }

private val actorMap = mutableMapOf<T, BaseActor<*, *>>()
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 as SimpleActor,
functionInterceptor = wrapper
)
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 as ParsedActor<*>),
functionInterceptor = wrapper
)
is ParsedActor<*> -> ParsedActorInterceptor(
inner = baseActor,
functionInterceptor = wrapper
)

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

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

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

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

private val wrapperMap = mutableMapOf<String, FunctionWrapper>()
private fun getWrapper(name: String) = synchronized(wrapperMap) {
wrapperMap.getOrPut(name) {
FunctionWrapper(JsonFunctionRecorder(File(sessionDir, ".sys/$session/actors/$name")))
private val wrapperMap = mutableMapOf<String, FunctionWrapper>()
private fun getWrapper(name: String) = synchronized(wrapperMap) {
wrapperMap.getOrPut(name) {
FunctionWrapper(JsonFunctionRecorder(File(sessionDir, ".sys/$session/actors/$name")))
}
}
}

companion object {
private val log = org.slf4j.LoggerFactory.getLogger(ActorSystem::class.java)
}
companion object {
private val log = org.slf4j.LoggerFactory.getLogger(ActorSystem::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@ import com.simiacryptus.jopenai.models.ChatModels
import com.simiacryptus.jopenai.models.OpenAIModel
import com.simiacryptus.jopenai.models.OpenAITextModel

abstract class BaseActor<I,R>(
abstract class BaseActor<I, R>(
open val prompt: String,
val name: String? = null,
val model: ChatModels,
val temperature: Double = 0.3,
) {
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(
ApiModel.ChatRequest(
messages = ArrayList(input.toList()),
temperature = temperature,
model = this.model.modelName,
),
model = this.model
)
open fun answer(input: I, api: API): R = respond(input=input, api = api, *chatMessages(input))
open fun response(vararg input: ApiModel.ChatMessage, model: OpenAIModel = this.model, api: API) =
(api as OpenAIClient).chat(
ApiModel.ChatRequest(
messages = ArrayList(input.toList()),
temperature = temperature,
model = this.model.modelName,
),
model = this.model
)

open fun answer(input: I, api: API): R = respond(input = input, api = api, *chatMessages(input))

abstract fun chatMessages(questions: I): Array<ApiModel.ChatMessage>
abstract fun withModel(model: ChatModels): BaseActor<I,R>
abstract fun withModel(model: ChatModels): BaseActor<I, R>
}
Loading

0 comments on commit 5b1ef56

Please sign in to comment.