Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ver update #123

Open
wants to merge 105 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
54aa648
ver update
acharneski Nov 23, 2024
64a467c
fixes
acharneski Nov 23, 2024
e225e04
Update ClientManager.kt
acharneski Nov 26, 2024
e2f590e
ui v2 prototype
acharneski Nov 26, 2024
11914a0
wip
acharneski Nov 26, 2024
3326715
wip
acharneski Nov 26, 2024
2375b77
fix
acharneski Nov 26, 2024
e34f7be
wip
acharneski Nov 26, 2024
2fe8155
wip
acharneski Nov 26, 2024
9c3619a
wip
acharneski Nov 26, 2024
d094d88
wip
acharneski Nov 27, 2024
d3685fc
wip
acharneski Nov 27, 2024
86524d1
wip
acharneski Nov 27, 2024
23e32e2
wip
acharneski Nov 27, 2024
cc90b5a
wip
acharneski Nov 27, 2024
f35cbac
wip
acharneski Nov 27, 2024
f5721d1
Dingoes!
acharneski Nov 28, 2024
40545b7
egggllooo!
acharneski Nov 28, 2024
8033ba5
wip
acharneski Nov 28, 2024
4b11c27
wip
acharneski Nov 28, 2024
3ede32d
brb
acharneski Nov 28, 2024
d4ce072
wip
acharneski Nov 28, 2024
ac262be
:-)
acharneski Nov 28, 2024
b202e35
knot running
acharneski Nov 29, 2024
7c92913
fix
acharneski Nov 29, 2024
7754bb3
tabs stay
acharneski Nov 29, 2024
4643c57
Update App.css
acharneski Nov 29, 2024
935fad6
prism themes
acharneski Nov 29, 2024
8208247
theme styles
acharneski Nov 29, 2024
2f1b23c
optimize load
acharneski Nov 29, 2024
6aa3df0
wip
acharneski Nov 29, 2024
0696461
wip
acharneski Nov 29, 2024
06f7aab
wip
acharneski Nov 30, 2024
586a30a
cleanup
acharneski Nov 30, 2024
bb51755
wip
acharneski Nov 30, 2024
7751ada
wip
acharneski Nov 30, 2024
151212e
perf fix
acharneski Nov 30, 2024
071d6e2
optimize?
acharneski Nov 30, 2024
a4b2617
etc
acharneski Nov 30, 2024
ddcef95
clean
acharneski Dec 1, 2024
329bbcf
wip
acharneski Dec 1, 2024
d59fed1
updates
acharneski Dec 1, 2024
62caf31
cleanup
acharneski Dec 1, 2024
0f6d859
fix
acharneski Dec 1, 2024
bf79843
Update tabHandling.ts
acharneski Dec 1, 2024
f1e94a0
arf arf
acharneski Dec 1, 2024
9f49953
wip
acharneski Dec 2, 2024
675586d
Update logger.ts
acharneski Dec 2, 2024
93b8039
Update tabHandling.ts
acharneski Dec 2, 2024
66f8fd9
Update tabHandling.ts
acharneski Dec 2, 2024
8f02ac8
Revert "Update tabHandling.ts"
acharneski Dec 2, 2024
f00ec2d
??
acharneski Dec 2, 2024
632f2a4
rev1
acharneski Dec 2, 2024
ff98bfb
rev log
acharneski Dec 2, 2024
ede5b1f
Revert "rev log"
acharneski Dec 2, 2024
0cfc25e
diag and logging
acharneski Dec 2, 2024
3aa6259
wip
acharneski Dec 2, 2024
5088ec0
wip
acharneski Dec 2, 2024
c6a9ff6
wip
acharneski Dec 2, 2024
10eff60
nolog
acharneski Dec 2, 2024
46d5929
themes
acharneski Dec 2, 2024
8a2a0e5
fix
acharneski Dec 2, 2024
097c891
wip
acharneski Dec 3, 2024
85976bd
wip
acharneski Dec 3, 2024
f0cda80
piw
acharneski Dec 3, 2024
8890ecf
wip
acharneski Dec 3, 2024
f8e0705
wip
acharneski Dec 4, 2024
1e353c8
styles
acharneski Dec 4, 2024
0e255e8
webapp
acharneski Dec 4, 2024
2ef9352
menu
acharneski Dec 4, 2024
6e2b056
wip
acharneski Dec 4, 2024
26fb8ee
wip
acharneski Dec 5, 2024
916a246
wip
acharneski Dec 5, 2024
3166c4f
rel
acharneski Dec 5, 2024
ded5602
wip
acharneski Dec 6, 2024
6128bc8
wip
acharneski Dec 7, 2024
88d8dee
wip
acharneski Dec 7, 2024
d81a678
spinner
acharneski Dec 7, 2024
73fe585
wip
acharneski Dec 7, 2024
46bb366
wip
acharneski Dec 7, 2024
66a66d3
wip
acharneski Dec 7, 2024
ddcf5e6
ids
acharneski Dec 7, 2024
174107c
wip
acharneski Dec 7, 2024
c0dff25
input
acharneski Dec 7, 2024
5987b0a
wip
acharneski Dec 8, 2024
e49fe05
wip
acharneski Dec 8, 2024
b3afbec
wip
acharneski Dec 8, 2024
67d0e16
Update SessionTask.kt
acharneski Dec 8, 2024
fc77c1f
fix
acharneski Dec 8, 2024
ddedb2b
Update README.md
acharneski Dec 9, 2024
53cf216
wip
acharneski Dec 10, 2024
22c9179
wip
acharneski Dec 10, 2024
8a29399
Create SingleTaskApp.kt
acharneski Dec 10, 2024
e6e69dd
wip
acharneski Dec 10, 2024
302c6f5
wip
acharneski Dec 12, 2024
583970c
wip
acharneski Dec 12, 2024
3678096
wip
acharneski Dec 12, 2024
78d4343
wip
acharneski Dec 12, 2024
fcb98a2
strings
acharneski Dec 14, 2024
d1c578e
update ui
acharneski Dec 14, 2024
632326f
fixes
acharneski Dec 14, 2024
587e186
wip
acharneski Dec 16, 2024
b8ebc60
wip
acharneski Dec 17, 2024
cf7c678
minor fix
acharneski Dec 20, 2024
e067428
wip
acharneski Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ reports/
build/
.gradle/
.idea/
.*
openai.key
*.log
*.log.*
client_secret_google_oauth.json
settings.gradle.kts
*.data
*.parsed.json
package-lock.json
.kotlin/
19 changes: 0 additions & 19 deletions INTERPRETER_MODULES_DOCUMENTATION.md

