Skip to content

Commit

Permalink
Fixing errors on startup for sanctioned systems
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Nov 4, 2023
1 parent d6ce177 commit 604bc27
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,17 @@ class GenerateProjectAction extends FileContextAction<Settings> {
return UITools.showDialog(project, SettingsUI.class, Settings.class, "Project Settings", { config -> })
}

SoftwareProjectAI projectAI = new ChatProxy<SoftwareProjectAI>(
clazz: SoftwareProjectAI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()
SoftwareProjectAI projectAI = null

@Override
File[] processSelection(SelectionState state, Settings config) {
projectAI = new ChatProxy<SoftwareProjectAI>(
clazz: SoftwareProjectAI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()
if (config == null) return new File[0]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AnalogueFileAction extends FileContextAction<AnalogueFileAction.Settings>
}

private ProjectFile generateFile(ProjectFile baseFile, String directive) {
def chatRequest = new com.simiacryptus.openai.OpenAIClient.ChatRequest.ChatRequest()
def chatRequest = new ChatRequest()
def model = AppSettingsState.instance.defaultChatModel()
chatRequest.model = model.modelName
chatRequest.max_tokens = model.maxTokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CreateFileAction extends FileContextAction<CreateFileAction.Settings> {
String basePath,
String directive
) {
def chatRequest = new com.simiacryptus.openai.OpenAIClient.ChatRequest.ChatRequest()
def chatRequest = new ChatRequest()
def model = AppSettingsState.instance.defaultChatModel()
chatRequest.model = model.modelName
chatRequest.max_tokens = model.maxTokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,18 @@ class GenerateStoryAction extends FileContextAction<GenerateStoryAction.Settings
return UITools.showDialog(project, SettingsUI.class, Settings.class, "Generate Story", {})
}

def proxy = new ChatProxy<AuthorAPI>(
clazz: AuthorAPI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()
AuthorAPI proxy = null

@Override
File[] processSelection(SelectionState state, Settings config) {
proxy = new ChatProxy<AuthorAPI>(
clazz: AuthorAPI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()

List<File> outputFiles = []

if (config) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.simiacryptus.aicoder.ui

import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.JBPopup
import com.intellij.openapi.wm.StatusBar
Expand Down Expand Up @@ -102,10 +103,12 @@ class ModelSelectionWidgetFactory : StatusBarWidgetFactory {
}

override fun isAvailable(project: Project): Boolean {
if (UITools.isSanctioned()) return false
return true
}

override fun canBeEnabledOn(statusBar: StatusBar): Boolean {
if (UITools.isSanctioned()) return false
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,7 @@ class TemperatureControlWidgetFactory : StatusBarWidgetFactory {
val feedbackPanel = JPanel()
feedbackPanel.setLayout(VerticalLayout(5))
//feedbackPanel.setBorder(BorderFactory.createTitledBorder("Feedback"))
if (UITools.isSanctioned()) {
feedbackPanel.add(
link(
JBLabel("<html><a href=''>Why is this plugin disabled?</a></html>"),
URI("https://news.google.com/home?q=russian+war+crimes&hl=ru&gl=RU&ceid=RU:ru")
)
)
feedbackPanel.add(
link(
JBLabel("<html><a href=''>How can I help?</a></html>"),
URI("https://www.bing.com/search?q=ukrainian+charities")
)
)
tabbedPane.addTab("Info", feedbackPanel)
} else {
if (!UITools.isSanctioned()) {
feedbackPanel.add(
link(
JBLabel("<html><a href=''>Problem? Request help...</a></html>"),
Expand Down Expand Up @@ -148,18 +134,26 @@ class TemperatureControlWidgetFactory : StatusBarWidgetFactory {
}

override fun createWidget(project: Project, scope: CoroutineScope): StatusBarWidget {
if (UITools.isSanctioned()) return object : StatusBarWidget {
override fun ID(): String = ""
}
return TemperatureControlWidget()
}

override fun createWidget(project: Project): StatusBarWidget {
if (UITools.isSanctioned()) return object : StatusBarWidget {
override fun ID(): String = ""
}
return TemperatureControlWidget()
}

override fun isAvailable(project: Project): Boolean {
if (UITools.isSanctioned()) return false
return true
}

override fun canBeEnabledOn(statusBar: StatusBar): Boolean {
if (UITools.isSanctioned()) return false
return true
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.simiacryptus.aicoder.ui

import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.editor.event.SelectionEvent
Expand Down Expand Up @@ -124,10 +125,12 @@ class TokenCountWidgetFactory : StatusBarWidgetFactory {
}

override fun isAvailable(project: Project): Boolean {
if (UITools.isSanctioned()) return false
return true
}

override fun canBeEnabledOn(statusBar: StatusBar): Boolean {
if (UITools.isSanctioned()) return false
return true
}
}
5 changes: 1 addition & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
displayName="AI Coder"/>
</extensions>

<applicationListeners>
<listener class="com.github.simiacryptus.aicoder.ApplicationEvents"
topic="com.intellij.openapi.application.ApplicationActivationListener"/>
</applicationListeners>
<extensions defaultExtensionNs="com.intellij">
<statusBarWidgetFactory implementation="com.github.simiacryptus.aicoder.ui.TemperatureControlWidgetFactory"
id="com.github.simiacryptus.aicoder.ui.TemperatureControlWidgetFactory"
Expand All @@ -28,6 +24,7 @@
id="com.github.simiacryptus.aicoder.ui.TokenCountWidgetFactory"
order="first"/>
</extensions>

<actions>
<group id="com.github.simiacryptus.aicoder.ui.EditorMenu"
class="com.github.simiacryptus.aicoder.ui.EditorMenu"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,17 @@ class GenerateProjectAction extends FileContextAction<Settings> {
return UITools.showDialog(project, SettingsUI.class, Settings.class, "Project Settings", { config -> })
}

SoftwareProjectAI projectAI = new ChatProxy<SoftwareProjectAI>(
clazz: SoftwareProjectAI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()
SoftwareProjectAI projectAI = null

@Override
File[] processSelection(SelectionState state, Settings config) {
projectAI = new ChatProxy<SoftwareProjectAI>(
clazz: SoftwareProjectAI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()
if (config == null) return new File[0]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,18 @@ class GenerateStoryAction extends FileContextAction<GenerateStoryAction.Settings
return UITools.showDialog(project, SettingsUI.class, Settings.class, "Generate Story", {})
}

def proxy = new ChatProxy<AuthorAPI>(
clazz: AuthorAPI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()
AuthorAPI proxy = null

@Override
File[] processSelection(SelectionState state, Settings config) {
proxy = new ChatProxy<AuthorAPI>(
clazz: AuthorAPI.class,
api: api,
model: AppSettingsState.instance.defaultChatModel(),
temperature: AppSettingsState.instance.temperature,
deserializerRetries: 2,
).create()

List<File> outputFiles = []

if (config) {
Expand Down

0 comments on commit 604bc27

Please sign in to comment.