Skip to content

Commit

Permalink
1.0.82 (#87)
Browse files Browse the repository at this point in the history
* 1.0.82

* improved diff/patch

* Update AddApplyFileDiffLinks.kt

* Update functions.js

* wip

* Update IterativePatchUtil.kt

* wip

* wip

* wip

* Update IterativePatchUtil.kt

* Update IterativePatchUtil.kt

* wip

* wip

* wip

* Update SocketManagerBase.kt

* wip

* wip

* Update SocketManagerBase.kt

* Update SocketManagerBase.kt

* Update IterativePatchUtil.kt

* Update IterativePatchUtil.kt

* wip

* Update IterativePatchUtil.kt

* Update IterativePatchUtil.kt

* Update SocketManagerBase.kt

* Update SocketManagerBase.kt

* Update SocketManagerBase.kt

* wip

* Update IterativePatchUtilTest.kt

* wip

* diff patch test

* fix

* Update SocketManagerBase.kt

* Update FilePatchTestApp.kt

* Update IterativePatchUtil.kt

* Update IterativePatchUtil.kt
  • Loading branch information
acharneski authored Jul 7, 2024
1 parent aee88c0 commit 96720aa
Show file tree
Hide file tree
Showing 19 changed files with 1,035 additions and 430 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build/
openai.key
*.log
*.log.*
client_secret_google_oauth.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ open class AwsPlatform(
fun get() = try {
AwsPlatform()
} catch (e: Throwable) {
log.info("Error initializing AWS platform", e)
log.warn("Error initializing AWS platform", e)
null
}
}
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Gradle Releases -> https://github.com/gradle/gradle/releases
libraryGroup = com.simiacryptus.skyenet
libraryVersion = 1.0.81
libraryVersion = 1.0.82
gradleVersion = 7.6.1
kotlin.daemon.jvmargs=-Xmx2g
27 changes: 20 additions & 7 deletions webui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ val jetty_version = "11.0.18"
val jackson_version = "2.17.0"
dependencies {

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

implementation(project(":core"))
implementation(project(":kotlin"))

implementation("org.seleniumhq.selenium:selenium-chrome-driver:4.16.1")
compileOnly(group = "software.amazon.awssdk", name = "aws-sdk-java", version = "2.21.9")
compileOnly("org.jsoup:jsoup:1.17.2")


implementation("com.google.zxing:core:3.5.3")
implementation("com.google.zxing:javase:3.5.3")

implementation("org.openapitools:openapi-generator:7.3.0")
implementation("org.openapitools:openapi-generator-cli:7.3.0")
compileOnly(group = "software.amazon.awssdk", name = "aws-sdk-java", version = "2.21.9")
runtimeOnly(group = "software.amazon.awssdk", name = "aws-sdk-java", version = "2.21.9")

implementation("org.openapitools:openapi-generator:7.3.0") {
exclude(group = "org.slf4j", module = "slf4j-api")
exclude(group = "org.slf4j", module = "slf4j-ext")
exclude(group = "org.slf4j", module = "slf4j-simple")
}
compileOnly("org.openapitools:openapi-generator-cli:7.3.0") {
exclude(group = "org.slf4j", module = "slf4j-api")
}
testRuntimeOnly("org.openapitools:openapi-generator-cli:7.3.0")

implementation(group = "org.eclipse.jetty", name = "jetty-server", version = jetty_version)
implementation(group = "org.eclipse.jetty", name = "jetty-servlet", version = jetty_version)
Expand All @@ -71,7 +80,9 @@ dependencies {
testImplementation(project(":kotlin"))
testImplementation(project(":scala"))

implementation(group = "org.apache.httpcomponents.client5", name = "httpclient5", version = "5.2.3")
implementation(group = "org.apache.httpcomponents.client5", name = "httpclient5", version = "5.3.1") {
exclude(group = "org.slf4j", module = "slf4j-api")
}

implementation(group = "com.fasterxml.jackson.core", name = "jackson-core", version = jackson_version)
implementation(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = jackson_version)
Expand All @@ -85,7 +96,9 @@ dependencies {
implementation(group = "commons-codec", name = "commons-codec", version = "1.16.0")

implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.9")
testImplementation(group = "org.slf4j", name = "slf4j-simple", version = "2.0.9")
runtimeOnly(group = "org.slf4j", name = "slf4j-simple", version = "2.0.9")
testImplementation(group = "ch.qos.logback", name = "logback-classic", version = "1.4.14")
testImplementation(group = "ch.qos.logback", name = "logback-core", version = "1.4.14")

testImplementation(kotlin("script-runtime"))
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-api", version = "5.10.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun SocketManagerBase.addApplyDiffLinks(
val isParenthesisBalanced = FileValidationUtils.isParenthesisBalanced(code)
val isQuoteBalanced = FileValidationUtils.isQuoteBalanced(code)
val isSingleQuoteBalanced = FileValidationUtils.isSingleQuoteBalanced(code)
var newCode = IterativePatchUtil.patch(code, diff)
var newCode = IterativePatchUtil.applyPatch(code, diff)
newCode = newCode.replace("\r", "")
val isCurlyBalancedNew = FileValidationUtils.isCurlyBalanced(newCode)
val isSquareBalancedNew = FileValidationUtils.isSquareBalanced(newCode)
Expand Down Expand Up @@ -58,12 +58,7 @@ fun SocketManagerBase.addApplyDiffLinks(
}
})!!
val patch = patch(code(), diffVal).newCode
val test1 = DiffUtil.formatDiff(
DiffUtil.generateDiff(
code().replace("\r", "").lines(),
patch.lines()
)
)
val test1 = IterativePatchUtil.generatePatch(code().replace("\r", ""), patch)
val patchRev = patch(
code().lines().reversed().joinToString("\n"),
diffVal.lines().reversed().joinToString("\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.simiacryptus.diff
import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.models.ChatModels
import com.simiacryptus.skyenet.AgentPatterns
import com.simiacryptus.skyenet.AgentPatterns.displayMapInTabs
import com.simiacryptus.skyenet.core.actors.SimpleActor
import com.simiacryptus.skyenet.set
Expand All @@ -28,7 +27,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
api: API,
): String {
val initiator = "(?s)```[\\w]*\n".toRegex()
if(response.contains(initiator) && !response.split(initiator, 2)[1].contains("\n```(?![^\n])".toRegex())) {
if (response.contains(initiator) && !response.split(initiator, 2)[1].contains("\n```(?![^\n])".toRegex())) {
// Single diff block without the closing ``` due to LLM limitations... add it back
return addApplyFileDiffLinks(
root,
Expand All @@ -45,7 +44,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
val diffs: List<Pair<IntRange, String>> = findAll.filter { block ->
val header = headers.lastOrNull { it.first.endInclusive < block.range.start }
val filename = resolve(root, header?.second ?: "Unknown")
when {
when {
!root.toFile().resolve(filename).exists() -> false
//block.groupValues[1] == "diff" -> true
else -> true
Expand All @@ -55,7 +54,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
val codeblocks = findAll.filter { block ->
val header = headers.lastOrNull { it.first.endInclusive < block.range.start }
val filename = resolve(root, header?.second ?: "Unknown")
when {
when {
root.toFile().resolve(filename).exists() -> false
block.groupValues[1] == "diff" -> false
else -> true
Expand Down Expand Up @@ -111,12 +110,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
"""
|```diff
|${
DiffUtil.formatDiff(
DiffUtil.generateDiff(
prevCode.lines(),
codeValue.lines()
)
)
IterativePatchUtil.generatePatch(prevCode, codeValue)
}
|```
""".trimMargin(), ui = ui
Expand Down Expand Up @@ -164,7 +158,8 @@ private fun SocketManagerBase.renderDiffBlock(
diffVal: String,
handle: (Map<Path, String>) -> Unit,
ui: ApplicationInterface,
api: API?
api: API?,
watch: Boolean = false,
): String {

val diffTask = ui.newTask(root = false)
Expand All @@ -183,9 +178,6 @@ private fun SocketManagerBase.renderDiffBlock(
val patch2TaskSB = patch2Task.add("")





val filepath = path(root, filename)
val prevCode = load(filepath)
val relativize = try {
Expand All @@ -204,8 +196,7 @@ private fun SocketManagerBase.renderDiffBlock(
var newCode = patch(originalCode, diffVal)



val verifyFwdTabs = if(!newCode.isValid) displayMapInTabs(
val verifyFwdTabs = if (!newCode.isValid) displayMapInTabs(
mapOf(
"Code" to (prevCodeTask?.placeholder ?: ""),
"Preview" to (newCodeTask?.placeholder ?: ""),
Expand Down Expand Up @@ -255,7 +246,7 @@ private fun SocketManagerBase.renderDiffBlock(
applydiffTask.error(null, e)
}
}
if(!newCode.isValid) {
if (!newCode.isValid) {
val fixPatchLink = hrefLink("Fix Patch", classname = "href-link cmd-button") {
try {
val header = fixTask.header("Attempting to fix patch...")
Expand Down Expand Up @@ -302,12 +293,7 @@ private fun SocketManagerBase.renderDiffBlock(
)

val echoDiff = try {
DiffUtil.formatDiff(
DiffUtil.generateDiff(
prevCode.lines(),
newCode.newCode.lines()
)
)
IterativePatchUtil.generatePatch(prevCode, newCode.newCode)
} catch (e: Throwable) {
renderMarkdown("```\n${e.stackTraceToString()}\n```", ui = ui)
}
Expand Down Expand Up @@ -336,7 +322,7 @@ private fun SocketManagerBase.renderDiffBlock(
)
answer = ui.socketManager?.addApplyFileDiffLinks(root, answer, handle, ui, api) ?: answer
header?.clear()
fixTask.complete(answer)
fixTask.complete(renderMarkdown(answer))
} catch (e: Throwable) {
log.error("Error in fix patch", e)
}
Expand Down Expand Up @@ -387,12 +373,7 @@ private fun SocketManagerBase.renderDiffBlock(
if (!isApplied && thisFilehash != filehash) {
val newCode = patch(prevCode, diffVal)
val echoDiff = try {
DiffUtil.formatDiff(
DiffUtil.generateDiff(
prevCode.lines(),
newCode.newCode.lines()
)
)
IterativePatchUtil.generatePatch(prevCode, newCode.newCode)
} catch (e: Throwable) {
renderMarkdown("```\n${e.stackTraceToString()}\n```", ui = ui)
}
Expand Down Expand Up @@ -423,12 +404,7 @@ private fun SocketManagerBase.renderDiffBlock(
diffVal.reverseLines()
).newCode.lines().reversed().joinToString("\n")
val echoDiff2 = try {
DiffUtil.formatDiff(
DiffUtil.generateDiff(
prevCode.lines(),
newCode2.lines(),
)
)
IterativePatchUtil.generatePatch(prevCode, newCode2)
} catch (e: Throwable) {
renderMarkdown("```\n${e.stackTraceToString()}\n```", ui = ui)
}
Expand Down Expand Up @@ -458,15 +434,21 @@ private fun SocketManagerBase.renderDiffBlock(
filehash = thisFilehash
}
}
if (!isApplied) {
if (!isApplied && watch) {
scheduledThreadPoolExecutor.schedule(scheduledFn, 1000, TimeUnit.MILLISECONDS)
}
} catch (e: Throwable) {
log.error("Error in scheduled function", e)
}
}
scheduledThreadPoolExecutor.schedule(scheduledFn, 1000, TimeUnit.MILLISECONDS)
val newValue = mainTabs + "\n" + applydiffTask.placeholder
val newValue = if (newCode.isValid) {
mainTabs + "\n" + applydiffTask.placeholder
} else {
mainTabs + """
<div class="warning">Warning: The patch is not valid. Please fix the patch before applying.</div>
""".trimIndent() + applydiffTask.placeholder
}
return newValue
}

Expand All @@ -476,7 +458,7 @@ private val patch = { code: String, diff: String ->
val isParenthesisBalanced = FileValidationUtils.isParenthesisBalanced(code)
val isQuoteBalanced = FileValidationUtils.isQuoteBalanced(code)
val isSingleQuoteBalanced = FileValidationUtils.isSingleQuoteBalanced(code)
var newCode = IterativePatchUtil.patch(code, diff)
var newCode = IterativePatchUtil.applyPatch(code, diff)
newCode = newCode.replace("\r", "")
val isCurlyBalancedNew = FileValidationUtils.isCurlyBalanced(newCode)
val isSquareBalancedNew = FileValidationUtils.isSquareBalanced(newCode)
Expand Down
Loading

0 comments on commit 96720aa

Please sign in to comment.