This file was deleted.

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.1.12")
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.1.13")
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 @@ -24,7 +24,7 @@ open class CodingActor(
val symbols: Map<String, Any> = mapOf(),
val describer: TypeDescriber = AbbrevWhitelistTSDescriber(
"com.simiacryptus",
"com.github.simiacryptus"
"com.simiacryptus"
),
name: String? = interpreterClass.simpleName,
val details: String? = null,
Expand Down Expand Up @@ -106,10 +106,7 @@ ${details ?: ""}
get() = this.symbols.map { (name, utilityObj) ->
val describe = this.describer.describe(utilityObj.javaClass)
log.info("Describing $name (${utilityObj.javaClass}) in ${describe.length} characters")
"""
$name:
${describe.indent(" ")}
""".trimMargin().trim()
"$name:\n ${describe.indent(" ")}"
}.joinToString("\n")


Expand Down Expand Up @@ -163,8 +160,8 @@ ${details ?: ""}
val blocks = extractTextBlocks(respondWithCode)
val renderedResponse = getRenderedResponse(blocks)
val codedInstruction = codeInterceptor(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())
log.debug("Response: \n\t${renderedResponse.replace("\n", "\n\t", false)}")
log.debug("New Code: \n\t${codedInstruction.replace("\n", "\n\t", false)}")
result = CodeResultImpl(
*messages,
input = input,
Expand Down Expand Up @@ -254,8 +251,8 @@ ${details ?: ""}
val codeBlocks = extractTextBlocks(chat(api, request, model))
val renderedResponse = getRenderedResponse(codeBlocks)
val codedInstruction = codeInterceptor(getCode(language, codeBlocks))
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())
log.debug("Response: \n\t${renderedResponse.replace("\n", "\n\t", false)}")
log.debug("New Code: \n\t${codedInstruction.replace("\n", "\n\t", false)}")
var workingCode = codedInstruction
var workingRenderedResponse = renderedResponse
for (fixAttempt in 0..input.fixIterations) {
Expand Down Expand Up @@ -286,16 +283,8 @@ ${TT}
val codeBlocks = extractTextBlocks(respondWithCode)
workingRenderedResponse = getRenderedResponse(codeBlocks)
workingCode = codeInterceptor(getCode(language, codeBlocks))
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())
log.debug("Response: \n\t" + workingRenderedResponse.replace("\n", "\n\t", false))
log.debug("New Code: \n\t${workingCode.replace("\n", "\n\t", false)}")
}
}
} catch (ex: FailedToImplementException) {
Expand Down Expand Up @@ -424,7 +413,7 @@ Correct the code and try again.
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
} else {
""
}
Expand Down Expand Up @@ -487,13 +476,11 @@ Correct the code and try again.
}

