mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:38:25 +00:00
Merge PR #8868: add Baidu Qianfan support (thanks @ide-rea)
This commit is contained in:
@@ -15,6 +15,8 @@ import {
|
||||
applyAuthProfileConfig,
|
||||
applyCloudflareAiGatewayConfig,
|
||||
applyCloudflareAiGatewayProviderConfig,
|
||||
applyQianfanConfig,
|
||||
applyQianfanProviderConfig,
|
||||
applyKimiCodeConfig,
|
||||
applyKimiCodeProviderConfig,
|
||||
applyMoonshotConfig,
|
||||
@@ -35,6 +37,7 @@ import {
|
||||
applyXiaomiProviderConfig,
|
||||
applyZaiConfig,
|
||||
CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF,
|
||||
QIANFAN_DEFAULT_MODEL_REF,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
@@ -43,6 +46,7 @@ import {
|
||||
VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF,
|
||||
XIAOMI_DEFAULT_MODEL_REF,
|
||||
setCloudflareAiGatewayConfig,
|
||||
setQianfanApiKey,
|
||||
setGeminiApiKey,
|
||||
setKimiCodingApiKey,
|
||||
setMoonshotApiKey,
|
||||
@@ -104,6 +108,8 @@ export async function applyAuthChoiceApiProviders(
|
||||
authChoice = "venice-api-key";
|
||||
} else if (params.opts.tokenProvider === "opencode") {
|
||||
authChoice = "opencode-zen";
|
||||
} else if (params.opts.tokenProvider === "qianfan") {
|
||||
authChoice = "qianfan-api-key";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,5 +803,61 @@ export async function applyAuthChoiceApiProviders(
|
||||
return { config: nextConfig, agentModelOverride };
|
||||
}
|
||||
|
||||
if (authChoice === "qianfan-api-key") {
|
||||
let hasCredential = false;
|
||||
if (!hasCredential && params.opts?.token && params.opts?.tokenProvider === "qianfan") {
|
||||
setQianfanApiKey(normalizeApiKeyInput(params.opts.token), params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
|
||||
if (!hasCredential) {
|
||||
await params.prompter.note(
|
||||
[
|
||||
"Get your API key at: https://console.bce.baidu.com/qianfan/ais/console/apiKey",
|
||||
"API key format: bce-v3/ALTAK-...",
|
||||
].join("\n"),
|
||||
"QIANFAN",
|
||||
);
|
||||
}
|
||||
const envKey = resolveEnvApiKey("qianfan");
|
||||
if (envKey) {
|
||||
const useExisting = await params.prompter.confirm({
|
||||
message: `Use existing QIANFAN_API_KEY (${envKey.source}, ${formatApiKeyPreview(envKey.apiKey)})?`,
|
||||
initialValue: true,
|
||||
});
|
||||
if (useExisting) {
|
||||
setQianfanApiKey(envKey.apiKey, params.agentDir);
|
||||
hasCredential = true;
|
||||
}
|
||||
}
|
||||
if (!hasCredential) {
|
||||
const key = await params.prompter.text({
|
||||
message: "Enter QIANFAN API key",
|
||||
validate: validateApiKeyInput,
|
||||
});
|
||||
setQianfanApiKey(normalizeApiKeyInput(String(key)), params.agentDir);
|
||||
}
|
||||
nextConfig = applyAuthProfileConfig(nextConfig, {
|
||||
profileId: "qianfan:default",
|
||||
provider: "qianfan",
|
||||
mode: "api_key",
|
||||
});
|
||||
{
|
||||
const applied = await applyDefaultModelChoice({
|
||||
config: nextConfig,
|
||||
setDefaultModel: params.setDefaultModel,
|
||||
defaultModel: QIANFAN_DEFAULT_MODEL_REF,
|
||||
applyDefaultConfig: applyQianfanConfig,
|
||||
applyProviderConfig: applyQianfanProviderConfig,
|
||||
noteDefault: QIANFAN_DEFAULT_MODEL_REF,
|
||||
noteAgentModel,
|
||||
prompter: params.prompter,
|
||||
});
|
||||
nextConfig = applied.config;
|
||||
agentModelOverride = applied.agentModelOverride ?? agentModelOverride;
|
||||
}
|
||||
return { config: nextConfig, agentModelOverride };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user