Skip to content

Commit

Permalink
Merge pull request #95 from openharmony-dev/master
Browse files Browse the repository at this point in the history
core: add 'custom model' field for OpenAI API like.
  • Loading branch information
phodal committed Mar 1, 2024
2 parents c139860 + e001c12 commit f62be13
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
Expand Up @@ -8,6 +8,7 @@ import cc.unitmesh.devti.coder.recording.Recording
import cc.unitmesh.devti.coder.recording.RecordingInstruction
import cc.unitmesh.devti.settings.AutoDevSettingsState
import cc.unitmesh.devti.settings.coder.coderSetting
import cc.unitmesh.devti.settings.SELECT_CUSTOM_MODEL
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
Expand Down Expand Up @@ -63,7 +64,13 @@ class OpenAIProvider(val project: Project) : LLMProvider {

private val timeout = Duration.ofSeconds(600)
private val openAiVersion: String
get() = AutoDevSettingsState.getInstance().openAiModel
get() {
val customModel = AutoDevSettingsState.getInstance().customModel
if(AutoDevSettingsState.getInstance().openAiModel == SELECT_CUSTOM_MODEL) {
AutoDevSettingsState.getInstance().openAiModel = customModel
}
return AutoDevSettingsState.getInstance().openAiModel
}
private val openAiKey: String
get() = AutoDevSettingsState.getInstance().openAiKey

Expand Down
Expand Up @@ -21,6 +21,7 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
var customEngineServer = ""
var customEngineToken = ""
var customPrompts = ""
var customModel = ""

// 星火有三个版本 https://console.xfyun.cn/services/bm3
var xingHuoApiVersion = XingHuoApiVersion.V3
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt
@@ -1,6 +1,6 @@
package cc.unitmesh.devti.settings

val OPENAI_MODEL = arrayOf("gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4")
val OPENAI_MODEL = arrayOf("gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4", "custom")
val AI_ENGINES = arrayOf("OpenAI", "Custom", "Azure", "XingHuo")

enum class AIEngines {
Expand Down Expand Up @@ -35,3 +35,4 @@ val DEFAULT_AI_MODEL = OPENAI_MODEL[0]
val HUMAN_LANGUAGES = arrayOf("English", "中文")
val DEFAULT_HUMAN_LANGUAGE = HUMAN_LANGUAGES[0]
val MAX_TOKEN_LENGTH = 4000
val SELECT_CUSTOM_MODEL = "custom"
Expand Up @@ -23,6 +23,7 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
private val maxTokenLengthParam by LLMParam.creating { Editable(settings.maxTokenLength) }
private val openAIModelsParam by LLMParam.creating { ComboBox(settings.openAiModel, OPENAI_MODEL.toList()) }
private val openAIKeyParam by LLMParam.creating { Password(settings.openAiKey) }
private val customModelParam: LLMParam by LLMParam.creating { Editable(settings.customModel) }
private val customOpenAIHostParam: LLMParam by LLMParam.creating { Editable(settings.customOpenAiHost) }

private val gitTypeParam: LLMParam by LLMParam.creating { ComboBox(settings.gitType, GIT_TYPE.toList()) }
Expand Down Expand Up @@ -78,6 +79,7 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
AIEngines.OpenAI to listOf(
openAIModelsParam,
openAIKeyParam,
customModelParam,
customOpenAIHostParam,
),
AIEngines.Custom to listOf(
Expand All @@ -89,10 +91,10 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
),
AIEngines.XingHuo to listOf(
xingHuoApiVersionParam,
xingHuoAppIDParam,
xingHuoApiKeyParam,
xingHuoApiSecretParam,
),
xingHuoAppIDParam,
xingHuoApiKeyParam,
xingHuoApiSecretParam,
),
)


Expand Down Expand Up @@ -186,6 +188,7 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
gitLabTokenParam.value = gitlabToken
gitLabUrlParam.value = gitlabUrl
openAIKeyParam.value = openAiKey
customModelParam.value = customModel
customOpenAIHostParam.value = customOpenAiHost
customEngineServerParam.value = customEngineServer
customEngineResponseTypeParam.value = customEngineResponseType
Expand All @@ -212,6 +215,7 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
gitlabUrl = gitLabUrlParam.value
gitlabToken = gitLabTokenParam.value
openAiKey = openAIKeyParam.value
customModel = customModelParam.value
customOpenAiHost = customOpenAIHostParam.value
xingHuoApiSecrect = xingHuoApiSecretParam.value
xingHuoApiVersion = XingHuoApiVersion.of(xingHuoApiVersionParam.value)
Expand All @@ -237,6 +241,7 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
settings.gitlabUrl != gitLabUrlParam.value ||
settings.gitlabToken != gitLabTokenParam.value ||
settings.openAiKey != openAIKeyParam.value ||
settings.customModel != customModelParam.value ||
settings.xingHuoApiSecrect != xingHuoApiSecretParam.value ||
settings.xingHuoApiVersion != XingHuoApiVersion.of(xingHuoApiVersionParam.value) ||
settings.xingHuoAppId != xingHuoAppIDParam.value ||
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/AutoDevBundle.properties
Expand Up @@ -56,6 +56,7 @@ settings.xingHuoApiKeyParam=XingHuo API Key
settings.xingHuoApiSecretParam=XingHuo API Secret
settings.xingHuoAppIDParam=XingHuo App ID
settings.xingHuoApiVersionParam=XingHuo API Version
settings.customModelParam= Custom Model

settings.delaySecondsParam=Quest Delay Seconds
settings.customEngineResponseFormatParam=Custom Response Format (Json Path)
Expand Down

0 comments on commit f62be13

Please sign in to comment.