fun errorMessage(ex: ScriptException, code: String) = try {
"""
|${TT}text
|${ex.message ?: ""} at line ${ex.lineNumber} column ${ex.columnNumber}
| ${if (ex.lineNumber > 0) code.split("\n")[ex.lineNumber - 1] else ""}
| ${if (ex.columnNumber > 0) " ".repeat(ex.columnNumber - 1) + "^" else ""}
|${TT}
""".trimMargin().trim()
"${TT}text\n${ex.message ?: ""} at line ${ex.lineNumber} column ${ex.columnNumber}\n ${if (ex.lineNumber > 0) code.split("\n")[ex.lineNumber - 1] else ""}\n ${
if (ex.columnNumber > 0) " ".repeat(
ex.columnNumber - 1
) + "^" else ""
}\n${TT}".trim()
} catch (_: Exception) {
ex.message ?: ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ open class ImageActor(
temperature: Double = 0.3,
val width: Int = 1024,
val height: Int = 1024,
var openAI: OpenAIClient? = null,
) : BaseActor<List<String>, ImageResponse>(
prompt = prompt,
name = name,
Expand Down Expand Up @@ -78,7 +79,7 @@ open class ImageActor(
api = api
).choices.first().message?.content ?: throw RuntimeException("No response")
}
return ImageResponseImpl(text, api = this.openAI!!)
return ImageResponseImpl(text, api = this.openAI ?: throw RuntimeException("No API"))
}

