Calculate the median prime number from the range 1-1000
\n
\nfun main() {\n val primeNumbers = mutableListOf<Int>()\n \n for (number in 1..1000) {\n if (isPrime(number)) {\n primeNumbers.add(number)\n }\n }\n \n primeNumbers.sort()\n \n val median = if (primeNumbers.size % 2 == 0) {\n val middleIndex = primeNumbers.size / 2\n (primeNumbers[middleIndex - 1] + primeNumbers[middleIndex]) / 2.0\n } else {\n primeNumbers[primeNumbers.size / 2].toDouble()\n }\n \n println("The median prime number from the range 1-1000 is: $median")\n}\n\nfun isPrime(number: Int): Boolean {\n if (number <= 1) {\n return false\n }\n \n for (i in 2 until number) {\n if (number % i == 0) {\n return false\n }\n }\n \n return true\n}\n\n
11:34:55.431 [pool-12-thread-1] INFO c.s.skyenet.heart.KotlinInterpreter - Running:\n fun main() {\n\t val primeNumbers = mutableListOf()\n\t \n\t for (number in 1..1000) {\n\t if (isPrime(number)) {\n\t primeNumbers.add(number)\n\t }\n\t }\n\t \n\t primeNumbers.sort()\n\t \n\t val median = if (primeNumbers.size % 2 == 0) {\n\t val middleIndex = primeNumbers.size / 2\n\t (primeNumbers[middleIndex - 1] + primeNumbers[middleIndex]) / 2.0\n\t } else {\n\t primeNumbers[primeNumbers.size / 2].toDouble()\n\t }\n\t \n\t println(\"The median prime number from the range 1-1000 is: $median\")\n\t}\n\t\n\tfun isPrime(number: Int): Boolean {\n\t if (number <= 1) {\n\t return false\n\t }\n\t \n\t for (i in 2 until number) {\n\t if (number % i == 0) {\n\t return false\n\t }\n\t }\n\t \n\t return true\n\t}\n\n11:35:04.395 [pool-12-thread-1] INFO c.s.skyenet.actors.CodingActor - Result: null\n
"
\ No newline at end of file
diff --git a/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/hvlauy.json b/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/hvlauy.json
new file mode 100644
index 00000000..625e334a
--- /dev/null
+++ b/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/hvlauy.json
@@ -0,0 +1 @@
+"
This is the last message
\n
Isthay isay ethay astlay essagemay
\n
"
\ No newline at end of file
diff --git a/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/nakgfp.json b/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/nakgfp.json
new file mode 100644
index 00000000..5927441b
--- /dev/null
+++ b/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/nakgfp.json
@@ -0,0 +1 @@
+"
"
\ No newline at end of file
diff --git a/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/ozicdd.json b/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/ozicdd.json
new file mode 100644
index 00000000..1fcdddeb
--- /dev/null
+++ b/.skynet/SimpleActorTest_SimpleActor/20231111/35e2c6c5/messages/ozicdd.json
@@ -0,0 +1 @@
+"
I wish to have a longer conversation
\n
Ishway otay avehay alay ongerlay onversationcay
\n
"
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 1b73fa84..1adb7935 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -25,10 +25,10 @@ repositories {
val kotlin_version = "1.9.20"
val jetty_version = "11.0.15"
val slf4j_version = "2.0.9"
-val skyenet_version = "1.0.23"
+val skyenet_version = "1.0.24"
dependencies {
- implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.25")
+ implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.26")
implementation(group = "com.simiacryptus.skyenet", name = "core", version = skyenet_version)
implementation(group = "com.simiacryptus.skyenet", name = "webui", version = skyenet_version)
diff --git a/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy b/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy
index 27e8ea4c..9b0eb479 100644
--- a/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy
+++ b/src/main/groovy/com/github/simiacryptus/aicoder/actions/code/GenerateProjectAction.groovy
@@ -22,7 +22,7 @@ import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
class GenerateProjectAction extends FileContextAction {
- static Logger logger = LoggerFactory.getLogger(GenerateProjectAction.class)
+ static Logger log = LoggerFactory.getLogger(GenerateProjectAction.class)
GenerateProjectAction() {
@@ -326,7 +326,7 @@ class GenerateProjectAction extends FileContextAction {
)
// def progressVal = currentDraft.incrementAndGet().toDouble() / totalDrafts
// progress(progressVal)
-// logger.info("Progress: $progressVal")
+// log.info("Progress: $progressVal")
return new Pair(file.location, implement)
}
})
@@ -371,7 +371,7 @@ class GenerateProjectAction extends FileContextAction {
)
// def progressVal = currentDraft.incrementAndGet().toDouble() / totalDrafts
// progress(progressVal)
-// logger.info("Progress: $progressVal")
+// log.info("Progress: $progressVal")
return new Pair(file.location, implement)
}
})
@@ -418,7 +418,7 @@ class GenerateProjectAction extends FileContextAction {
)
// def progressVal = currentDraft.incrementAndGet().toDouble() / totalDrafts
// progress(progressVal)
-// logger.info("Progress: $progressVal")
+// log.info("Progress: $progressVal")
return new Pair(file.location, implement)
}
})
@@ -522,20 +522,20 @@ class GenerateProjectAction extends FileContextAction {
entries.each { file, sourceCode ->
def relative = trimStart(trimEnd(file.file, '/'), ['/', '.']) ?: ""
if (new File(relative).isAbsolute()) {
- logger.warn("Invalid path: $relative")
+ log.warn("Invalid path: $relative")
} else {
def outFile = new File(outputDir, relative)
outFile.parentFile.mkdirs()
def best = sourceCode.max { it.code.length() }
outFile.text = best.code
- logger.debug("Wrote ${outFile.canonicalPath} (Resolved from $relative)")
+ log.debug("Wrote ${outFile.canonicalPath} (Resolved from $relative)")
generatedFiles << outFile
if (config.saveAlternates)
sourceCode.findAll { it != best }.eachWithIndex { alternate, index ->
def outFileAlternate = new File(outputDir, relative + ".${index + 1}")
outFileAlternate.parentFile.mkdirs()
outFileAlternate.text = alternate.code
- logger.debug("Wrote ${outFileAlternate.canonicalPath} (Resolved from $relative)")
+ log.debug("Wrote ${outFileAlternate.canonicalPath} (Resolved from $relative)")
generatedFiles << outFileAlternate
}
}
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/AppServer.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/AppServer.kt
index 350b22be..a7546105 100644
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/AppServer.kt
+++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/AppServer.kt
@@ -4,7 +4,7 @@ import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
-import com.simiacryptus.skyenet.body.WebSocketServer
+import com.simiacryptus.skyenet.webui.WebSocketServer
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.handler.ContextHandlerCollection
import org.eclipse.jetty.webapp.WebAppContext
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt
index 89206975..70d6a7b4 100644
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt
+++ b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/CodeChatServer.kt
@@ -3,7 +3,7 @@ package com.github.simiacryptus.aicoder.actions.dev
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.intellij.openapi.project.Project
import com.simiacryptus.openai.OpenAIClient
-import com.simiacryptus.skyenet.body.*
+import com.simiacryptus.skyenet.webui.*
import org.eclipse.jetty.util.resource.Resource
class CodeChatServer(
@@ -43,7 +43,7 @@ rootMessageTrail =
messages += OpenAIClient.ChatMessage(OpenAIClient.ChatMessage.Role.user, userMessage)
val response = api.chat(chatRequest, model).choices.first()?.message?.content.orEmpty()
messages += OpenAIClient.ChatMessage(OpenAIClient.ChatMessage.Role.assistant, response)
- messageTrail += ChatSessionFlexmark.renderMarkdown(response)
+ messageTrail += MarkdownUtil.renderMarkdown(response)
send(messageTrail)
}
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/LaunchSkyenetAction.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/LaunchSkyenetAction.kt
deleted file mode 100644
index 975d39c8..00000000
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/LaunchSkyenetAction.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
-
-package com.github.simiacryptus.aicoder.actions.dev
-
-import com.github.simiacryptus.aicoder.actions.BaseAction
-import com.github.simiacryptus.aicoder.config.AppSettingsState
-import com.github.simiacryptus.aicoder.util.UITools
-import com.intellij.openapi.actionSystem.AnActionEvent
-import com.intellij.openapi.project.Project
-import com.intellij.openapi.vfs.VirtualFile
-import com.simiacryptus.util.describe.Description
-import java.awt.Desktop
-import java.util.UUID
-
-class LaunchSkyenetAction : BaseAction() {
-
- override fun isEnabled(event: AnActionEvent): Boolean {
- return isEnabled()
- }
-
- interface TestTools {
- fun getProject(): Project
- fun getSelectedFolder(): VirtualFile
-
- @Description("Prints to script output")
- fun print(msg: String): Unit
- }
-
- override fun handle(e: AnActionEvent) {
- val project = e.project!!
- val selectedFolder = UITools.getSelectedFolder(e)!!
- val server = AppServer.getServer(e.project)
- val uuid = UUID.randomUUID().toString()
- server.addApp("/$uuid", SkyenetProjectCodingSessionServer(project, selectedFolder))
- Thread {
- Thread.sleep(500)
- try {
- Desktop.getDesktop().browse(server.server.uri.resolve("/$uuid/index.html"))
- } catch (e: Throwable) {
- log.warn("Error opening browser", e)
- }
- }.start()
- }
-
- private fun isEnabled(): Boolean {
- if (UITools.isSanctioned()) return false
- return AppSettingsState.instance.devActions
- }
-
- companion object {
- }
-
-}
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/SkyenetProjectCodingSessionServer.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/SkyenetProjectCodingSessionServer.kt
deleted file mode 100644
index b1703fba..00000000
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/SkyenetProjectCodingSessionServer.kt
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.github.simiacryptus.aicoder.actions.dev
-
-import com.github.simiacryptus.aicoder.config.AppSettingsState
-import com.github.simiacryptus.aicoder.util.UITools
-import com.intellij.openapi.project.Project
-import com.intellij.openapi.vfs.VirtualFile
-import com.simiacryptus.skyenet.Heart
-import com.simiacryptus.skyenet.OutputInterceptor
-import com.simiacryptus.skyenet.body.ClasspathResource
-import com.simiacryptus.skyenet.util.SessionServerUtil.asJava
-import com.simiacryptus.skyenet.body.SkyenetCodingSessionServer
-import com.simiacryptus.skyenet.heart.WeakGroovyInterpreter
-import org.eclipse.jetty.util.resource.Resource
-import java.util.Map
-import java.util.function.Supplier
-
-class SkyenetProjectCodingSessionServer(
- val project: Project,
- val selectedFolder: VirtualFile
-) : SkyenetCodingSessionServer(
- applicationName = "IdeaAgent",
- model = AppSettingsState.instance.defaultChatModel(),
- apiKey = AppSettingsState.instance.apiKey
-) {
- override val baseResource: Resource
- get() = ClasspathResource(javaClass.classLoader.getResource(resourceBase))
-
- override fun hands() = Map.of(
- "ide",
- object : LaunchSkyenetAction.TestTools {
- override fun getProject(): Project {
- return project
- }
-
- override fun getSelectedFolder(): VirtualFile {
- return selectedFolder
- }
-
- val toolStream =
- OutputInterceptor.createInterceptorStream(
- System.out
- //PrintStream(NullOutputStream.NULL_OUTPUT_STREAM)
- )
-
- override fun print(msg: String) {
- toolStream.println(msg)
- }
- } as Object,
- ).asJava
-
- override fun toString(e: Throwable): String {
- return e.message ?: e.toString()
- }
-
- override fun heart(hands: Map): Heart = object : WeakGroovyInterpreter(hands) {
- override fun wrapExecution(fn: Supplier): T? {
- return UITools.run(
- project, "Running Script", false
- ) {
- fn.get()
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/config/AppSettingsState.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/config/AppSettingsState.kt
index c4e270b7..95934c30 100644
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/config/AppSettingsState.kt
+++ b/src/main/kotlin/com/github/simiacryptus/aicoder/config/AppSettingsState.kt
@@ -13,14 +13,13 @@ import java.util.*
class SimpleEnvelope(var value: String? = null)
-@Suppress("MemberVisibilityCanBePrivate")
@State(name = "org.intellij.sdk.settings.AppSettingsState", storages = [Storage("SdkSettingsPlugin.xml")])
class AppSettingsState : PersistentStateComponent {
val listeningPort: Int = 8081
val listeningEndpoint: String = "localhost"
val modalTasks: Boolean = false
var suppressErrors: Boolean = false
- var apiLog: Boolean = false
+ private var apiLog: Boolean = false
var apiBase = "https://api.openai.com/v1"
var apiKey = ""
var temperature = 0.1
@@ -33,7 +32,7 @@ class AppSettingsState : PersistentStateComponent {
val editorActions = ActionSettingsRegistry()
val fileActions = ActionSettingsRegistry()
- val recentCommands = mutableMapOf()
+ private val recentCommands = mutableMapOf()
fun createChatRequest(): ChatRequest {
return createChatRequest(defaultChatModel())
@@ -41,7 +40,7 @@ class AppSettingsState : PersistentStateComponent {
fun defaultChatModel() = if (useGPT4) OpenAIClient.Models.GPT4 else OpenAIClient.Models.GPT35Turbo
- fun createChatRequest(model: OpenAIClient.Model): ChatRequest {
+ private fun createChatRequest(model: OpenAIClient.Model): ChatRequest {
val chatRequest = ChatRequest()
chatRequest.model = model.modelName
chatRequest.temperature = temperature
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt
index 2bb84a82..0410b865 100644
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt
+++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/ModelSelectionWidgetFactory.kt
@@ -19,7 +19,7 @@ import javax.swing.ListModel
class ModelSelectionWidgetFactory : StatusBarWidgetFactory {
companion object {
- val logger = org.slf4j.LoggerFactory.getLogger(ModelSelectionWidgetFactory::class.java)
+ val log = org.slf4j.LoggerFactory.getLogger(ModelSelectionWidgetFactory::class.java)
}
class ModelSelectionWidget : StatusBarWidget, StatusBarWidget.MultipleTextValuesPresentation {
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt
index 4b892215..db74bf5f 100644
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt
+++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TemperatureControlWidgetFactory.kt
@@ -28,7 +28,7 @@ import javax.swing.event.ChangeListener
class TemperatureControlWidgetFactory : StatusBarWidgetFactory {
companion object {
- val logger = org.slf4j.LoggerFactory.getLogger(TemperatureControlWidgetFactory::class.java)
+ val log = org.slf4j.LoggerFactory.getLogger(TemperatureControlWidgetFactory::class.java)
val pool = Executors.newCachedThreadPool()
}
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt
index 83e7ee9b..1c76a9e8 100644
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt
+++ b/src/main/kotlin/com/github/simiacryptus/aicoder/ui/TokenCountWidgetFactory.kt
@@ -22,7 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean
class TokenCountWidgetFactory : StatusBarWidgetFactory {
companion object {
- val logger = org.slf4j.LoggerFactory.getLogger(TokenCountWidgetFactory::class.java)
+ val log = org.slf4j.LoggerFactory.getLogger(TokenCountWidgetFactory::class.java)
val workQueue = LinkedBlockingDeque()
val pool = ThreadPoolExecutor(
/* corePoolSize = */ 1, /* maximumPoolSize = */ 1,
diff --git a/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiTranslationTree.kt b/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiTranslationTree.kt
index 9b277b10..92353cf1 100644
--- a/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiTranslationTree.kt
+++ b/src/main/kotlin/com/github/simiacryptus/aicoder/util/psi/PsiTranslationTree.kt
@@ -97,7 +97,7 @@ class PsiTranslationTree(
fun getTranslatedDocument(): CharSequence = try {
var translated = translatedResult.toString()
if (!stubs.isEmpty()) {
- logger.warn(
+ log.warn(
"Translating ${stubs.size} stubs in ${stubId ?: "---"} - Initial Code: \n```\n ${
translationText().replace(
"\n",
@@ -112,7 +112,7 @@ class PsiTranslationTree(
val regex = child.getStubRegex(targetLanguage, translated)
val childDoc = child.getTranslatedDocument().toString()
val findAll = regex.findAll(translated).toList()
- logger.warn(
+ log.warn(
"Replacing ${findAll.size} instances of ${child.stubId} with: \n```\n ${
childDoc.replace(
"\n",
@@ -123,7 +123,7 @@ class PsiTranslationTree(
translated.replace(regex, childDoc.replace("\$", "\\\$"))
}
}
- logger.warn("Translation for ${stubId ?: "---"}: \n```\n ${translated.replace("\n", "\n ")}\n```\n")
+ log.warn("Translation for ${stubId ?: "---"}: \n```\n ${translated.replace("\n", "\n ")}\n```\n")
translated
} catch (e: InterruptedException) {
throw RuntimeException(e)
@@ -223,7 +223,7 @@ class PsiTranslationTree(
companion object {
- val logger = Logger.getInstance(PsiTranslationTree::class.java)
+ val log = Logger.getInstance(PsiTranslationTree::class.java)
fun parseFile(
psiFile: PsiFile,
diff --git a/src/main/kotlin/com/simiacryptus/skyenet/heart/WeakGroovyInterpreter.kt b/src/main/kotlin/com/simiacryptus/skyenet/heart/WeakGroovyInterpreter.kt
index 6d29f4a0..a0a89ab7 100644
--- a/src/main/kotlin/com/simiacryptus/skyenet/heart/WeakGroovyInterpreter.kt
+++ b/src/main/kotlin/com/simiacryptus/skyenet/heart/WeakGroovyInterpreter.kt
@@ -5,6 +5,7 @@ package com.simiacryptus.skyenet.heart
import com.simiacryptus.skyenet.Heart
import java.lang.reflect.Method
+@Suppress("unused")
open class WeakGroovyInterpreter(defs: java.util.Map) : Heart {
private val shell: Any
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 0bf4cd98..7e9f888c 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -143,15 +143,6 @@
-
-
-
-
-