Skip to content

Commit

Permalink
1.0.45 (#50)
Browse files Browse the repository at this point in the history
* S3 archival prototype

* perms

* Update SessionShareServlet.kt

* add jsoup

* Update SessionShareServlet.kt

* Update SessionShareServlet.kt

* Update SessionShareServlet.kt

* Update SessionShareServlet.kt

* Masked settings, class-based selenium exporter

* wip

* wip

* Update Selenium2S3.kt

* wip

* rm kotlin-hack

* wip

* wip

* wip

* Update BashInterpreter.kt

* coding agents

* etc

* sasss

* themes

* Update SessionTask.kt

* colors improved

* wip
  • Loading branch information
acharneski authored Jan 12, 2024
1 parent 9ef93c5 commit 63b4033
Show file tree
Hide file tree
Showing 69 changed files with 1,881 additions and 3,556 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.44</version>
<version>1.0.45</version>
</dependency>
```

Gradle:

```groovy
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.44'
implementation group: 'com.simiacryptus', name: 'skyenet', version: '1.0.45'
```

```kotlin
implementation("com.simiacryptus:skyenet:1.0.44")
implementation("com.simiacryptus:skyenet:1.0.45")
```

### 🌟 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 @@ -32,7 +32,7 @@ val jackson_version = "2.15.3"

dependencies {

implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.42")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.0.43")

implementation(group = "org.slf4j", name = "slf4j-api", version = "2.0.9")
implementation(group = "commons-io", name = "commons-io", version = "2.15.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.skyenet.core.actors.record.CodingActorInterceptor
import com.simiacryptus.skyenet.core.actors.record.ImageActorInterceptor
import com.simiacryptus.skyenet.core.actors.record.ParsedActorInterceptor
import com.simiacryptus.skyenet.core.actors.record.SimpleActorInterceptor
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
Expand All @@ -28,6 +25,7 @@ open class ActorSystem<T:Enum<*>>(
is ParsedActor<*> -> ParsedActorInterceptor(baseActor, wrapper)
is CodingActor -> CodingActorInterceptor(baseActor, wrapper)
is ImageActor -> ImageActorInterceptor(baseActor, wrapper)
is TextToSpeechActor -> TextToSpeechActorInterceptor(baseActor, wrapper)
else -> throw RuntimeException("Unknown actor type: ${baseActor.javaClass}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel.*
import com.simiacryptus.jopenai.ClientUtil.toContentList
import com.simiacryptus.jopenai.util.ClientUtil.toContentList
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.skyenet.core.Interpreter
import com.simiacryptus.skyenet.interpreter.Interpreter
import com.simiacryptus.skyenet.core.OutputInterceptor
import java.util.*
import javax.script.ScriptException
Expand Down Expand Up @@ -51,6 +51,7 @@ open class CodingActor(
val code: String
val status: Status
val result: ExecutionResult
val renderedResponse: String?
}

data class ExecutionResult(
Expand All @@ -60,9 +61,10 @@ open class CodingActor(

override val prompt: String
get() = if (symbols.isNotEmpty()) """
|You will translate natural language instructions into
|an implementation using ${language} and the script context.
|Use ``` code blocks labeled with ${language} where appropriate.
|You are a coding assistant allows users actions to be enacted using $language and the script context.
|Your role is to translate natural language instructions into code as well as interpret the results and converse with the user.
|Use ``` code blocks labeled with $language where appropriate. (i.e. ```$language)
|Each response should have EXACTLY ONE code block. Do not use inline blocks.
|
|Defined symbols include {${symbols.keys.joinToString(", ")}} described below:
|
Expand All @@ -73,9 +75,10 @@ open class CodingActor(
|${details ?: ""}
|""".trimMargin().trim()
else """
|You will translate natural language instructions into
|an implementation using ${language} and the script context.
|Use ``` code blocks labeled with ${language} where appropriate.
|You are a coding assistant allows users actions to be enacted using $language and the script context.
|Your role is to translate natural language instructions into code as well as interpret the results and converse with the user.
|Use ``` code blocks labeled with $language where appropriate. (i.e. ```$language)
|Each response should have EXACTLY ONE code block. Do not use inline blocks.
|
|${details ?: ""}
|""".trimMargin().trim()
Expand Down Expand Up @@ -117,7 +120,11 @@ open class CodingActor(
input: CodeRequest,
api: API,
): CodeResult {
var result = CodeResultImpl(*messages, api = (api as OpenAIClient), input = input)
var result = CodeResultImpl(
*messages,
input = input,
api = (api as OpenAIClient)
)
if (!input.autoEvaluate) return result
for (i in 0..input.fixIterations) try {
require(result.result.resultValue.length > -1)
Expand All @@ -132,19 +139,25 @@ open class CodingActor(
throw ex
}
val respondWithCode = fixCommand(api, result.code, ex, *messages, model = model)
val codeBlocks = extractCodeBlocks(respondWithCode)
val renderedResponse = getRenderedResponse(codeBlocks)
val codedInstruction = getCode(language, codeBlocks)
log.info("Response: \n\t${renderedResponse.replace("\n", "\n\t", false)}".trimMargin())
log.info("New Code: \n\t${codedInstruction.replace("\n", "\n\t", false)}".trimMargin())
result = CodeResultImpl(*messages, input = input, api = api, givenCode = codedInstruction)
val blocks = extractTextBlocks(respondWithCode)
val renderedResponse = getRenderedResponse(blocks)
val codedInstruction = getCode(language, blocks)
log.debug("Response: \n\t${renderedResponse.replace("\n", "\n\t", false)}".trimMargin())
log.debug("New Code: \n\t${codedInstruction.replace("\n", "\n\t", false)}".trimMargin())
result = CodeResultImpl(
*messages,
input = input,
api = api,
givenCode = codedInstruction,
givenResponse = renderedResponse
)
}
throw IllegalStateException()
}

open fun execute(prefix: String, code: String): ExecutionResult {
//language=HTML
log.info("Running $code")
log.debug("Running $code")
OutputInterceptor.clearGlobalOutput()
val result = try {
interpreter.run((prefix + code).sortCode())
Expand All @@ -156,19 +169,21 @@ open class CodingActor(
message = errorMessage(e, code),
language = language,
code = code,
prefix = prefix
prefix = prefix,
)

e.cause is ScriptException -> throw FailedToImplementException(
cause = e,
message = errorMessage(e.cause!! as ScriptException, code),
language = language,
code = code,
prefix = prefix
prefix = prefix,
)

else -> throw e
}
}
log.info("Result: $result")
log.debug("Result: $result")
//language=HTML
val executionResult = ExecutionResult(result.toString(), OutputInterceptor.getThreadOutput())
OutputInterceptor.clearThreadOutput()
Expand All @@ -180,80 +195,87 @@ open class CodingActor(
private val input: CodeRequest,
private val api: OpenAIClient,
private val givenCode: String? = null,
private val givenResponse: String? = null,
) : CodeResult {
var _status = CodeResult.Status.Coding

override val status get() = _status

override val code: String = givenCode ?: try {
private val implementation by lazy {
if (!givenCode.isNullOrBlank() && !givenResponse.isNullOrBlank()) (givenCode to givenResponse) else try {
implement(model)
} catch (ex: FailedToImplementException) {
if (fallbackModel != model) {
try {
implement(fallbackModel)
} catch (ex: FailedToImplementException) {
log.info("Failed to implement ${messages.map { it.content }.joinToString("\n")}")
log.debug("Failed to implement ${messages.map { it.content }.joinToString("\n")}")
_status = CodeResult.Status.Failure
throw ex
}
} else {
log.info("Failed to implement ${messages.map { it.content }.joinToString("\n")}")
log.debug("Failed to implement ${messages.map { it.content }.joinToString("\n")}")
_status = CodeResult.Status.Failure
throw ex
}
}
}

var _status = CodeResult.Status.Coding

override val status get() = _status

override val renderedResponse: String = givenResponse ?: implementation.second
override val code: String = givenCode ?: implementation.first

private fun implement(
model: ChatModels,
): String {
): Pair<String, String> {
val request = ChatRequest(messages = ArrayList(this.messages.toList()))
for (codingAttempt in 0..input.fixRetries) {
try {
val codeBlocks = extractCodeBlocks(chat(api, request, model))
val codeBlocks = extractTextBlocks(chat(api, request, model))
val renderedResponse = getRenderedResponse(codeBlocks)
val codedInstruction = getCode(language, codeBlocks)
log.info("Response: \n\t${renderedResponse.replace("\n", "\n\t", false)}".trimMargin())
log.info("New Code: \n\t${codedInstruction.replace("\n", "\n\t", false)}".trimMargin())
log.debug("Response: \n\t${renderedResponse.replace("\n", "\n\t", false)}".trimMargin())
log.debug("New Code: \n\t${codedInstruction.replace("\n", "\n\t", false)}".trimMargin())
var workingCode = codedInstruction
var workingRenderedResponse = renderedResponse
for (fixAttempt in 0..input.fixIterations) {
try {
val validate = interpreter.validate((input.codePrefix + "\n" + workingCode).sortCode())
if (validate != null) throw validate
log.info("Validation succeeded")
log.debug("Validation succeeded")
_status = CodeResult.Status.Success
return workingCode
return workingCode to workingRenderedResponse
} catch (ex: Throwable) {
if (fixAttempt == input.fixIterations)
throw if(ex is FailedToImplementException) ex else FailedToImplementException(
cause = ex,
message = """
throw if (ex is FailedToImplementException) ex else FailedToImplementException(
cause = ex,
message = """
|**ERROR**
|
|```text
|${ex.message}
|```
|""".trimMargin().trim(),
language = language,
code = workingCode,
prefix = input.codePrefix
)
log.info("Validation failed - ${ex.message}")
language = language,
code = workingCode,
renderedResponse = workingRenderedResponse,
prefix = input.codePrefix
)
log.debug("Validation failed - ${ex.message}")
_status = CodeResult.Status.Correcting
val respondWithCode = fixCommand(api, workingCode, ex, *messages, model = model)
val codeBlocks = extractCodeBlocks(respondWithCode)
val response = getRenderedResponse(codeBlocks)
val codeBlocks = extractTextBlocks(respondWithCode)
workingRenderedResponse = getRenderedResponse(codeBlocks)
workingCode = getCode(language, codeBlocks)
log.info("Response: \n\t${response.replace("\n", "\n\t", false)}".trimMargin())
log.info("New Code: \n\t${workingCode.replace("\n", "\n\t", false)}".trimMargin())
log.debug("Response: \n\t${workingRenderedResponse.replace("\n", "\n\t", false)}".trimMargin())
log.debug("New Code: \n\t${workingCode.replace("\n", "\n\t", false)}".trimMargin())
}
}
} catch (ex: FailedToImplementException) {
if (codingAttempt == input.fixRetries) {
log.info("Failed to implement ${messages.map { it.content }.joinToString("\n")}")
log.debug("Failed to implement ${messages.map { it.content }.joinToString("\n")}")
throw ex
}
log.info("Retry failed to implement ${messages.map { it.content }.joinToString("\n")}")
log.debug("Retry failed to implement ${messages.map { it.content }.joinToString("\n")}")
_status = CodeResult.Status.Correcting
}
}
Expand Down Expand Up @@ -325,7 +347,7 @@ open class CodingActor(

fun String.indent(indent: String = " ") = this.replace("\n", "\n$indent")

fun extractCodeBlocks(response: String): List<Pair<String, String>> {
fun extractTextBlocks(response: String): List<Pair<String, String>> {
val codeBlockRegex = Regex("(?s)```(.*?)\\n(.*?)```")
val languageRegex = Regex("([a-zA-Z0-9-_]+)")

Expand Down Expand Up @@ -360,34 +382,20 @@ open class CodingActor(
return result
}

fun getRenderedResponse(respondWithCode: List<Pair<String, String>>) =
fun getRenderedResponse(respondWithCode: List<Pair<String, String>>, defaultLanguage: String = "") =
respondWithCode.joinToString("\n") {
var language = it.first
if (language == "code") language = "groovy"
if (language == "text") {
//language=HTML
"""
|<div>
|${it.second}
|</div>
|""".trimMargin().trim()
} else {
//language=HTML
"""
|<pre><code class="language-$language">
|${it.second}
|</code></pre>
|""".trimMargin().trim()
when (it.first) {
"code" -> "```$defaultLanguage\n${it.second}\n```"
"text" -> it.second
else -> "```${it.first}\n${it.second}\n```"
}
}

fun getCode(language: String, textSegments: List<Pair<String, String>>): String {
if (textSegments.size == 1) return textSegments.joinToString("\n") { it.second }
return textSegments.joinToString("\n") {
if (it.first.lowercase() == "code" || it.first.lowercase() == language.lowercase()) {
"""
|${it.second}
|""".trimMargin().trim()
it.second.trimMargin().trim()
} else {
""
}
Expand Down Expand Up @@ -468,5 +476,6 @@ open class CodingActor(
val language: String? = null,
val code: String? = null,
val prefix: String? = null,
val renderedResponse: String? = null,
) : RuntimeException(message, cause)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.ApiModel.ChatMessage
import com.simiacryptus.jopenai.ApiModel.ImageGenerationRequest
import com.simiacryptus.jopenai.ClientUtil.toChatMessage
import com.simiacryptus.jopenai.ClientUtil.toContentList
import com.simiacryptus.jopenai.util.ClientUtil.toChatMessage
import com.simiacryptus.jopenai.util.ClientUtil.toContentList
import com.simiacryptus.jopenai.GPT4Tokenizer
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.models.ChatModels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.ClientUtil.toContentList
import com.simiacryptus.jopenai.util.ClientUtil.toContentList
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.models.ChatModels
import com.simiacryptus.jopenai.proxy.ChatProxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.simiacryptus.skyenet.core.actors

import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.ApiModel
import com.simiacryptus.jopenai.ClientUtil.toContentList
import com.simiacryptus.jopenai.util.ClientUtil.toContentList
import com.simiacryptus.jopenai.models.ChatModels

open class SimpleActor(
Expand Down
Loading

0 comments on commit 63b4033

Please sign in to comment.