override fun withModel(model: ChatModel): ImageActor = ImageActor(
Expand All @@ -89,9 +90,9 @@ open class ImageActor(
temperature = temperature,
width = width,
height = height,
openAI = openAI
)

var openAI: OpenAIClient? = null
fun setImageAPI(openAI: OpenAIClient): ImageActor {
this.openAI = openAI
return this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.simiacryptus.skyenet.core.actors

import com.google.common.base.Strings.commonPrefix
import com.simiacryptus.jopenai.API
import com.simiacryptus.jopenai.models.ApiModel
import com.simiacryptus.jopenai.models.ApiModel.Role
import com.simiacryptus.jopenai.models.ChatModel
import com.simiacryptus.jopenai.models.OpenAIModels
import com.simiacryptus.jopenai.models.TextModel
import com.simiacryptus.jopenai.util.ClientUtil.toChatMessage
import com.simiacryptus.jopenai.util.ClientUtil.toContentList

/**
Expand All @@ -13,100 +16,127 @@ import com.simiacryptus.jopenai.util.ClientUtil.toContentList
* then recursively expands the result by searching for the pattern and making additional LLM calls.
*/
class LargeOutputActor(
prompt: String = """
When generating large responses, please:
1. Break down the content into logical sections
2. Use named ellipsis markers like '...sectionName...' to indicate where content needs expansion
3. Keep each section focused and concise
4. Use descriptive section names that reflect the content

## Example format:

```markdown
# Topic Title
## Overview
Here's an overview of the topic ...introduction...
## Main Points
The first important aspect is ...mainPoints...
## Technical Details
For technical details, ...technicalDetails...
## Conclusion
To conclude, ...conclusion...
```

Note: Each '...sectionName...' will be expanded in subsequent iterations.
prompt: String = """
You are a long-form content writer. You have been tasked with writing a comprehensive guide on a topic.
1. Break down the content into logical sections using markdown formatting and headers.
2. To support large content generation, use markers to indicate where content needs expansion.
3. Expansion markers should use a line formatted like '...sectionName...' to indicate where detailed content should be inserted.
4. Use descriptive and unique section names that reflect the content expected in that section.
5. For the initial iteration, provide a high level document structure with a few expansion markers. Each '...sectionName...' will be expanded in subsequent iterations.
""".trimIndent(),
name: String? = null,
model: TextModel = OpenAIModels.GPT4o,
temperature: Double = 0.3,
private val maxIterations: Int = 5,
private val ellipsisPattern: Regex = Regex("\\.\\.\\."),
private val namedEllipsisPattern: Regex = Regex("""\.\.\.(?<sectionName>[\w\s]+)\.\.\.""")
name: String? = null,
model: TextModel = OpenAIModels.GPT4o,
temperature: Double = 0.3, private val maxIterations: Int = 3, private val namedEllipsisPattern: Regex = Regex("""\.\.\.(?<sectionName>[\w\s-_]+?)\.\.\.""")
) : BaseActor<List<String>, String>(
prompt = prompt,
name = name,
model = model,
temperature = temperature
prompt = prompt, name = name, model = model, temperature = temperature
) {

override fun chatMessages(questions: List<String>): Array<ApiModel.ChatMessage> {
val systemMessage = ApiModel.ChatMessage(
role = ApiModel.Role.system,
content = prompt.toContentList()
override fun chatMessages(questions: List<String>): Array<ApiModel.ChatMessage> {
val systemMessage = ApiModel.ChatMessage(
role = Role.system, content = prompt.toContentList()
)
val userMessages = questions.map {
ApiModel.ChatMessage(
role = Role.user, content = it.toContentList()
)
}
return arrayOf(systemMessage) + userMessages
}

override fun respond(input: List<String>, api: API, vararg messages: ApiModel.ChatMessage): String {
var accumulatedResponse = ""
var iterations = 0
while (iterations < maxIterations) {
if (accumulatedResponse.isEmpty()) {
accumulatedResponse = response(*messages, api = api).choices.first().message?.content?.trim() ?: throw RuntimeException("No response from LLM")
}
val matches = namedEllipsisPattern.findAll(accumulatedResponse).toMutableList()
if (matches.isEmpty()) break
val pairs = matches.mapNotNull { matchResult ->
val nextSection = matchResult.groups["sectionName"]?.value ?: return@mapNotNull null
val contextLines = 100
val contextChars = 10000
Pair(
matchResult, response(
*(listOf(
"""
You are a long-form content writer. You have been tasked with writing a comprehensive guide on a topic by filling in a detail section.
1. Break down the content into logical sections using markdown formatting and headers.
2. To support large content generation, use markers to indicate where content needs expansion.
3. Expansion markers should use a line formatted like '...sectionName...' to indicate where detailed content should be inserted.
4. Use descriptive and unique section names that reflect the content expected in that section.
""".trimIndent().toChatMessage(Role.system)
) + messages.toList().drop(1) + listOf(
ApiModel.ChatMessage(
role = Role.user, content = ("""
Previous context:

```
""".trimIndent() + accumulatedResponse.substring(0, matchResult.range.first).lines().takeLast(contextLines).joinToString { " $it" }.takeLast(contextChars) + """
```

Continue the section '""".trimIndent() + nextSection + """'
Make sure the response flows naturally with the existing content.
It should end so that it matches the next section, provided below:

```
""".trimIndent() + accumulatedResponse.substring(matchResult.range.last).lines().take(contextLines).joinToString { " $it" }.take(contextChars) + """
```
""".trimIndent()).toContentList()
)
)).toTypedArray(), api = api
)
)
val userMessages = questions.map {
ApiModel.ChatMessage(
role = ApiModel.Role.user,
content = it.toContentList()
)
}
accumulatedResponse = pairs.reversed().fold(accumulatedResponse) { acc, (match, response) ->
val original = response.choices.first().message?.content?.trim() ?: ""
var replacement = original
if (replacement.isEmpty()) return acc
//val replaced = acc.substring(match.range)
if (replacement.startsWith("```")) {
replacement = replacement.lines().drop(1).reversed().dropWhile { !it.startsWith("```") }.drop(1).reversed().joinToString("\n")
}
return arrayOf(systemMessage) + userMessages
val prefix = acc.substring(0, match.range.first)
val suffix = acc.substring(match.range.last)
val commonPrefix = commonPrefix(prefix, replacement)
if (commonPrefix.isNotBlank() && commonPrefix.contains('\n')) replacement = replacement.substring(commonPrefix.length)
val largestCommonSubstring = largestCommonSubstring(replacement, suffix)
if (largestCommonSubstring.isNotBlank()) replacement = replacement.substring(0, replacement.indexOf(largestCommonSubstring))
val replaceRange = acc.replaceRange(match.range, replacement)
replaceRange
}
iterations++
}
return accumulatedResponse
}

override fun respond(input: List<String>, api: API, vararg messages: ApiModel.ChatMessage): String {
var accumulatedResponse = ""
var currentMessages = messages.toList()
var iterations = 0
override fun withModel(model: ChatModel): LargeOutputActor {
return LargeOutputActor(
prompt = this.prompt,
name = this.name,
model = model,
temperature = this.temperature,
maxIterations = this.maxIterations,
namedEllipsisPattern = this.namedEllipsisPattern
)
}
}

while (iterations < maxIterations) {
val response = response(*currentMessages.toTypedArray(), api = api).choices.first().message?.content
?: throw RuntimeException("No response from LLM")

accumulatedResponse += response.trim()

val matches = namedEllipsisPattern.findAll(response).mapNotNull { it.groups["sectionName"]?.value }.toList()
if (matches.isNotEmpty()) {
// Identify the pattern after the ellipsis to continue
val continuationRequests = matches.map { name ->
"Continue the section '$name' by expanding the ellipsis."
}
currentMessages = continuationRequests.map { request ->
ApiModel.ChatMessage(
role = ApiModel.Role.user,
content = request.toContentList()
)
}
iterations++
} else {
break
}
fun largestCommonSubstring(a: String, b: String): String {
val lengths = Array(a.length + 1) { IntArray(b.length + 1) }
var z = 0
var ret = ""
for (i in 0 until a.length) {
for (j in 0 until b.length) {
if (a[i] == b[j]) {
lengths[i + 1][j + 1] = lengths[i][j] + 1
val len = lengths[i + 1][j + 1]
if (len > z) {
z = len
ret = a.substring(i - z + 1, i + 1)
}

if (iterations == maxIterations && namedEllipsisPattern.containsMatchIn(accumulatedResponse)) {
throw RuntimeException("Maximum iterations reached. Output may be incomplete.")
}

return accumulatedResponse
}

override fun withModel(model: ChatModel): LargeOutputActor {
return LargeOutputActor(
prompt = this.prompt,
name = this.name,
model = model,
temperature = this.temperature,
maxIterations = this.maxIterations,
ellipsisPattern = this.ellipsisPattern
)
}
}
}
return ret
}
Loading
Loading