Skip to content

Commit

Permalink
1.2.22
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Nov 18, 2023
1 parent 4825a66 commit 4e1c606
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 57 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ repositories {
val kotlin_version = "1.9.20"
val jetty_version = "11.0.18"
val slf4j_version = "2.0.9"
val skyenet_version = "1.0.32"
val skyenet_version = "1.0.33"
dependencies {

implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.29")
implementation(group = "com.simiacryptus", name = "joe-penai", version = "1.0.31")

implementation(group = "com.simiacryptus.skyenet", name = "core", version = skyenet_version)
implementation(group = "com.simiacryptus.skyenet", name = "webui", version = skyenet_version)

implementation("org.apache.httpcomponents.client5:httpclient5:5.2.1")
implementation(group = "org.eclipse.jetty", name = "jetty-server", version = jetty_version)
implementation(group = "org.eclipse.jetty", name = "jetty-servlet", version = jetty_version)
implementation(group = "org.eclipse.jetty", name = "jetty-annotations", version = jetty_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.21
pluginVersion=1.2.22
# 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 @@ -85,7 +85,7 @@ class AnalogueFileAction extends FileContextAction<Settings> {
chatRequest.temperature = AppSettingsState.instance.temperature
chatRequest.messages = [
new ChatMessage(
ChatMessage.Role.system, """
Role.system, """
You will combine natural language instructions with a user provided code example to create a new file.
Provide a new filename and the code to be written to the file.
Paths should be relative to the project root and should not exist.
Expand All @@ -94,7 +94,7 @@ class AnalogueFileAction extends FileContextAction<Settings> {
""".stripIndent(), null
),
new ChatMessage(
ChatMessage.Role.user, """
Role.user, """
Create a new file based on the following directive: $directive
The file should be based on `${baseFile.path}` which contains the following code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class AppendAction extends SelectionAction<String> {
request.temperature = AppSettingsState.instance.temperature
request.messages = [
new OpenAIClient.ChatMessage(
OpenAIClient.ChatMessage.Role.system,
OpenAIClient.Role.system,
"Append text to the end of the user's prompt", null
),
new OpenAIClient.ChatMessage(
OpenAIClient.ChatMessage.Role.user,
OpenAIClient.Role.user,
state.selectedText.toString(), null
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CreateFileAction extends FileContextAction<Settings> {
chatRequest.messages = [
//language=TEXT
new ChatMessage(
ChatMessage.Role.system, """
Role.system, """
You will interpret natural language requirements to create a new file.
Provide a new filename and the code to be written to the file.
Paths should be relative to the project root and should not exist.
Expand All @@ -98,7 +98,7 @@ class CreateFileAction extends FileContextAction<Settings> {
),
//language=TEXT
new ChatMessage(
ChatMessage.Role.user, """
Role.user, """
Create a new file based on the following directive: $directive
The file location should be based on the selected path `${basePath}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class CodeChatAction : BaseAction() {
}

override fun isEnabled(event: AnActionEvent): Boolean {
if (UITools.isSanctioned()) return false
return true
return !UITools.isSanctioned()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +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.ApplicationBase
import com.simiacryptus.skyenet.chat.ChatServer
import com.simiacryptus.skyenet.chat.ChatSession
import com.simiacryptus.skyenet.util.ClasspathResource
Expand Down Expand Up @@ -44,6 +45,7 @@ class CodeChatServer(
|
|Responses may use markdown formatting.
""".trimMargin(),
applicationClass = ApplicationBase::class.java,
) {
override fun canWrite(user: String?): Boolean = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ActionSettingsRegistry {
} catch (e: Throwable) {
false
}
if(canLoad) {
if (canLoad) {
actionConfig.file.writeText(code)
actionConfig.version = version
} else {
Expand Down Expand Up @@ -75,7 +75,12 @@ class ActionSettingsRegistry {
return children.toTypedArray()
}

class DynamicActionException(cause: Throwable, private val msg: String, val file: File, val actionSetting: ActionSettings) : Exception(msg, cause)
class DynamicActionException(
cause: Throwable,
msg: String,
val file: File,
val actionSetting: ActionSettings
) : Exception(msg, cause)

data class ActionSettings(
val id: String, // Static property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBPasswordField
import com.intellij.ui.components.JBTextField
import com.simiacryptus.openai.Models
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.models.ChatModels
import com.simiacryptus.openai.OpenAIClientBase
import java.awt.event.ActionEvent
import javax.swing.AbstractAction
Expand Down Expand Up @@ -58,7 +57,7 @@ class AppSettingsComponent {
@Suppress("unused")
val openApiLog = JButton(object : AbstractAction("Open API Log") {
override fun actionPerformed(e: ActionEvent) {
OpenAIClientBase.auxillaryLog?.let {
OpenAIClientBase.auxiliaryLog?.let {
val project = ApplicationManager.getApplication().runReadAction<Project> {
com.intellij.openapi.project.ProjectManager.getInstance().openProjects.firstOrNull()
}
Expand Down Expand Up @@ -104,9 +103,9 @@ class AppSettingsComponent {

init {
tokenCounter.isEditable = false
this.modelName.addItem(Models.GPT35Turbo.modelName)
this.modelName.addItem(Models.GPT4.modelName)
this.modelName.addItem(Models.GPT4Turbo.modelName)
this.modelName.addItem(ChatModels.GPT35Turbo.modelName)
this.modelName.addItem(ChatModels.GPT4.modelName)
this.modelName.addItem(ChatModels.GPT4Turbo.modelName)
}

val preferredFocusedComponent: JComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil
import com.simiacryptus.openai.Model
import com.simiacryptus.openai.Models
import com.simiacryptus.openai.models.OpenAIModel
import com.simiacryptus.openai.models.ChatModels
import com.simiacryptus.openai.OpenAIClient.ChatRequest
import com.simiacryptus.openai.models.OpenAITextModel
import com.simiacryptus.util.JsonUtil

class SimpleEnvelope(var value: String? = null)
Expand All @@ -23,7 +24,7 @@ class AppSettingsState : PersistentStateComponent<SimpleEnvelope> {
var apiBase = "https://api.openai.com/v1"
var apiKey = ""
var temperature = 0.1
var modelName : String = Models.GPT35Turbo.modelName
var modelName : String = ChatModels.GPT35Turbo.modelName
var tokenCounter = 0
var humanLanguage = "English"
var devActions = false
Expand All @@ -38,9 +39,9 @@ class AppSettingsState : PersistentStateComponent<SimpleEnvelope> {
return createChatRequest(defaultChatModel())
}

fun defaultChatModel(): Model = Models.entries.first { it.modelName == modelName }
fun defaultChatModel(): OpenAITextModel = ChatModels.entries.first { it.modelName == modelName }

private fun createChatRequest(model: Model): ChatRequest = ChatRequest(
private fun createChatRequest(model: OpenAIModel): ChatRequest = ChatRequest(
model = model.modelName,
temperature = temperature
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import com.intellij.openapi.wm.StatusBarWidgetFactory
import com.intellij.ui.CollectionListModel
import com.intellij.ui.SimpleListCellRenderer
import com.intellij.ui.popup.list.ComboBoxPopup
import com.simiacryptus.openai.Models
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.models.ChatModels
import kotlinx.coroutines.CoroutineScope
import javax.swing.JList
import javax.swing.ListCellRenderer
Expand All @@ -27,9 +26,9 @@ class ModelSelectionWidgetFactory : StatusBarWidgetFactory {
private var statusBar: StatusBar? = null
private var activeModel: String = AppSettingsState.instance.defaultChatModel().modelName
val models = listOf(
Models.GPT4Turbo,
Models.GPT4,
Models.GPT35Turbo,
ChatModels.GPT4Turbo,
ChatModels.GPT4,
ChatModels.GPT35Turbo,
)

override fun ID(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.components.JBScrollPane
import com.intellij.util.ui.FormBuilder
import com.simiacryptus.openai.Model
import com.simiacryptus.openai.models.OpenAIModel
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.models.OpenAITextModel
import com.simiacryptus.util.JsonUtil
import org.apache.http.client.methods.HttpRequestBase
import org.apache.hc.core5.http.HttpRequest
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import javax.swing.JPanel
Expand All @@ -22,36 +23,36 @@ class IdeaOpenAIClient : OpenAIClient(
) {
private val isInRequest = AtomicBoolean(false)

override fun incrementTokens(model: Model?, tokens: Int) {
AppSettingsState.instance.tokenCounter += tokens
override fun incrementTokens(model: OpenAIModel?, tokens: Usage) {
AppSettingsState.instance.tokenCounter += tokens.total_tokens
}

override fun authorize(request: HttpRequestBase) {
override fun authorize(request: HttpRequest) {
key = UITools.checkApiKey(key)
super.authorize(request)
}

override fun chat(
completionRequest: ChatRequest,
model: Model
chatRequest: ChatRequest,
model: OpenAITextModel
): ChatResponse {
lastEvent ?: return super.chat(completionRequest, model)
lastEvent ?: return super.chat(chatRequest, model)
if (isInRequest.getAndSet(true)) {
val response = super.chat(completionRequest, model)
val response = super.chat(chatRequest, model)
UITools.logAction("""
|Chat Response: ${JsonUtil.toJson(response.usage!!)}
""".trimMargin().trim())
return response
} else {
try {
if (!AppSettingsState.instance.editRequests) {
val response = super.chat(completionRequest, model)
val response = super.chat(chatRequest, model)
UITools.logAction("""
|Chat Response: ${JsonUtil.toJson(response.usage!!)}
""".trimMargin().trim())
return response
}
return withJsonDialog(completionRequest, {
return withJsonDialog(chatRequest, {
val chatRequest = it
UITools.run(
lastEvent!!.project, "OpenAI Request", true, suppressProgress = false
Expand All @@ -70,7 +71,7 @@ class IdeaOpenAIClient : OpenAIClient(
}


override fun complete(request: CompletionRequest, model: Model): CompletionResponse {
override fun complete(request: CompletionRequest, model: OpenAITextModel): CompletionResponse {
lastEvent ?: return super.complete(request, model)
if (isInRequest.getAndSet(true)) {
val response = super.complete(request, model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import com.intellij.ui.components.JBPasswordField
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.components.JBTextArea
import com.intellij.util.ui.FormBuilder
import com.simiacryptus.openai.APIClientBase
import com.simiacryptus.openai.ModerationException
import com.simiacryptus.openai.OpenAIClientBase
import com.simiacryptus.openai.exceptions.ModerationException
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.util.StringUtil
import groovy.lang.GroovyRuntimeException
Expand All @@ -46,15 +46,12 @@ import java.beans.PropertyChangeEvent
import java.io.IOException
import java.io.PrintWriter
import java.io.StringWriter
import java.lang.reflect.Field
import java.lang.reflect.Modifier
import java.net.URI
import java.util.*
import java.util.concurrent.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
import java.util.function.Supplier
import java.util.stream.Collectors
import javax.swing.*
import javax.swing.text.JTextComponent
import kotlin.math.max
Expand All @@ -71,7 +68,7 @@ object UITools {
val retry = WeakHashMap<Document, Runnable>()

@JvmStatic
fun isSanctioned() = APIClientBase.isSanctioned()
fun isSanctioned() = OpenAIClientBase.isSanctioned()

@JvmStatic
fun redoableTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AnalogueFileAction extends FileContextAction<Settings> {
chatRequest.temperature = AppSettingsState.instance.temperature
chatRequest.messages = [
new ChatMessage(
ChatMessage.Role.system, """
Role.system, """
You will combine natural language instructions with a user provided code example to create a new file.
Provide a new filename and the code to be written to the file.
Paths should be relative to the project root and should not exist.
Expand All @@ -94,7 +94,7 @@ class AnalogueFileAction extends FileContextAction<Settings> {
""".stripIndent(), null
),
new ChatMessage(
ChatMessage.Role.user, """
Role.user, """
Create a new file based on the following directive: $directive
The file should be based on `${baseFile.path}` which contains the following code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class AppendAction extends SelectionAction<String> {
request.temperature = AppSettingsState.instance.temperature
request.messages = [
new OpenAIClient.ChatMessage(
OpenAIClient.ChatMessage.Role.system,
OpenAIClient.Role.system,
"Append text to the end of the user's prompt", null
),
new OpenAIClient.ChatMessage(
OpenAIClient.ChatMessage.Role.user,
OpenAIClient.Role.user,
state.selectedText.toString(), null
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CreateFileAction extends FileContextAction<Settings> {
chatRequest.messages = [
//language=TEXT
new ChatMessage(
ChatMessage.Role.system, """
Role.system, """
You will interpret natural language requirements to create a new file.
Provide a new filename and the code to be written to the file.
Paths should be relative to the project root and should not exist.
Expand All @@ -98,7 +98,7 @@ class CreateFileAction extends FileContextAction<Settings> {
),
//language=TEXT
new ChatMessage(
ChatMessage.Role.user, """
Role.user, """
Create a new file based on the following directive: $directive
The file location should be based on the selected path `${basePath}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.util.ComputerLanguage
import com.github.simiacryptus.aicoder.util.MarkdownProcessor
import com.simiacryptus.openai.Models
import com.simiacryptus.openai.OpenAIClient
import com.simiacryptus.openai.models.ChatModels
import com.simiacryptus.openai.OpenAIClientBase
import com.simiacryptus.util.JsonUtil
import org.junit.jupiter.api.Assertions
Expand All @@ -17,7 +16,7 @@ open class ActionTestBase {
fun <T:Any>testScript_SelectionAction(selectionAction: SelectionAction<T>, scriptPath: String) {
AppSettingsState.instance.apiKey = OpenAIClientBase.keyTxt
AppSettingsState.instance.temperature = 0.0
AppSettingsState.instance.modelName = Models.GPT35Turbo.name
AppSettingsState.instance.modelName = ChatModels.GPT35Turbo.name
val input =
selectionAction.javaClass.getResourceAsStream(scriptPath)?.readAllBytes()?.toString(Charsets.UTF_8)
?: ""
Expand Down Expand Up @@ -65,7 +64,7 @@ open class ActionTestBase {
) {
AppSettingsState.instance.apiKey = OpenAIClientBase.keyTxt
AppSettingsState.instance.temperature = 0.0
AppSettingsState.instance.modelName = Models.GPT35Turbo.name
AppSettingsState.instance.modelName = ChatModels.GPT35Turbo.name
val input =
selectionAction.javaClass.getResourceAsStream(scriptPath)?.readAllBytes()?.toString(Charsets.UTF_8)
?: ""
Expand Down

0 comments on commit 4e1c606

Please sign in to comment.