Skip to content

Commit

Permalink
feat: add xinghuo api version config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
iptton committed Dec 14, 2023
1 parent 946f5a0 commit d6d035a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 296 deletions.
15 changes: 12 additions & 3 deletions src/main/kotlin/cc/unitmesh/devti/llms/xianghuo/XingHuoProvider.kt
Expand Up @@ -4,6 +4,7 @@ package cc.unitmesh.devti.llms.xianghuo

import cc.unitmesh.devti.llms.LLMProvider
import cc.unitmesh.devti.settings.AutoDevSettingsState
import cc.unitmesh.devti.settings.XingHuoApiVersion
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import io.ktor.util.*
Expand All @@ -27,6 +28,14 @@ class XingHuoProvider(val project: Project) : LLMProvider {
private val secrectKey: String
get() = autoDevSettingsState.xingHuoApiSecrect

private val apiVersion: XingHuoApiVersion
get() = autoDevSettingsState.xingHuoApiVersion
private val XingHuoApiVersion.asGeneralDomain
get() = when (this) {
XingHuoApiVersion.V1 -> ""
XingHuoApiVersion.V2 -> "v2"
else -> "v3"
}

private val appid: String
get() = autoDevSettingsState.xingHuoAppId
Expand Down Expand Up @@ -113,7 +122,7 @@ class XingHuoProvider(val project: Project) : LLMProvider {
val header = """
|host: spark-api.xf-yun.com
|date: $date
|GET /v1.1/chat HTTP/1.1
|GET /v${apiVersion.value}.1/chat HTTP/1.1
""".trimMargin()
val signature = hmacsha256.doFinal(header.toByteArray()).encodeBase64()
val authorization =
Expand All @@ -124,7 +133,7 @@ class XingHuoProvider(val project: Project) : LLMProvider {
"date" to date,
"host" to "spark-api.xf-yun.com"
)
val urlBuilder = "https://spark-api.xf-yun.com/v1.1/chat".toHttpUrl().newBuilder()
val urlBuilder = "https://spark-api.xf-yun.com/v${apiVersion.value}.1/chat".toHttpUrl().newBuilder()
params.forEach {
urlBuilder.addQueryParameter(it.key, it.value)
}
Expand All @@ -141,7 +150,7 @@ class XingHuoProvider(val project: Project) : LLMProvider {
},
"parameter": {
"chat": {
"domain": "general",
"domain": "general${apiVersion.asGeneralDomain}",
"temperature": 0.5,
"max_tokens": 1024
}
Expand Down
292 changes: 0 additions & 292 deletions src/main/kotlin/cc/unitmesh/devti/settings/AppSettingsComponent.kt

This file was deleted.

Expand Up @@ -18,6 +18,8 @@ class AutoDevSettingsState : PersistentStateComponent<AutoDevSettingsState> {
var customEngineToken = ""
var customPrompts = ""

// 星火有三个版本 https://console.xfyun.cn/services/bm3
var xingHuoApiVersion = XingHuoApiVersion.V3
var xingHuoAppId = ""
var xingHuoApiSecrect = ""
var xingHuoApiKey = ""
Expand Down
16 changes: 15 additions & 1 deletion src/main/kotlin/cc/unitmesh/devti/settings/Constants.kt
@@ -1,12 +1,26 @@
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")
val AI_ENGINES = arrayOf("OpenAI", "Custom", "Azure", "XingHuo")

enum class AIEngines {
OpenAI, Custom, Azure, XingHuo
}

enum class XingHuoApiVersion(val value: Int) {
V1(1), V2(2), V3(3);

companion object {
fun of(str: String): XingHuoApiVersion = when (str) {
"V1" -> V1
"V2" -> V2
"V3" -> V3
else -> V3
}
}
}


val DEFAULT_AI_ENGINE = AI_ENGINES[0]

val HUMAN_LANGUAGES = arrayOf("English", "中文")
Expand Down

0 comments on commit d6d035a

Please sign in to comment.