Files
storyforge/scripts/render_cliproxy_config.sh

74 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
set -eu
ROOT="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
if [ -f "$ROOT/.env" ]; then
set -a
# shellcheck disable=SC1091
. "$ROOT/.env"
set +a
fi
DATA_DIR="$ROOT/data/cliproxyapi"
CONFIG_PATH="$DATA_DIR/config.yaml"
mkdir -p "$DATA_DIR/auths" "$DATA_DIR/logs"
: "${CLIPROXY_MANAGEMENT_SECRET:=storyforge-local-management}"
: "${CLIPROXY_DASHSCOPE_BASE_URL:=https://dashscope.aliyuncs.com/compatible-mode/v1}"
python3 - <<'PY' "$CONFIG_PATH" "$CLIPROXY_MANAGEMENT_SECRET" "$CLIPROXY_DASHSCOPE_BASE_URL"
import os
import sys
from pathlib import Path
config_path = Path(sys.argv[1])
management_secret = sys.argv[2]
base_url = sys.argv[3]
dashscope_api_key = os.environ.get("DASHSCOPE_API_KEY", "").strip()
lines = [
'host: ""',
'port: 8317',
'tls:',
' enable: false',
' cert: ""',
' key: ""',
'remote-management:',
' allow-remote: false',
f' secret-key: "{management_secret}"',
' disable-control-panel: false',
'auth-dir: "/root/.cli-proxy-api"',
'debug: false',
'logging-to-file: true',
'logs-max-total-size-mb: 200',
'usage-statistics-enabled: true',
'request-retry: 2',
]
if dashscope_api_key:
lines.extend(
[
'openai-compatibility:',
' - name: "dashscope"',
f' base-url: "{base_url}"',
' api-key-entries:',
f' - api-key: "{dashscope_api_key}"',
' models:',
' - name: "glm-5"',
' alias: "GLM-5"',
' - name: "glm-5"',
' alias: "glm-5"',
' - name: "qwen3.5-plus"',
' alias: "qwen3.5-plus"',
]
)
config_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
if dashscope_api_key:
print(f"rendered cliproxy config with DashScope upstream -> {config_path}")
else:
print(f"rendered cliproxy config without upstream credentials -> {config_path}")
PY