Skip to content

Commit

Permalink
1.0.33 (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski authored Nov 18, 2023
1 parent ec05be9 commit 91469d4
Show file tree
Hide file tree
Showing 30 changed files with 253 additions and 178 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.32</version>
<version>1.0.33</version>
</dependency>
```

Gradle:

```groovy
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.32'
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.33'
```

```kotlin
implementation("com.simiacryptus:skyenet:1.0.32")
implementation("com.simiacryptus:skyenet:1.0.33")
```

### 🌟 To Use
Expand Down
4 changes: 2 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ kotlin {
}

val junit_version = "5.10.1"
val logback_version = "1.2.12"
val logback_version = "1.4.11"

dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.29")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.31")

implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.9")
implementation(group = "commons-io", name = "commons-io", version = "2.15.0")
Expand Down
25 changes: 13 additions & 12 deletions core/src/main/kotlin/com/simiacryptus/skyenet/Brain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

package com.simiacryptus.skyenet

import com.simiacryptus.openai.Model
import com.simiacryptus.openai.Models
import com.simiacryptus.openai.models.OpenAIModel
import com.simiacryptus.openai.models.ChatModels
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.OpenAIClient.ChatMessage
import com.simiacryptus.openai.OpenAIClient.ChatRequest
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
Expand All @@ -18,7 +19,7 @@ import java.util.concurrent.atomic.AtomicInteger
open class Brain(
val api: OpenAIClient,
val symbols: java.util.Map<String, Object> = java.util.HashMap<String, Object>() as java.util.Map<String, Object>,
val model: Model = Models.GPT35Turbo,
val model: OpenAITextModel = ChatModels.GPT35Turbo,
private val verbose: Boolean = false,
val temperature: Double = 0.3,
val describer: TypeDescriber = YamlDescriber(),
Expand All @@ -33,7 +34,7 @@ open class Brain(
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(ChatMessage.Role.user, it) }).toTypedArray()
prompt.map { ChatMessage(Role.user, it.toContentList()) }).toTypedArray()
)
}

Expand All @@ -49,15 +50,15 @@ open class Brain(
@Language("TEXT")
open fun getChatSystemMessages(apiDescription: String): List<ChatMessage> = listOf(
ChatMessage(
ChatMessage.Role.system, """
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()
|""".trimMargin().trim().toContentList()
)
)

Expand All @@ -71,15 +72,15 @@ open class Brain(
messages = ArrayList(
promptMessages.toList() + listOf(
ChatMessage(
ChatMessage.Role.assistant,
Role.assistant,
"""
|```${language.lowercase()}
|${previousCode}
|```
|""".trimMargin().trim()
|""".trimMargin().trim().toContentList()
),
ChatMessage(
ChatMessage.Role.system,
Role.system,
"""
|The previous code failed with the following error:
|
Expand All @@ -93,7 +94,7 @@ open class Brain(
|```
|
|Correct the code and try again.
|""".trimMargin().trim()
|""".trimMargin().trim().toContentList()
)
))
)
Expand Down
18 changes: 10 additions & 8 deletions core/src/main/kotlin/com/simiacryptus/skyenet/actors/BaseActor.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.simiacryptus.skyenet.actors

import com.simiacryptus.openai.Model
import com.simiacryptus.openai.Models
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

