Skip to content

Commit

Permalink
1.0.88 (#93)
Browse files Browse the repository at this point in the history
* 1.0.88

* 1.0.68

* fixes

* Update TaskPlanningTask.kt

* wip
  • Loading branch information
acharneski authored Aug 29, 2024
1 parent 668d45f commit 5eabcfa
Show file tree
Hide file tree
Showing 31 changed files with 2,229 additions and 168 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.67</version>
<version>1.0.68</version>
</dependency>
```

Gradle:

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

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

### 🌟 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.67")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.68")
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
Expand Up @@ -10,7 +10,7 @@ import com.simiacryptus.jopenai.models.OpenAITextModel
abstract class BaseActor<I, R>(
open val prompt: String,
val name: String? = null,
val model: ChatModels,
val model: OpenAITextModel,
val temperature: Double = 0.3,
) {
abstract fun respond(input: I, api: API, vararg messages: ApiModel.ChatMessage): R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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.jopenai.util.ClientUtil.toContentList
import com.simiacryptus.skyenet.core.OutputInterceptor
import com.simiacryptus.skyenet.interpreter.Interpreter
Expand All @@ -22,7 +23,7 @@ open class CodingActor(
),
name: String? = interpreterClass.simpleName,
val details: String? = null,
model: ChatModels,
model: OpenAITextModel,
val fallbackModel: ChatModels = ChatModels.GPT4o,
temperature: Double = 0.1,
val runtimeSymbols: Map<String, Any> = mapOf()
Expand Down Expand Up @@ -237,7 +238,7 @@ open class CodingActor(
override val code: String = givenCode ?: implementation.first

private fun implement(
model: ChatModels,
model: OpenAITextModel,
): Pair<String, String> {
val request = ChatRequest(messages = ArrayList(this.messages.toList()))
for (codingAttempt in 0..input.fixRetries) {
Expand Down Expand Up @@ -312,7 +313,7 @@ open class CodingActor(
previousCode: String,
error: Throwable,
vararg promptMessages: ChatMessage,
model: ChatModels
model: OpenAITextModel
): String = chat(
api = api,
request = ChatRequest(
Expand Down Expand Up @@ -344,7 +345,7 @@ open class CodingActor(
model = model
)

private fun chat(api: OpenAIClient, request: ChatRequest, model: ChatModels) =
private fun chat(api: OpenAIClient, 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 @@ -18,7 +18,7 @@ import javax.imageio.ImageIO
open class ImageActor(
prompt: String = "Transform the user request into an image generation prompt that the user will like",
name: String? = null,
textModel: ChatModels,
textModel: OpenAITextModel,
val imageModel: ImageModels = ImageModels.DallE2,
temperature: Double = 0.3,
val width: Int = 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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.jopenai.util.ClientUtil.toContentList
import com.simiacryptus.jopenai.util.JsonUtil
import java.util.function.Function
Expand All @@ -15,9 +16,9 @@ open class ParsedActor<T : Any>(
val exampleInstance: T? = resultClass?.getConstructor()?.newInstance(),
prompt: String = "",
name: String? = resultClass?.simpleName,
model: ChatModels = ChatModels.GPT4o,
model: OpenAITextModel = ChatModels.GPT4o,
temperature: Double = 0.3,
val parsingModel: ChatModels = ChatModels.GPT35Turbo,
val parsingModel: OpenAITextModel = ChatModels.GPT35Turbo,
val deserializerRetries: Int = 2,
open val describer: TypeDescriber = object : AbbrevWhitelistYamlDescriber(
"com.simiacryptus", "com.github.simiacryptus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.simiacryptus.jopenai.util.ClientUtil.toContentList
open class SimpleActor(
prompt: String,
name: String? = null,
model: ChatModels,
model: OpenAITextModel,
temperature: Double = 0.3,
) : BaseActor<List<String>, String>(
prompt = prompt,
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Gradle Releases -> https://github.com/gradle/gradle/releases
libraryGroup = com.simiacryptus.skyenet
libraryVersion = 1.0.87
libraryVersion = 1.0.88
gradleVersion = 7.6.1
kotlin.daemon.jvmargs=-Xmx2g
2 changes: 1 addition & 1 deletion webui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ val jetty_version = "11.0.18"
val jackson_version = "2.17.0"
dependencies {

implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.67") {
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.68") {
exclude(group = "org.slf4j", module = "slf4j-api")
}

Expand Down
18 changes: 16 additions & 2 deletions webui/src/main/kotlin/com/simiacryptus/diff/FileValidationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class FileValidationUtils {
file.name.startsWith(".") -> false
file.length() > (256 * 1024) -> false
isGitignore(file.toPath()) -> false
file.extension?.lowercase(Locale.getDefault()) in setOf(
file.extension.lowercase(Locale.getDefault()) in setOf(
"jar",
"zip",
"class",
Expand All @@ -104,6 +104,20 @@ class FileValidationUtils {
}
}

fun expandFileList(vararg data: File): Array<File> {
return data.flatMap {
(when {
it.name.startsWith(".") -> arrayOf()
isGitignore(it.toPath()) -> arrayOf()
it.length() > 1e6 -> arrayOf()
it.extension.lowercase(Locale.getDefault()) in
setOf("jar", "zip", "class", "png", "jpg", "jpeg", "gif", "ico") -> arrayOf()
it.isDirectory -> expandFileList(*it.listFiles() ?: arrayOf())
else -> arrayOf(it)
}).toList()
}.toTypedArray()
}

fun isGitignore(path: Path): Boolean {
var currentDir = path.toFile().parentFile
currentDir ?: return false
Expand All @@ -112,7 +126,7 @@ class FileValidationUtils {
if (it.exists()) {
val gitignore = it.readText()
if (gitignore.split("\n").any { line ->
val pattern = line.trim().trimEnd('/').replace(".", "\\.").replace("*", ".*")
val pattern = line.trim().trimStart('/').trimEnd('/').replace(".", "\\.").replace("*", ".*")
line.trim().isNotEmpty()
&& !line.startsWith("#")
&& path.fileName.toString().trimEnd('/').matches(Regex(pattern))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.models.ChatModels
import com.simiacryptus.jopenai.models.OpenAITextModel
import com.simiacryptus.jopenai.proxy.ValidatedObject
import com.simiacryptus.skyenet.Retryable
import com.simiacryptus.skyenet.core.actors.ActorSystem
Expand Down Expand Up @@ -34,7 +35,7 @@ open class CodingAgent<T : Interpreter>(
val symbols: Map<String, Any>,
temperature: Double = 0.1,
val details: String? = null,
val model: ChatModels,
val model: OpenAITextModel,
private val mainTask: SessionTask,
val actorMap: Map<ActorTypes, CodingActor> = mapOf(
ActorTypes.CodingActor to CodingActor(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.simiacryptus.skyenet.apps.general


import com.simiacryptus.diff.FileValidationUtils
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.models.OpenAITextModel
import com.simiacryptus.skyenet.core.platform.Session
import com.simiacryptus.skyenet.set
import com.simiacryptus.skyenet.webui.session.SessionTask
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
import java.util.concurrent.TimeUnit

class CmdPatchApp(
root: Path,
session: Session,
settings: Settings,
api: OpenAIClient,
val virtualFiles: Array<out File>?,
model: OpenAITextModel
) : PatchApp(root.toFile(), session, settings, api, model) {
companion object {
private val log = LoggerFactory.getLogger(CmdPatchApp::class.java)

val String.htmlEscape: String
get() = this.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&#39;")

fun truncate(output: String, kb: Int = 32): String {
var returnVal = output
if (returnVal.length > 1024 * 2 * kb) {
returnVal = returnVal.substring(0, 1024 * kb) +
"\n\n... Output truncated ...\n\n" +
returnVal.substring(returnVal.length - 1024 * kb)
}
return returnVal
}


}

private fun getFiles(
virtualFiles: Array<out File>?
): MutableSet<Path> {
val codeFiles = mutableSetOf<Path>() // Set to avoid duplicates
virtualFiles?.forEach { file ->
if (file.isDirectory) {
if (file.name.startsWith(".")) return@forEach
if (FileValidationUtils.isGitignore(file.toPath())) return@forEach
codeFiles.addAll(getFiles(file.listFiles()))
} else {
codeFiles.add((file.toPath()))
}
}
return codeFiles
}

override fun codeFiles() = getFiles(virtualFiles)
.filter { it.toFile().length() < 1024 * 1024 / 2 } // Limit to 0.5MB
.map { root.toPath().relativize(it) ?: it }.toSet()

override fun codeSummary(paths: List<Path>): String = paths
.filter {
val file = settings.workingDirectory?.resolve(it.toFile())
file?.exists() == true && !file.isDirectory && file.length() < (256 * 1024)
}
.joinToString("\n\n") { path ->
try {
"""
|# ${path}
|${tripleTilde}${path.toString().split('.').lastOrNull()}
|${settings.workingDirectory?.resolve(path.toFile())?.readText(Charsets.UTF_8)}
|${tripleTilde}
""".trimMargin()
} catch (e: Exception) {
log.warn("Error reading file", e)
"Error reading file `${path}` - ${e.message}"
}
}

override fun projectSummary(): String {
val codeFiles = codeFiles()
val str = codeFiles
.asSequence()
.filter { settings.workingDirectory?.toPath()?.resolve(it)?.toFile()?.exists() == true }
.distinct().sorted()
.joinToString("\n") { path ->
"* ${path} - ${
settings.workingDirectory?.toPath()?.resolve(path)?.toFile()?.length() ?: "?"
} bytes".trim()
}
return str
}

override fun output(task: SessionTask): OutputResult = run {
val command =
listOf(settings.executable.absolutePath) + settings.arguments.split(" ").filter(String::isNotBlank)
val processBuilder = ProcessBuilder(command).directory(settings.workingDirectory)
val buffer = StringBuilder()
val taskOutput = task.add("")
val process = processBuilder.start()
Thread {
var lastUpdate = 0L
process.errorStream.bufferedReader().use { reader ->
var line: String?
while (reader.readLine().also { line = it } != null) {
buffer.append(line).append("\n")
if (lastUpdate + TimeUnit.SECONDS.toMillis(15) < System.currentTimeMillis()) {
taskOutput?.set("<pre>\n${truncate(buffer.toString()).htmlEscape}\n</pre>")
task.append("", true)
lastUpdate = System.currentTimeMillis()
}
}
task.append("", true)
}
}.start()
process.inputStream.bufferedReader().use { reader ->
var line: String?
var lastUpdate = 0L
while (reader.readLine().also { line = it } != null) {
buffer.append(line).append("\n")
if (lastUpdate + TimeUnit.SECONDS.toMillis(15) < System.currentTimeMillis()) {
taskOutput?.set("<pre>\n${outputString(buffer).htmlEscape}\n</pre>")
task.append("", true)
lastUpdate = System.currentTimeMillis()
}
}
task.append("", true)
}
task.append("", false)
if (!process.waitFor(5, TimeUnit.MINUTES)) {
process.destroy()
throw RuntimeException("Process timed out")
}
val exitCode = process.exitValue()
var output = outputString(buffer)
taskOutput?.clear()
OutputResult(exitCode, output)
}

private fun outputString(buffer: StringBuilder): String {
var output = buffer.toString()
output = output.replace(Regex("\\x1B\\[[0-?]*[ -/]*[@-~]"), "") // Remove terminal escape codes
output = truncate(output)
return output
}

override fun searchFiles(searchStrings: List<String>): Set<Path> {
return searchStrings.flatMap { searchString ->
FileValidationUtils.filteredWalk(settings.workingDirectory!!) { !FileValidationUtils.isGitignore(it.toPath()) }
.filter { FileValidationUtils.isLLMIncludable(it) }
.filter { it.readText().contains(searchString, ignoreCase = true) }
.map { it.toPath() }
.toList()
}.toSet()
}
}
Loading

0 comments on commit 5eabcfa

Please sign in to comment.