fix(settings): 测试按钮跟随当前选中代理区域,不再固定国内
This commit is contained in:
parent
75ccd2fe8e
commit
b1907fae23
@ -132,61 +132,75 @@ class SettingsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 用 Trae CN 默认账号发一条 stream=true 测试。 */
|
/** 用当前选中的 Trae 目标发一条 stream=true 测试(未选 Trae 时兜底 CN)。 */
|
||||||
fun testTraeStream() {
|
fun testTraeStream() {
|
||||||
|
val target = _selectedProxy.value
|
||||||
|
val region = when (target) {
|
||||||
|
ProxyTarget.TRAE_CN, ProxyTarget.TRAE_INTL -> target.region()
|
||||||
|
else -> ProviderRegion.CN
|
||||||
|
}
|
||||||
|
val intl = region == ProviderRegion.INTL
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_proxyDebug.value = "正在请求 Trae CN 流..."
|
_proxyDebug.value = if (intl) "正在请求 Trae INTL 流..." else "正在请求 Trae CN 流..."
|
||||||
_proxyDebugRaw.value = null
|
_proxyDebugRaw.value = null
|
||||||
val model = traeModelProvider.selectedFor(ProviderRegion.CN)
|
val model = traeModelProvider.selectedFor(region)
|
||||||
val body = """{"model":"$model","stream":true,"messages":[{"role":"user","content":"只回复OK两个字"}],"max_tokens":100}"""
|
val body = """{"model":"$model","stream":true,"messages":[{"role":"user","content":"只回复OK两个字"}],"max_tokens":100}"""
|
||||||
|
val requestLine = if (intl) {
|
||||||
|
"POST https://core-normal.trae.ai/api/agent/v3/llm_utils_chat"
|
||||||
|
} else {
|
||||||
|
"POST https://trae-api-cn.mchost.guru/api/agent/v3/llm_utils_chat"
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
val stream = traeChatProxy.openStreamingChat(body, null, ProviderRegion.CN)
|
val stream = traeChatProxy.openStreamingChat(body, null, region)
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
_proxyDebug.value = "Trae CN 未配置或未登录"
|
_proxyDebug.value = if (intl) "Trae INTL 未配置或未登录" else "Trae CN 未配置或未登录"
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
val result = readStreamSample(
|
val label = if (intl) "Trae INTL" else "Trae CN"
|
||||||
stream,
|
val result = readStreamSample(stream, label, body, requestLine)
|
||||||
"Trae CN",
|
|
||||||
body,
|
|
||||||
"POST https://trae-api-cn.mchost.guru/api/agent/v3/llm_utils_chat"
|
|
||||||
)
|
|
||||||
_proxyDebug.value = result.summary
|
_proxyDebug.value = result.summary
|
||||||
_proxyDebugRaw.value = result.raw
|
_proxyDebugRaw.value = result.raw
|
||||||
} catch (e: kotlinx.coroutines.CancellationException) {
|
} catch (e: kotlinx.coroutines.CancellationException) {
|
||||||
throw e
|
throw e
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_proxyDebug.value = "Trae CN 异常:" + (e.message ?: "未知错误")
|
_proxyDebug.value = (if (intl) "Trae INTL" else "Trae CN") + " 异常:" + (e.message ?: "未知错误")
|
||||||
_proxyDebugRaw.value = null
|
_proxyDebugRaw.value = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 用 WorkBuddy CN 默认账号发一条 stream=true 测试。 */
|
/** 用当前选中的 WorkBuddy 目标发一条 stream=true 测试(未选 WorkBuddy 时兜底 CN)。 */
|
||||||
fun testWorkBuddyStream() {
|
fun testWorkBuddyStream() {
|
||||||
|
val target = _selectedProxy.value
|
||||||
|
val region = when (target) {
|
||||||
|
ProxyTarget.WORKBUDDY_CN, ProxyTarget.WORKBUDDY_INTL -> target.region()
|
||||||
|
else -> ProviderRegion.CN
|
||||||
|
}
|
||||||
|
val intl = region == ProviderRegion.INTL
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_proxyDebug.value = "正在请求 WorkBuddy CN 流..."
|
_proxyDebug.value = if (intl) "正在请求 WorkBuddy INTL 流..." else "正在请求 WorkBuddy CN 流..."
|
||||||
_proxyDebugRaw.value = null
|
_proxyDebugRaw.value = null
|
||||||
val model = workBuddyModelProvider.selectedFor(ProviderRegion.CN)
|
val model = workBuddyModelProvider.selectedFor(region)
|
||||||
val body = """{"model":"$model","stream":true,"messages":[{"role":"user","content":"只回复OK两个字"}],"max_tokens":100}"""
|
val body = """{"model":"$model","stream":true,"messages":[{"role":"user","content":"只回复OK两个字"}],"max_tokens":100}"""
|
||||||
|
val requestLine = if (intl) {
|
||||||
|
"POST https://www.workbuddy.ai/console/chat/completions"
|
||||||
|
} else {
|
||||||
|
"POST https://copilot.tencent.com/v2/chat/completions"
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
val stream = workBuddyChatProxy.openStreamingChat(body, null, ProviderRegion.CN)
|
val stream = workBuddyChatProxy.openStreamingChat(body, null, region)
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
_proxyDebug.value = "WorkBuddy CN 未配置或未登录"
|
_proxyDebug.value = if (intl) "WorkBuddy INTL 未配置或未登录" else "WorkBuddy CN 未配置或未登录"
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
val result = readStreamSample(
|
val label = if (intl) "WorkBuddy INTL" else "WorkBuddy CN"
|
||||||
stream,
|
val result = readStreamSample(stream, label, body, requestLine)
|
||||||
"WorkBuddy CN",
|
|
||||||
body,
|
|
||||||
"POST https://copilot.tencent.com/v2/chat/completions"
|
|
||||||
)
|
|
||||||
_proxyDebug.value = result.summary
|
_proxyDebug.value = result.summary
|
||||||
_proxyDebugRaw.value = result.raw
|
_proxyDebugRaw.value = result.raw
|
||||||
} catch (e: kotlinx.coroutines.CancellationException) {
|
} catch (e: kotlinx.coroutines.CancellationException) {
|
||||||
throw e
|
throw e
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_proxyDebug.value = "WorkBuddy CN 异常:" + (e.message ?: "未知错误")
|
_proxyDebug.value = (if (intl) "WorkBuddy INTL" else "WorkBuddy CN") + " 异常:" + (e.message ?: "未知错误")
|
||||||
_proxyDebugRaw.value = null
|
_proxyDebugRaw.value = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user