Skip to content

Commit a3dc0b4

Browse files
authored
refactor(ai-gateway): move EXTRA_CONFIGS construction to get-ai-gateway.sh (#247)
Changes in ai-gateway.sh: - Add parseExtraConfigs() and getExtraConfigValue() helper functions - Modify each provider to use parseExtraConfigs() with fallback to env vars Changes in get-ai-gateway.sh: - Add build*ExtraConfigs() functions for all providers with EXTRA_CONFIGS - Add buildAllExtraConfigs() called before writeConfiguration() - Add --zhipuai-domain and --zhipuai-code-plan-mode CLI options Providers with EXTRA_CONFIGS: - ZhipuAI, Minimax, Azure, Bedrock, Vertex, Claude - Cloudflare, DeepL, Dify, Ollama, Hunyuan Benefits: - Dynamic configuration without Docker image rebuild - Backward compatible with existing env vars
1 parent 8588e5d commit a3dc0b4

2 files changed

Lines changed: 272 additions & 71 deletions

File tree

all-in-one/get-ai-gateway.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ parseArgs() {
335335
LLM_ENVS+=("ZHIPUAI_MODELS")
336336
shift 2
337337
;;
338+
--zhipuai-domain)
339+
ZHIPUAI_DOMAIN="$2"
340+
shift 2
341+
;;
342+
--zhipuai-code-plan-mode)
343+
ZHIPUAI_CODE_PLAN_MODE="true"
344+
shift
345+
;;
338346
--minimax-models)
339347
MINIMAX_MODELS="$2"
340348
LLM_ENVS+=("MINIMAX_MODELS")
@@ -1200,6 +1208,18 @@ configureZhipuAIProvider() {
12001208
fi
12011209
fi
12021210
LLM_ENVS+=("ZHIPUAI_MODELS")
1211+
1212+
if [ -z "$ZHIPUAI_DOMAIN" ]; then
1213+
echo "Choose domain (China: open.bigmodel.cn, International: api.z.ai):"
1214+
read -r -u 3 -p "→ Domain (default: open.bigmodel.cn): " ZHIPUAI_DOMAIN
1215+
fi
1216+
1217+
if [ -z "$ZHIPUAI_CODE_PLAN_MODE" ]; then
1218+
read -r -u 3 -p "→ Enable Code Plan Mode? (y/N): " ENABLE_CODE_PLAN
1219+
if [[ "$ENABLE_CODE_PLAN" =~ ^[Yy] ]]; then
1220+
ZHIPUAI_CODE_PLAN_MODE="true"
1221+
fi
1222+
fi
12031223
}
12041224

