Skip to content

Commit

Permalink
1.2.9 (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski authored Aug 10, 2023
1 parent ed39463 commit b06dc59
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ val slf4j_version = "2.0.5"
val skyenet_version = "1.0.14"
dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.15")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.16")

implementation(group = "com.simiacryptus.skyenet", name = "util", version = skyenet_version)
implementation(group = "com.simiacryptus.skyenet", name = "core", version = skyenet_version)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pluginName=intellij-aicoder
pluginRepositoryUrl=https://github.com/SimiaCryptus/intellij-aicoder
# SemVer format -> https://semver.org
pluginVersion=1.2.8
pluginVersion=1.2.9
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
#pluginSinceBuild = 203
pluginSinceBuild=231
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import org.jetbrains.annotations.Nullable

class RecentCodeEditsAction extends ActionGroup {
void update(AnActionEvent e) {
Expand All @@ -20,7 +22,7 @@ class RecentCodeEditsAction extends ActionGroup {
def id = children.size() + 1
def text = id < 10 ? "_${id}: ${instruction}" : "${id}: ${instruction}"
def element = new CustomEditAction() {
String getInstruction() {
@Override String getConfig(@Nullable Project project) {
return instruction
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.stream.Collectors
class ActionSettingsRegistry {

val actionSettings: MutableMap<String, ActionSettings> = HashMap()
val version = 1.4
val version = 1.5

fun edit(superChildren: Array<out AnAction>): Array<AnAction> {
val children = superChildren.toList().toMutableList()
Expand Down
99 changes: 81 additions & 18 deletions src/main/kotlin/com/github/simiacryptus/aicoder/util/UITools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package com.github.simiacryptus.aicoder.util

import com.github.simiacryptus.aicoder.config.ActionSettingsRegistry
import com.github.simiacryptus.aicoder.config.ActionTable
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.config.Name
import com.google.common.util.concurrent.*
Expand All @@ -27,6 +26,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBPasswordField
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.components.JBTextArea
import com.intellij.util.ui.FormBuilder
Expand All @@ -43,6 +43,7 @@ import java.awt.event.ComponentEvent
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import java.beans.PropertyChangeEvent
import java.io.IOException
import java.io.PrintWriter
import java.io.StringWriter
import java.lang.reflect.Field
Expand Down Expand Up @@ -902,12 +903,13 @@ object UITools {
}

val singleThreadPool = Executors.newSingleThreadExecutor()

@JvmStatic
fun error(log: org.slf4j.Logger, msg: String, e: Throwable) {
log?.error(msg, e)
errorLog += Pair(msg, e)
singleThreadPool.submit {
if(AppSettingsState.instance.suppressErrors) {
if (AppSettingsState.instance.suppressErrors) {
return@submit
} else if (e.matches { ModerationException::class.java.isAssignableFrom(it.javaClass) }) {
JOptionPane.showMessageDialog(
Expand All @@ -916,9 +918,70 @@ object UITools {
"This request was rejected by OpenAI Moderation",
JOptionPane.WARNING_MESSAGE
)
} else if (e.matches { java.lang.InterruptedException::class.java.isAssignableFrom(it.javaClass) && it.message?.contains("sleep interrupted") == true }) {
JOptionPane.showMessageDialog(
null,
"This request was cancelled by the user",
"User Cancelled Request",
JOptionPane.WARNING_MESSAGE
)
} else if (e.matches { IOException::class.java.isAssignableFrom(it.javaClass) && it.message?.contains("Incorrect API key") == true }) {

val formBuilder = FormBuilder.createFormBuilder()

formBuilder.addLabeledComponent(
"Error",
JLabel("The API key was rejected by the server.")
)

val apiKeyInput = JBPasswordField()
//bugReportTextArea.rows = 40
apiKeyInput.columns = 80
apiKeyInput.isEditable = true
//apiKeyInput.text = """""".trimMargin()
formBuilder.addLabeledComponent("API Key", apiKeyInput)

val openAccountButton = JXButton("Open Account Page")
openAccountButton.addActionListener {
Desktop.getDesktop().browse(URI("https://platform.openai.com/account/api-keys"))
}
formBuilder.addLabeledComponent("OpenAI Account", openAccountButton)

val testButton = JXButton("Test Key")
testButton.addActionListener {
val apiKey = apiKeyInput.password.joinToString("")
try {
OpenAIClient(key = apiKey).listModels()
JOptionPane.showMessageDialog(
null,
"The API key was accepted by the server. The new value will be saved.",
"Success",
JOptionPane.INFORMATION_MESSAGE
)
AppSettingsState.instance.apiKey = apiKey
} catch (e: Exception) {
JOptionPane.showMessageDialog(
null,
"The API key was rejected by the server.",
"Failure",
JOptionPane.WARNING_MESSAGE
)
return@addActionListener
}
}
formBuilder.addLabeledComponent("Validation", testButton)
val showOptionDialog = showOptionDialog(
formBuilder.panel,
"Dismiss",
title = "Error",
modal = true
)
log.info("showOptionDialog = $showOptionDialog")
} else if (e.matches { GroovyRuntimeException::class.java.isAssignableFrom(it.javaClass) }) {
val groovyRuntimeException = e.get { GroovyRuntimeException::class.java.isAssignableFrom(it.javaClass) } as GroovyRuntimeException?
val dynamicActionException = e.get { ActionSettingsRegistry.DynamicActionException::class.java.isAssignableFrom(it.javaClass) } as ActionSettingsRegistry.DynamicActionException?
val groovyRuntimeException =
e.get { GroovyRuntimeException::class.java.isAssignableFrom(it.javaClass) } as GroovyRuntimeException?
val dynamicActionException =
e.get { ActionSettingsRegistry.DynamicActionException::class.java.isAssignableFrom(it.javaClass) } as ActionSettingsRegistry.DynamicActionException?
val formBuilder = FormBuilder.createFormBuilder()

formBuilder.addLabeledComponent(
Expand All @@ -942,15 +1005,15 @@ object UITools {
|""".trimMargin()
formBuilder.addLabeledComponent("Error Report", wrapScrollPane(bugReportTextArea))

if(!(dynamicActionException?.actionSetting?.isDynamic ?: true)) {
if (!(dynamicActionException?.actionSetting?.isDynamic ?: true)) {
val openButton = JXButton("Revert to Default")
openButton.addActionListener {
dynamicActionException?.actionSetting?.file?.delete()
}
formBuilder.addLabeledComponent("Revert Built-in Action", openButton)
}

if(null != dynamicActionException) {
if (null != dynamicActionException) {
val openButton = JXButton("Open Dynamic Action")
openButton.addActionListener {
dynamicActionException?.file?.let {
Expand Down Expand Up @@ -983,13 +1046,13 @@ object UITools {
formBuilder.addComponent(supressFutureErrors)

val showOptionDialog = showOptionDialog(
formBuilder.panel,
"Dismiss",
title = "Error",
modal = true
)
formBuilder.panel,
"Dismiss",
title = "Error",
modal = true
)
log.info("showOptionDialog = $showOptionDialog")
if(supressFutureErrors.isSelected) {
if (supressFutureErrors.isSelected) {
AppSettingsState.instance.suppressErrors = true
}
} else {
Expand Down Expand Up @@ -1049,13 +1112,13 @@ object UITools {
formBuilder.addComponent(supressFutureErrors)

val showOptionDialog = showOptionDialog(
formBuilder.panel,
"Dismiss",
title = "Error",
modal = true
)
formBuilder.panel,
"Dismiss",
title = "Error",
modal = true
)
log.info("showOptionDialog = $showOptionDialog")
if(supressFutureErrors.isSelected) {
if (supressFutureErrors.isSelected) {
AppSettingsState.instance.suppressErrors = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import org.jetbrains.annotations.Nullable

class RecentCodeEditsAction extends ActionGroup {
void update(AnActionEvent e) {
Expand All @@ -20,7 +22,7 @@ class RecentCodeEditsAction extends ActionGroup {
def id = children.size() + 1
def text = id < 10 ? "_${id}: ${instruction}" : "${id}: ${instruction}"
def element = new CustomEditAction() {
String getInstruction() {
@Override String getConfig(@Nullable Project project) {
return instruction
}
}
Expand Down

0 comments on commit b06dc59

Please sign in to comment.