Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
YiiGuxing committed May 31, 2023
2 parents f3732f2 + 809507c commit 0c5da0f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package cn.yiiguxing.plugin.translate.trans.openai
/**
* See: [OpenAI Models](https://platform.openai.com/docs/models)
*/
enum class OpenAIModel(val value: String) {
GPT_3_5_TURBO("gpt-3.5-turbo"),
GPT_4("gpt-4"),
GPT_4_32K("gpt-4-32k");
enum class OpenAIModel(val value: String, val modelName: String) {
GPT_3_5_TURBO("gpt-3.5-turbo", "GPT-3.5-Turbo"),
GPT_4("gpt-4", "GPT-4"),
GPT_4_32K("gpt-4-32k", "GPT-4-32K");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cn.yiiguxing.plugin.translate.trans.openai

import cn.yiiguxing.plugin.translate.HelpTopic
import cn.yiiguxing.plugin.translate.message
import cn.yiiguxing.plugin.translate.service.CacheService
import cn.yiiguxing.plugin.translate.ui.LogoHeaderPanel
import cn.yiiguxing.plugin.translate.ui.UI
import cn.yiiguxing.plugin.translate.ui.UI.migSize
import cn.yiiguxing.plugin.translate.ui.selected
import cn.yiiguxing.plugin.translate.ui.settings.TranslationEngine
import com.intellij.openapi.components.service
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.DialogWrapper
Expand All @@ -26,7 +28,7 @@ class OpenAISettingsDialog : DialogWrapper(false) {
private val apiModelComboBox: ComboBox<OpenAIModel> =
ComboBox(CollectionComboBoxModel(OpenAIModel.values().toList())).apply {
renderer = SimpleListCellRenderer.create { label, model, _ ->
label.text = model.value
label.text = model.modelName
}
}

Expand Down Expand Up @@ -71,7 +73,15 @@ class OpenAISettingsDialog : DialogWrapper(false) {

override fun doOKAction() {
OpenAICredential.apiKey = apiKey
settings.model = apiModelComboBox.selected ?: OpenAIModel.GPT_3_5_TURBO

val oldModel = settings.model
val newModel = apiModelComboBox.selected ?: OpenAIModel.GPT_3_5_TURBO
if (oldModel != newModel) {
settings.model = newModel
service<CacheService>().removeMemoryCache { key, _ ->
key.translator == TranslationEngine.OPEN_AI.id
}
}

super.doOKAction()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/messages/TranslationBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ got.it.notification.text.wordbook.storage.path=You can now change the storage pa
and sync between multiple devices using sync services like iCloud Drive, Google Drive, Onedrive, and Dropbox.
openai.settings.dialog.title=OpenAI Translator Settings
openai.settings.dialog.label.model=API model\:
openai.settings.dialog.label.api.key=API Key\:
openai.settings.dialog.label.api.key=API key\:
openai.settings.dialog.hint=<html>The OpenAI API uses API keys for authentication. \
Visit your <a href='https://platform.openai.com/account/api-keys'>API Keys</a> page \
to retrieve the API key.</html>
Expand Down

0 comments on commit 0c5da0f

Please sign in to comment.