Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add 'custom model' field for OpenAI API like. #95

Merged
merged 1 commit into from Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,6 +8,7 @@
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 @@

private val timeout = Duration.ofSeconds(600)
private val openAiVersion: String
get() = AutoDevSettingsState.getInstance().openAiModel
get() {
val customModel = AutoDevSettingsState.getInstance().customModel

Check warning on line 68 in src/main/kotlin/cc/unitmesh/devti/llms/openai/OpenAIProvider.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/llms/openai/OpenAIProvider.kt#L68

Added line #L68 was not covered by tests
if(AutoDevSettingsState.getInstance().openAiModel == SELECT_CUSTOM_MODEL) {
AutoDevSettingsState.getInstance().openAiModel = customModel

Check warning on line 70 in src/main/kotlin/cc/unitmesh/devti/llms/openai/OpenAIProvider.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/llms/openai/OpenAIProvider.kt#L70

Added line #L70 was not covered by tests
}
return AutoDevSettingsState.getInstance().openAiModel

Check warning on line 72 in src/main/kotlin/cc/unitmesh/devti/llms/openai/OpenAIProvider.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/llms/openai/OpenAIProvider.kt#L72

Added line #L72 was not covered by tests
}
private val openAiKey: String
get() = AutoDevSettingsState.getInstance().openAiKey

Expand Down
Expand Up @@ -21,6 +21,7 @@
var customEngineServer = ""
var customEngineToken = ""
var customPrompts = ""
var customModel = ""

Check warning on line 24 in src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/AutoDevSettingsState.kt#L24

Added line #L24 was not covered by tests

// 星火有三个版本 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")

Check warning on line 3 in src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt#L3

Added line #L3 was not covered by tests
val AI_ENGINES = arrayOf("OpenAI", "Custom", "Azure", "XingHuo")

enum class AIEngines {
Expand Down Expand Up @@ -35,3 +35,4 @@
val HUMAN_LANGUAGES = arrayOf("English", "中文")
val DEFAULT_HUMAN_LANGUAGE = HUMAN_LANGUAGES[0]
val MAX_TOKEN_LENGTH = 4000
val SELECT_CUSTOM_MODEL = "custom"

Check warning on line 38 in src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt#L38

Added line #L38 was not covered by tests
Expand Up @@ -23,6 +23,7 @@
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) }

Check warning on line 26 in src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt#L26

Added line #L26 was not covered by tests
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 @@
AIEngines.OpenAI to listOf(
openAIModelsParam,
openAIKeyParam,
customModelParam,

Check warning on line 82 in src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt#L82

Added line #L82 was not covered by tests
customOpenAIHostParam,
),
AIEngines.Custom to listOf(
Expand All @@ -89,10 +91,10 @@
),
AIEngines.XingHuo to listOf(
xingHuoApiVersionParam,
xingHuoAppIDParam,
xingHuoApiKeyParam,
xingHuoApiSecretParam,
),
xingHuoAppIDParam,
xingHuoApiKeyParam,
xingHuoApiSecretParam,

Check warning on line 96 in src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt#L94-L96

Added lines #L94 - L96 were not covered by tests
),
)


Expand Down Expand Up @@ -186,6 +188,7 @@
gitLabTokenParam.value = gitlabToken
gitLabUrlParam.value = gitlabUrl
openAIKeyParam.value = openAiKey
customModelParam.value = customModel

Check warning on line 191 in src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt#L191

Added line #L191 was not covered by tests
customOpenAIHostParam.value = customOpenAiHost
customEngineServerParam.value = customEngineServer
customEngineResponseTypeParam.value = customEngineResponseType
Expand All @@ -212,6 +215,7 @@
gitlabUrl = gitLabUrlParam.value
gitlabToken = gitLabTokenParam.value
openAiKey = openAIKeyParam.value
customModel = customModelParam.value

Check warning on line 218 in src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt#L218

Added line #L218 was not covered by tests
customOpenAiHost = customOpenAIHostParam.value
xingHuoApiSecrect = xingHuoApiSecretParam.value
xingHuoApiVersion = XingHuoApiVersion.of(xingHuoApiVersionParam.value)
Expand All @@ -237,6 +241,7 @@
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