abstract class BaseActor<T>(
open val prompt: String,
val name: String? = null,
val model: Model = Models.GPT35Turbo,
val model: OpenAITextModel = ChatModels.GPT35Turbo,
val temperature: Double = 0.3,
) {
open fun response(vararg messages: OpenAIClient.ChatMessage, model: Model = this.model, api: OpenAIClient) = api.chat(
open fun response(vararg messages: OpenAIClient.ChatMessage, model: OpenAIModel = this.model, api: OpenAIClient) = api.chat(
OpenAIClient.ChatRequest(
messages = ArrayList(messages.toList()),
temperature = temperature,
Expand All @@ -23,13 +25,13 @@ abstract class BaseActor<T>(

open fun chatMessages(vararg questions: String) = arrayOf(
OpenAIClient.ChatMessage(
role = OpenAIClient.ChatMessage.Role.system,
content = prompt
role = OpenAIClient.Role.system,
content = prompt.toContentList()
),
) + questions.map {
OpenAIClient.ChatMessage(
role = OpenAIClient.ChatMessage.Role.user,
content = it
role = OpenAIClient.Role.user,
content = it.toContentList()
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.simiacryptus.skyenet.actors

import com.simiacryptus.openai.Model
import com.simiacryptus.openai.Models
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.skyenet.Brain
import com.simiacryptus.skyenet.Brain.Companion.indent
import com.simiacryptus.skyenet.Brain.Companion.superMethod
Expand All @@ -21,8 +23,8 @@ open class CodingActor(
),
name: String? = interpreterClass.simpleName,
val details: String? = null,
model: Model = Models.GPT35Turbo,
val fallbackModel: Model = Models.GPT4Turbo,
model: OpenAITextModel = ChatModels.GPT35Turbo,
val fallbackModel: OpenAITextModel = ChatModels.GPT4Turbo,
temperature: Double = 0.1,
) : BaseActor<CodeResult>(
prompt = "",
Expand Down Expand Up @@ -96,7 +98,7 @@ open class CodingActor(
fun answerWithPrefix(codePrefix: String, vararg messages: OpenAIClient.ChatMessage, api: OpenAIClient): CodeResult {
val prevList = messages.toList()
val newList = prevList.dropLast(1) + listOf(
OpenAIClient.ChatMessage(OpenAIClient.ChatMessage.Role.assistant, codePrefix)
OpenAIClient.ChatMessage(OpenAIClient.Role.assistant, codePrefix.toContentList())
) + prevList.last()
return CodeResultImpl(*newList.toTypedArray(), api = api)
}
Expand All @@ -108,7 +110,7 @@ open class CodingActor(
): Pair<CodeResult, ExecutionResult> {
val prevList = messages.toList()
val messagesWithPrefix = prevList.dropLast(1) + if(codePrefix.isBlank()) listOf() else listOf(
OpenAIClient.ChatMessage(OpenAIClient.ChatMessage.Role.assistant, codePrefix)
OpenAIClient.ChatMessage(OpenAIClient.Role.assistant, codePrefix.toContentList())
) + prevList.last()
var result = CodeResultImpl(*messagesWithPrefix.toTypedArray(), api = api)
for (i in 0..fixIterations) try {
Expand All @@ -128,7 +130,7 @@ open class CodingActor(
return CodeResultImpl(*messages.toTypedArray(), codePrefix = codedInstruction, api = api)
}

fun brain(api: OpenAIClient, model: Model) = Brain(
fun brain(api: OpenAIClient, model: OpenAITextModel) = Brain(
api = api,
symbols = symbols.mapValues { it as Object }.asJava,
language = interpreter.getLanguage(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.simiacryptus.skyenet.actors

import com.simiacryptus.openai.Model
import com.simiacryptus.openai.Models
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.openai.proxy.ChatProxy
import java.util.function.Function

open class ParsedActor<T>(
val parserClass: Class<out Function<String, T>>,
prompt: String,
val action: String? = null,
model: Model = Models.GPT35Turbo,
model: OpenAITextModel = ChatModels.GPT35Turbo,
temperature: Double = 0.3,
) : BaseActor<ParsedResponse<T>>(
prompt = prompt,
Expand All @@ -22,7 +23,7 @@ open class ParsedActor<T>(
val parser: Function<String, T> = ChatProxy(
clazz = parserClass,
api = api,
model = Models.GPT35Turbo,
model = ChatModels.GPT35Turbo,
temperature = temperature,
).create()
private val _text: String by lazy { response(*messages, api = api).choices.first().message?.content ?: throw RuntimeException("No response") }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.simiacryptus.skyenet.actors

import com.simiacryptus.openai.Model
import com.simiacryptus.openai.Models
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.models.ChatModels
import com.simiacryptus.openai.models.OpenAITextModel

open class SimpleActor(
prompt: String,
name: String? = null,
model: Model = Models.GPT35Turbo,
model: OpenAITextModel = ChatModels.GPT35Turbo,
temperature: Double = 0.3,
) : BaseActor<String>(
prompt = prompt,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.simiacryptus.skyenet.actors.opt

import com.simiacryptus.openai.Model
import com.simiacryptus.openai.Models
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.skyenet.actors.BaseActor
Expand All @@ -15,7 +16,7 @@ import kotlin.math.pow

open class ActorOptimization(
val api: OpenAIClient,
val model: Model = Models.GPT35Turbo,
val model: OpenAITextModel = ChatModels.GPT35Turbo,
private val mutationRate: Double = 0.5,
private val mutatonTypes: Map<String, Double> = mapOf(
"Rephrase" to 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.simiacryptus.skyenet.actors.opt

import com.simiacryptus.openai.Models
import com.simiacryptus.openai.models.ChatModels
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.models.EmbeddingModels
import com.simiacryptus.openai.opt.DistanceType
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -30,7 +31,7 @@ abstract class Expectation {

private fun createEmbedding(api: OpenAIClient, str: String) = api.createEmbedding(
OpenAIClient.EmbeddingRequest(
model = Models.AdaEmbedding.modelName, input = str
model = EmbeddingModels.AdaEmbedding.modelName, input = str
)
).data.first().embedding!!
}
Expand Down
Loading

0 comments on commit 91469d4

Please sign in to comment.