12051225
configureOpenAIProvider() {
@@ -1403,7 +1423,134 @@ validatePort() {
14031423
fi
14041424
}
14051425

1426+
# ========== Build EXTRA_CONFIGS for providers ==========
1427+
buildZhipuAIExtraConfigs() {
1428+
local configs=()
1429+
[ -n "$ZHIPUAI_DOMAIN" ] && configs+=("zhipuDomain=\"$ZHIPUAI_DOMAIN\"")
1430+
[ "$ZHIPUAI_CODE_PLAN_MODE" = "true" ] && configs+=("zhipuCodePlanMode=true")
1431+
if [ ${#configs[@]} -gt 0 ]; then
1432+
ZHIPUAI_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1433+
LLM_ENVS+=("ZHIPUAI_EXTRA_CONFIGS")
1434+
fi
1435+
}
1436+
1437+
buildMinimaxExtraConfigs() {
1438+
local configs=()
1439+
[ -n "$MINIMAX_GROUP_ID" ] && configs+=("minimaxGroupId=\"$MINIMAX_GROUP_ID\"")
1440+
if [ ${#configs[@]} -gt 0 ]; then
1441+
MINIMAX_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1442+
LLM_ENVS+=("MINIMAX_EXTRA_CONFIGS")
1443+
fi
1444+
}
1445+
1446+
buildAzureExtraConfigs() {
1447+
local configs=()
1448+
[ -n "$AZURE_SERVICE_URL" ] && configs+=("azureServiceUrl=$AZURE_SERVICE_URL")
1449+
if [ ${#configs[@]} -gt 0 ]; then
1450+
AZURE_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1451+
LLM_ENVS+=("AZURE_EXTRA_CONFIGS")
1452+
fi
1453+
}
1454+
1455+
buildBedrockExtraConfigs() {
1456+
local configs=()
1457+
[ -n "$BEDROCK_REGION" ] && configs+=("awsRegion=\"$BEDROCK_REGION\"")
1458+
[ -n "$BEDROCK_ACCESS_KEY" ] && configs+=("awsAccessKey=\"$BEDROCK_ACCESS_KEY\"")
1459+
[ -n "$BEDROCK_SECRET_KEY" ] && configs+=("awsSecretKey=\"$BEDROCK_SECRET_KEY\"")
1460+
if [ ${#configs[@]} -gt 0 ]; then
1461+
BEDROCK_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1462+
LLM_ENVS+=("BEDROCK_EXTRA_CONFIGS")
1463+
fi
1464+
}
1465+
1466+
buildVertexExtraConfigs() {
1467+
local configs=()
1468+
[ -n "$VERTEX_PROJECT_ID" ] && configs+=("vertexProjectId=\"$VERTEX_PROJECT_ID\"")
1469+
[ -n "$VERTEX_REGION" ] && configs+=("vertexRegion=\"$VERTEX_REGION\"")
1470+
[ -n "$VERTEX_AUTH_KEY" ] && configs+=("vertexAuthKey=\"$VERTEX_AUTH_KEY\"")
1471+
[ -n "$VERTEX_AUTH_SERVICE_NAME" ] && configs+=("vertexAuthServiceName=\"$VERTEX_AUTH_SERVICE_NAME\"")
1472+
if [ ${#configs[@]} -gt 0 ]; then
1473+
VERTEX_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1474+
LLM_ENVS+=("VERTEX_EXTRA_CONFIGS")
1475+
fi
1476+
}
1477+
1478+
buildClaudeExtraConfigs() {
1479+
local configs=()
1480+
configs+=("claudeVersion=\"${CLAUDE_VERSION:-2023-06-01}\"")
1481+
[ -n "$CLAUDE_CODE_API_KEY" ] && configs+=("claudeCodeMode=true")
1482+
CLAUDE_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1483+
LLM_ENVS+=("CLAUDE_EXTRA_CONFIGS")
1484+
}
1485+
1486+
buildCloudflareExtraConfigs() {
1487+
local configs=()
1488+
[ -n "$CLOUDFLARE_ACCOUNT_ID" ] && configs+=("cloudflareAccountId=\"$CLOUDFLARE_ACCOUNT_ID\"")
1489+
if [ ${#configs[@]} -gt 0 ]; then
1490+
CLOUDFLARE_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1491+
LLM_ENVS+=("CLOUDFLARE_EXTRA_CONFIGS")
1492+
fi
1493+
}
1494+
1495+
buildDeepLExtraConfigs() {
1496+
local configs=()
1497+
[ -n "$DEEPL_TARGET_LANG" ] && configs+=("targetLang=\"$DEEPL_TARGET_LANG\"")
1498+
if [ ${#configs[@]} -gt 0 ]; then
1499+
DEEPL_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1500+
LLM_ENVS+=("DEEPL_EXTRA_CONFIGS")
1501+
fi
1502+
}
1503+
1504+
buildDifyExtraConfigs() {
1505+
local configs=()
1506+
[ -n "$DIFY_API_URL" ] && configs+=("difyApiUrl=\"$DIFY_API_URL\"")
1507+
[ -n "$DIFY_BOT_TYPE" ] && configs+=("botType=\"$DIFY_BOT_TYPE\"")
1508+
[ -n "$DIFY_INPUT_VARIABLE" ] && configs+=("inputVariable=\"$DIFY_INPUT_VARIABLE\"")
1509+
[ -n "$DIFY_OUTPUT_VARIABLE" ] && configs+=("outputVariable=\"$DIFY_OUTPUT_VARIABLE\"")
1510+
if [ ${#configs[@]} -gt 0 ]; then
1511+
DIFY_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1512+
LLM_ENVS+=("DIFY_EXTRA_CONFIGS")
1513+
fi
1514+
}
1515+
1516+
buildOllamaExtraConfigs() {
1517+
local configs=()
1518+
[ -n "$OLLAMA_SERVER_HOST" ] && configs+=("ollamaServerHost=\"$OLLAMA_SERVER_HOST\"")
1519+
[ -n "$OLLAMA_SERVER_PORT" ] && configs+=("ollamaServerPort=$OLLAMA_SERVER_PORT")
1520+
if [ ${#configs[@]} -gt 0 ]; then
1521+
OLLAMA_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1522+
LLM_ENVS+=("OLLAMA_EXTRA_CONFIGS")
1523+
fi
1524+
}
1525+
1526+
buildHunyuanExtraConfigs() {
1527+
local configs=()
1528+
[ -n "$HUNYUAN_AUTH_ID" ] && configs+=("hunyuanAuthId=\"$HUNYUAN_AUTH_ID\"")
1529+
[ -n "$HUNYUAN_AUTH_KEY" ] && configs+=("hunyuanAuthKey=\"$HUNYUAN_AUTH_KEY\"")
1530+
if [ ${#configs[@]} -gt 0 ]; then
1531+
HUNYUAN_EXTRA_CONFIGS=$(IFS=','; echo "${configs[*]}")
1532+
LLM_ENVS+=("HUNYUAN_EXTRA_CONFIGS")
1533+
fi
1534+
}
1535+
1536+
buildAllExtraConfigs() {
1537+
buildZhipuAIExtraConfigs
1538+
buildMinimaxExtraConfigs
1539+
buildAzureExtraConfigs
1540+
buildBedrockExtraConfigs
1541+
buildVertexExtraConfigs
1542+
buildClaudeExtraConfigs
1543+
buildCloudflareExtraConfigs
1544+
buildDeepLExtraConfigs
1545+
buildDifyExtraConfigs
1546+
buildOllamaExtraConfigs
1547+
buildHunyuanExtraConfigs
1548+
}
1549+
14061550
writeConfiguration() {
1551+
# Build all provider extra configs before writing
1552+
buildAllExtraConfigs
1553+
14071554
local LLM_CONFIGS=""
14081555
for env in "${LLM_ENVS[@]}"; do
14091556
LLM_CONFIGS="$LLM_CONFIGS
@@ -1550,6 +1697,8 @@ Model Pattern Configurations:
15501697
--deepseek-models PATTERN Model pattern for DeepSeek
15511698
--moonshot-models PATTERN Model pattern for Moonshot
15521699
--zhipuai-models PATTERN Model pattern for Zhipu AI
1700+
--zhipuai-domain DOMAIN Zhipu AI domain (default: open.bigmodel.cn, international: api.z.ai)
1701+
--zhipuai-code-plan-mode Enable Zhipu AI Code Plan mode
15531702
--minimax-models PATTERN Model pattern for Minimax
15541703
--azure-models PATTERN Model pattern for Azure OpenAI
15551704
--bedrock-models PATTERN Model pattern for AWS Bedrock

0 commit comments

Comments
 (0)