chore: import upstream snapshot with attribution
Update draft releases / main (push) Has been cancelled
Build and push docs image / build-image (push) Has been cancelled
Build Web Application / build-web (macos-latest) (push) Has been cancelled
Build Web Application / build-web (ubuntu-latest) (push) Has been cancelled
Python Code Quality Checks / build (push) Has been cancelled
Test Python / test-python (macos-latest, 3.10) (push) Has been cancelled
Test Python / test-python (macos-latest, 3.11) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.10) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.11) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:27:08 +08:00
commit d13100ebf3
4413 changed files with 764874 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
SCRIPT_LOCATION=$0
cd "$(dirname "$SCRIPT_LOCATION")"
WORK_DIR=$(pwd)
WORK_DIR="$WORK_DIR/.."
TARGET_DIR="$WORK_DIR/packages/dbgpt-app/src/dbgpt_app/static/web"
echo "Building web static files"
echo "Target directory: $TARGET_DIR"
cd $WORK_DIR/web
source_env=".env"
tmp_env=".env.copy"
if [ -e "$source_env" ]; then
cp "$source_env" "$tmp_env"
rm -rf "$source_env"
else
echo "Do not find .env"
fi
yarn install
rm -rf ../web/out/
yarn compile
rm -rf $TARGET_DIR \
&& mkdir -p $TARGET_DIR \
&& cp -R ../web/out/* $TARGET_DIR
if [ -e "$tmp_env" ]; then
cp "$tmp_env" "$source_env"
rm -rf "$tmp_env"
fi
+69
View File
@@ -0,0 +1,69 @@
@echo off
setlocal
:: Get script location and set working directory
for %%i in (%0) do set SCRIPT_LOCATION=%%~dpi
cd %SCRIPT_LOCATION%
cd ..
cd ..
set WORK_DIR=%CD%
:: Check if sqlite3 is installed
where sqlite3 >nul 2>nul
if %ERRORLEVEL% neq 0 (
echo sqlite3 not found, please install sqlite3
exit /b 1
)
:: Default file paths
set DEFAULT_DB_FILE=DB-GPT\pilot\data\default_sqlite.db
set DEFAULT_SQL_FILE=DB-GPT\docker\examples\sqls\*_sqlite.sql
set DB_FILE=%WORK_DIR%\pilot\data\default_sqlite.db
set SQL_FILE=
:argLoop
if "%1"=="" goto argDone
if "%1"=="-d" goto setDBFile
if "%1"=="--db-file" goto setDBFile
if "%1"=="-f" goto setSQLFile
if "%1"=="--sql-file" goto setSQLFile
if "%1"=="-h" goto printUsage
if "%1"=="--help" goto printUsage
goto argError
:setDBFile
shift
set DB_FILE=%1
shift
goto argLoop
:setSQLFile
shift
set SQL_FILE=%1
shift
goto argLoop
:argError
echo Invalid argument: %1
goto printUsage
:printUsage
echo USAGE: %0 [--db-file sqlite db file] [--sql-file sql file path to run]
echo [-d^|--db-file sqlite db file path] default: %DEFAULT_DB_FILE%
echo [-f^|--sql-file sqlite file to run] default: %DEFAULT_SQL_FILE%
echo [-h^|--help] Usage message
exit /b 0
:argDone
if "%SQL_FILE%"=="" (
if not exist "%WORK_DIR%\pilot\data" mkdir "%WORK_DIR%\pilot\data"
for %%f in (%WORK_DIR%\docker\examples\sqls\*_sqlite.sql) do (
echo execute sql file: %%f
sqlite3 "%DB_FILE%" < "%%f"
)
) else (
echo Execute SQL file %SQL_FILE%
sqlite3 "%DB_FILE%" < "%SQL_FILE%"
)
+76
View File
@@ -0,0 +1,76 @@
#!/bin/bash
# Only support SQLite now
SCRIPT_LOCATION=$0
cd "$(dirname "$SCRIPT_LOCATION")"
WORK_DIR=$(pwd)
WORK_DIR="$WORK_DIR/../.."
if ! command -v sqlite3 > /dev/null 2>&1
then
echo "sqlite3 not found, please install sqlite3"
exit 1
fi
DEFAULT_DB_FILE="DB-GPT/pilot/data/default_sqlite.db"
DEFAULT_SQL_FILE="DB-GPT/docker/examples/sqls/*_sqlite.sql"
DB_FILE="$WORK_DIR/pilot/data/default_sqlite.db"
WIDE_DB_FILE="$WORK_DIR/pilot/data/wide_sqlite.db"
SQL_FILE=""
usage () {
echo "USAGE: $0 [--db-file sqlite db file] [--sql-file sql file path to run]"
echo " [-d|--db-file sqlite db file path] default: ${DEFAULT_DB_FILE}"
echo " [-f|--sql-file sqlte file to run] default: ${DEFAULT_SQL_FILE}"
echo " [-h|--help] Usage message"
}
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-d|--db-file)
DB_FILE="$2"
shift # past argument
shift # past value
;;
-f|--sql-file)
SQL_FILE="$2"
shift
shift
;;
-h|--help)
help="true"
shift
;;
*)
usage
exit 1
;;
esac
done
if [[ $help ]]; then
usage
exit 0
fi
if [ -n $SQL_FILE ];then
mkdir -p $WORK_DIR/pilot/data
for file in $WORK_DIR/docker/examples/sqls/*_sqlite.sql
do
echo "execute sql file: $file"
sqlite3 $DB_FILE < "$file"
done
for file in $WORK_DIR/docker/examples/sqls/*_sqlite_wide.sql
do
echo "execute sql file: $file"
sqlite3 $WIDE_DB_FILE < "$file"
done
else
echo "Execute SQL file ${SQL_FILE}"
sqlite3 $DB_FILE < $SQL_FILE
fi
+513
View File
@@ -0,0 +1,513 @@
#!/usr/bin/env bash
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ DB-GPT Quick Installer ║
# ║ ║
# ║ One-line usage: ║
# ║ curl -fsSL https://raw.githubusercontent.com/eosphoros-ai/DB-GPT/\ ║
# ║ main/scripts/install/install.sh | bash ║
# ║ ║
# ║ What this script does: ║
# ║ 1. Detect OS (macOS / Linux) ║
# ║ 2. Ensure git and curl are available ║
# ║ 3. Install uv (if not already present) ║
# ║ 4. Clone (or update) the DB-GPT repository ║
# ║ 5. Run `uv sync` with the extras for the chosen profile ║
# ║ 6. Generate config via dbgpt setup wizard ║
# ║ 7. Print next-steps (start command, URL) ║
# ║ ║
# ║ What this script does NOT do: ║
# ║ - Install GPU drivers or CUDA ║
# ║ - Download large local models ║
# ║ - Modify shell rc files (except via uv installer) ║
# ║ - Collect telemetry ║
# ╚════════════════════════════════════════════════════════════════════════════╝
set -euo pipefail
# ── Resolve script location (works for both local and curl|bash) ─────────────
# When piped from curl, BASH_SOURCE is empty. In that case we download the
# helper libs from GitHub on the fly.
SCRIPT_DIR=""
REMOTE_BASE="https://raw.githubusercontent.com/eosphoros-ai/DB-GPT/main/scripts/install"
_resolve_script_dir() {
if [[ -n "${BASH_SOURCE[0]:-}" && "${BASH_SOURCE[0]}" != "bash" ]]; then
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
fi
}
_resolve_script_dir
# ── Source helper libs ────────────────────────────────────────────────────────
_source_lib() {
local name="$1"
if [[ -n "${SCRIPT_DIR}" && -f "${SCRIPT_DIR}/lib/${name}" ]]; then
# shellcheck source=/dev/null
source "${SCRIPT_DIR}/lib/${name}"
else
# Running via curl | bash — fetch from GitHub
local tmp
tmp="$(mktemp)"
curl -fsSL "${REMOTE_BASE}/lib/${name}" -o "${tmp}"
# shellcheck source=/dev/null
source "${tmp}"
rm -f "${tmp}"
fi
}
_source_lib "common.sh"
_source_lib "profiles.sh"
# ── Default values ────────────────────────────────────────────────────────────
PROFILE=""
INSTALL_DIR="${DBGPT_INSTALL_DIR:-${HOME}/.dbgpt}"
VERSION="${DBGPT_VERSION:-main}"
REPO_DIR="${DBGPT_REPO_DIR:-}"
USE_EXISTING_REPO="false"
MIRROR=""
YES="false"
START_AFTER_INSTALL="false"
USER_CONFIG=""
# ── Usage ─────────────────────────────────────────────────────────────────────
usage() {
cat <<'EOF'
DB-GPT Quick Installer
Usage:
install.sh [options]
Options:
--profile <name> Deployment profile (openai, kimi, qwen, minimax, glm, custom, default)
--config <path> Use existing TOML config (skip config generation)
--install-dir <path> Where to install (default: ~/.dbgpt)
--version <git-ref> Git tag or branch to check out (default: main)
--repo-dir <path> Use an existing local DB-GPT checkout
--mirror china Use China PyPI mirror (Tsinghua)
--yes Non-interactive — accept all defaults
--start Start DB-GPT server after install
-h, --help Show this help
Environment variables:
OPENAI_API_KEY Automatically injected into OpenAI / custom / default / kimi(embedding) config
MOONSHOT_API_KEY Automatically injected into Kimi config
DASHSCOPE_API_KEY Automatically injected into Qwen config
MINIMAX_API_KEY Automatically injected into MiniMax config
ZHIPUAI_API_KEY Automatically injected into GLM config
DBGPT_INSTALL_DIR Override default install directory
DBGPT_REPO_DIR Reuse an existing local DB-GPT repo
DBGPT_VERSION Override default git ref
Examples:
# Interactive (will ask which profile)
bash install.sh
# Fully non-interactive
bash install.sh --profile openai --yes
# With OpenAI API key
OPENAI_API_KEY=sk-xxx bash install.sh --profile openai --yes
# With Kimi / Moonshot API key
MOONSHOT_API_KEY=sk-xxx bash install.sh --profile kimi --yes
# With Qwen / DashScope API key
DASHSCOPE_API_KEY=sk-xxx bash install.sh --profile qwen --yes
# With MiniMax API key
MINIMAX_API_KEY=sk-xxx bash install.sh --profile minimax --yes
# With GLM / ZhipuAI API key
ZHIPUAI_API_KEY=sk-xxx bash install.sh --profile glm --yes
# Reuse your current local repo (skip clone/update)
OPENAI_API_KEY=sk-xxx bash install.sh --profile openai --repo-dir . --yes
# Power-user: provide your own config file (skip config generation)
bash install.sh --config /path/to/my.toml --profile openai --yes
# China mirror
bash install.sh --profile openai --mirror china
EOF
}
# ── Argument parsing ──────────────────────────────────────────────────────────
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--profile)
PROFILE="${2:-}"
[[ -z "${PROFILE}" ]] && die "--profile requires a value"
shift 2
;;
--install-dir)
INSTALL_DIR="${2:-}"
[[ -z "${INSTALL_DIR}" ]] && die "--install-dir requires a value"
shift 2
;;
--version)
VERSION="${2:-}"
[[ -z "${VERSION}" ]] && die "--version requires a value"
shift 2
;;
--repo-dir)
REPO_DIR="${2:-}"
[[ -z "${REPO_DIR}" ]] && die "--repo-dir requires a value"
shift 2
;;
--mirror)
MIRROR="${2:-}"
[[ -z "${MIRROR}" ]] && die "--mirror requires a value"
shift 2
;;
--yes)
YES="true"
shift
;;
--start)
START_AFTER_INSTALL="true"
shift
;;
--config)
USER_CONFIG="${2:-}"
[[ -z "${USER_CONFIG}" ]] && die "--config requires a value"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
die "Unknown argument: $1. Run with --help for usage."
;;
esac
done
}
# ── Steps ─────────────────────────────────────────────────────────────────────
step_check_platform() {
local os arch
os="$(uname -s)"
arch="$(uname -m)"
case "${os}" in
Darwin|Linux) ;;
*)
die "Unsupported OS: ${os}. This installer supports macOS and Linux."
;;
esac
info "Platform: ${os} ${arch}"
}
step_ensure_base_commands() {
require_cmd curl
require_cmd git
}
step_choose_profile() {
if [[ -n "${PROFILE}" ]]; then
return
fi
if [[ "${YES}" == "true" ]]; then
PROFILE="openai"
info "Non-interactive mode: defaulting to profile 'openai'"
return
fi
printf '\n'
printf '%b' "${COLOR_CYAN}Select a deployment profile:${COLOR_RESET}\n"
printf ' 1) openai — OpenAI API proxy (recommended)\n'
printf ' 2) kimi — Kimi 2.5 via Moonshot API\n'
printf ' 3) qwen — Qwen via DashScope API\n'
printf ' 4) minimax — MiniMax OpenAI-compatible API\n'
printf ' 5) glm — GLM-5 via ZhipuAI API\n'
printf ' 6) custom — Custom OpenAI-compatible provider\n'
printf ' 7) default — Default (OpenAI-compatible)\n'
printf ' q) quit\n'
printf '\n'
printf '%b' "${COLOR_CYAN}Please select a profile by entering the corresponding number:${COLOR_RESET}\n"
printf '\n'
local choice
prompt_input "Enter choice [1]: " choice
choice="${choice:-1}"
case "${choice}" in
1|openai) PROFILE="openai" ;;
2|kimi) PROFILE="kimi" ;;
3|qwen) PROFILE="qwen" ;;
4|minimax) PROFILE="minimax" ;;
5|glm) PROFILE="glm" ;;
6|custom) PROFILE="custom" ;;
7|default) PROFILE="default" ;;
q|Q) info "Installation cancelled."; exit 0 ;;
*) die "Invalid choice: ${choice}" ;;
esac
}
step_ensure_uv() {
if command -v uv >/dev/null 2>&1; then
success "uv found: $(uv --version 2>/dev/null || echo 'unknown')"
return
fi
info "uv not found. Installing..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# uv installer puts the binary in ~/.local/bin or ~/.cargo/bin.
# Try to pick it up without requiring the user to reload their shell.
for candidate in \
"${HOME}/.local/bin" \
"${HOME}/.cargo/bin"
do
if [[ -x "${candidate}/uv" ]]; then
export PATH="${candidate}:${PATH}"
break
fi
done
if ! command -v uv >/dev/null 2>&1; then
die "uv was installed but cannot be found on PATH. Please open a new terminal and re-run."
fi
success "uv installed: $(uv --version 2>/dev/null || echo 'unknown')"
}
step_apply_mirror() {
if [[ "${MIRROR}" == "china" ]]; then
export UV_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
info "China mirror enabled: UV_INDEX_URL=${UV_INDEX_URL}"
fi
}
step_prepare_dirs() {
mkdir -p "${INSTALL_DIR}"
}
resolve_repo_dir() {
if [[ -z "${REPO_DIR}" ]]; then
REPO_DIR="${INSTALL_DIR}/DB-GPT"
return
fi
USE_EXISTING_REPO="true"
[[ -d "${REPO_DIR}" ]] || die "--repo-dir does not exist: ${REPO_DIR}"
local resolved_repo_dir
resolved_repo_dir="$(git -C "${REPO_DIR}" rev-parse --show-toplevel 2>/dev/null)" \
|| die "--repo-dir must point to a DB-GPT git checkout: ${REPO_DIR}"
REPO_DIR="${resolved_repo_dir}"
if [[ "${VERSION}" != "main" ]]; then
warn "--version is ignored when --repo-dir is set. Using existing checkout at ${REPO_DIR}."
fi
}
step_clone_or_update_repo() {
local repo_dir="${REPO_DIR}"
if [[ "${USE_EXISTING_REPO}" == "true" ]]; then
info "Using existing local repo: ${repo_dir}"
return
fi
if [[ ! -e "${repo_dir}" ]]; then
run "Cloning DB-GPT repository..." \
git clone --depth 1 --branch "${VERSION}" \
https://github.com/eosphoros-ai/DB-GPT.git "${repo_dir}"
return
fi
if [[ ! -d "${repo_dir}/.git" ]]; then
die "Directory exists but is not a git repo: ${repo_dir}. Remove it and re-run."
fi
info "Existing DB-GPT repo found: ${repo_dir}"
if confirm "Update to version '${VERSION}'?"; then
run "Fetching latest..." git -C "${repo_dir}" fetch --tags --prune
run "Checking out ${VERSION}..." git -C "${repo_dir}" checkout "${VERSION}"
else
info "Skipping repo update."
fi
}
step_install_deps() {
local repo_dir="${REPO_DIR}"
local extras
extras="$(profile_extras "${PROFILE}")"
info "Installing dependencies for profile: ${PROFILE}"
local extra_args=()
while IFS= read -r extra; do
[[ -z "${extra}" ]] && continue
extra_args+=(--extra "${extra}")
done <<< "${extras}"
(
cd "${repo_dir}"
run "Running uv sync (this may take a few minutes)..." \
uv sync --all-packages "${extra_args[@]}"
)
success "Dependencies installed."
}
step_check_api_key() {
local env_name
env_name="$(profile_api_key_env "${PROFILE}")"
# Primary API key check
if [[ -n "${env_name}" ]] && [[ -z "${!env_name:-}" ]]; then
warn "Environment variable ${env_name} is not set."
warn "The wizard will generate config with a placeholder."
warn "Set it before starting: export ${env_name}=sk-xxx"
fi
# Kimi special handling: also needs OPENAI_API_KEY for embeddings
if [[ "${PROFILE}" == "kimi" ]] && [[ -z "${OPENAI_API_KEY:-}" ]]; then
warn "Kimi profile also needs OPENAI_API_KEY for embeddings."
warn "Set it before starting: export OPENAI_API_KEY=sk-xxx"
fi
}
step_generate_config() {
info "Generating configuration via dbgpt setup..."
local setup_args=(dbgpt setup --profile "${PROFILE}" --yes)
# If user explicitly provided an API key via environment, pass it through
local api_key_env
api_key_env="$(profile_api_key_env "${PROFILE}")"
if [[ -n "${api_key_env}" && -n "${!api_key_env:-}" ]]; then
setup_args+=(--api-key "${!api_key_env}")
fi
(
cd "${REPO_DIR}"
run "Running dbgpt setup..." uv run "${setup_args[@]}"
)
local config_path="${HOME}/.dbgpt/configs/${PROFILE}.toml"
if [[ -f "${config_path}" ]]; then
success "Config written to ${config_path}"
else
die "Config generation failed — ${config_path} not found"
fi
}
step_validate() {
local repo_dir="${REPO_DIR}"
(
cd "${repo_dir}"
if uv run dbgpt --version >/dev/null 2>&1; then
success "dbgpt CLI verified: $(uv run dbgpt --version 2>/dev/null || echo 'ok')"
else
warn "Could not verify dbgpt CLI. This may be fine — try starting the server."
fi
)
}
step_print_summary() {
local repo_dir="${REPO_DIR}"
local config_path="${HOME}/.dbgpt/configs/${PROFILE}.toml"
printf '%b' "
${COLOR_GREEN}════════════════════════════════════════════════════════════${COLOR_RESET}
${COLOR_GREEN} DB-GPT installed successfully!${COLOR_RESET}
${COLOR_GREEN}════════════════════════════════════════════════════════════${COLOR_RESET}
Profile: ${PROFILE}
Repository: ${repo_dir}
Config: ${config_path}
${COLOR_CYAN}Next steps:${COLOR_RESET}
1. Review / Edit your config (set Custom API key Or BaseURL if not done):
${COLOR_YELLOW}${config_path}${COLOR_RESET}
2. Start DB-GPT:
${COLOR_YELLOW}cd \"${repo_dir}\" && uv run dbgpt start webserver --profile ${PROFILE}${COLOR_RESET}
3. Open your browser:
${COLOR_YELLOW}http://localhost:5670${COLOR_RESET}
"
}
step_start_if_requested() {
if [[ "${START_AFTER_INSTALL}" != "true" ]]; then
return
fi
local repo_dir="${REPO_DIR}"
info "Starting DB-GPT server..."
(
cd "${repo_dir}"
if [[ -n "${USER_CONFIG:-}" ]]; then
exec uv run dbgpt start webserver --config "${USER_CONFIG}"
else
exec uv run dbgpt start webserver --profile "${PROFILE}"
fi
)
}
# ── Main ──────────────────────────────────────────────────────────────────────
main() {
printf '%b' "${COLOR_GREEN}"
cat <<'BANNER'
____ ____ ____ ____ _____
| _ \| __ ) / ___| _ \_ _|
| | | | _ \ ____| | _| |_) || |
| |_| | |_) |____| |_| | __/ | |
|____/|____/ \____|_| |_|
Quick Installer
BANNER
printf '%b' "${COLOR_RESET}"
parse_args "$@"
step_check_platform
step_ensure_base_commands
if [[ -n "${USER_CONFIG:-}" ]]; then
[[ -f "${USER_CONFIG}" ]] || die "Config file not found: ${USER_CONFIG}"
info "Using user-provided config: ${USER_CONFIG}"
if [[ -z "${PROFILE}" ]]; then
PROFILE="openai"
info "No --profile specified with --config; defaulting to 'openai' for dependency extras."
fi
validate_profile "${PROFILE}"
step_apply_mirror
step_prepare_dirs
resolve_repo_dir
step_ensure_uv
step_clone_or_update_repo
step_install_deps
step_validate
step_print_summary
step_start_if_requested
else
step_choose_profile
validate_profile "${PROFILE}"
step_apply_mirror
step_prepare_dirs
resolve_repo_dir
step_ensure_uv
step_clone_or_update_repo
step_install_deps
step_check_api_key
step_generate_config
step_validate
step_print_summary
step_start_if_requested
fi
}
main "$@"
+90
View File
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
# common.sh - Shared utility functions for DB-GPT installer
# shellcheck disable=SC2034
# ── Colors ────────────────────────────────────────────────────────────────────
readonly COLOR_RESET='\033[0m'
readonly COLOR_RED='\033[1;31m'
readonly COLOR_GREEN='\033[1;32m'
readonly COLOR_YELLOW='\033[1;33m'
readonly COLOR_BLUE='\033[1;34m'
readonly COLOR_CYAN='\033[1;36m'
# ── Logging ───────────────────────────────────────────────────────────────────
info() {
printf "${COLOR_BLUE}[INFO]${COLOR_RESET} %s\n" "$*"
}
warn() {
printf "${COLOR_YELLOW}[WARN]${COLOR_RESET} %s\n" "$*"
}
error() {
printf "${COLOR_RED}[ERROR]${COLOR_RESET} %s\n" "$*" >&2
}
success() {
printf "${COLOR_GREEN}[OK]${COLOR_RESET} %s\n" "$*"
}
prompt_input() {
local prompt="$1"
local __resultvar="$2"
local answer=""
if [[ -r /dev/tty ]]; then
if read -r -p "${prompt}" answer < /dev/tty 2>/dev/null; then
printf -v "${__resultvar}" '%s' "${answer}"
return
fi
fi
if [[ -t 0 ]]; then
read -r -p "${prompt}" answer || die "Failed to read input from stdin."
else
die "Interactive input requires a terminal. Re-run with explicit flags such as --profile <name> or --yes."
fi
printf -v "${__resultvar}" '%s' "${answer}"
}
die() {
error "$*"
exit 1
}
# ── Command helpers ───────────────────────────────────────────────────────────
# Check that a command exists, die if not.
require_cmd() {
local cmd="$1"
if ! command -v "${cmd}" >/dev/null 2>&1; then
die "Required command not found: ${cmd}. Please install it first."
fi
}
# Run a command with a description printed before it.
run() {
local desc="$1"
shift
info "${desc}"
if ! "$@"; then
die "Command failed: $*"
fi
}
# ── Interactive helpers ───────────────────────────────────────────────────────
# Ask a yes/no question. Respects the global YES flag for non-interactive use.
confirm() {
local prompt="$1"
if [[ "${YES:-false}" == "true" ]]; then
return 0
fi
local answer
prompt_input "${prompt} [y/N]: " answer
[[ "${answer}" =~ ^[Yy]$ ]]
}
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env bash
# profiles.sh - Profile definitions for DB-GPT installer
#
# Each profile maps to:
# 1. A set of uv extras (fed to `uv sync --extra ...`)
# 2. The API key environment variable name
# ── Validation ────────────────────────────────────────────────────────────────
# Currently supported profiles. Extend this list when adding new profiles.
readonly SUPPORTED_PROFILES="openai kimi qwen minimax glm custom default"
validate_profile() {
local profile="$1"
case "${profile}" in
openai|kimi|qwen|minimax|glm|custom|default) ;;
*)
die "Unsupported profile: ${profile}. Supported profiles: ${SUPPORTED_PROFILES}"
;;
esac
}
# ── Extras mapping ────────────────────────────────────────────────────────────
# Returns newline-separated extras for the given profile.
# These are taken directly from install_help.py / get_deployment_presets().
profile_extras() {
local profile="$1"
case "${profile}" in
openai)
cat <<'EOF'
base
proxy_openai
rag
storage_chromadb
dbgpts
EOF
;;
kimi)
cat <<'EOF'
base
proxy_openai
rag
storage_chromadb
dbgpts
EOF
;;
qwen)
cat <<'EOF'
base
proxy_openai
proxy_tongyi
rag
storage_chromadb
dbgpts
EOF
;;
minimax)
cat <<'EOF'
base
proxy_openai
rag
storage_chromadb
dbgpts
EOF
;;
glm)
cat <<'EOF'
base
proxy_openai
proxy_zhipuai
rag
storage_chromadb
dbgpts
EOF
;;
custom)
cat <<'EOF'
base
proxy_openai
rag
storage_chromadb
dbgpts
EOF
;;
default)
cat <<'EOF'
base
proxy_openai
rag
storage_chromadb
dbgpts
EOF
;;
*)
die "No extras defined for profile: ${profile}"
;;
esac
}
# ── Environment variable name for API key ─────────────────────────────────────
profile_api_key_env() {
local profile="$1"
case "${profile}" in
openai) echo "OPENAI_API_KEY" ;;
kimi) echo "MOONSHOT_API_KEY" ;;
qwen) echo "DASHSCOPE_API_KEY" ;;
minimax) echo "MINIMAX_API_KEY" ;;
glm) echo "ZHIPUAI_API_KEY" ;;
custom) echo "OPENAI_API_KEY" ;;
default) echo "OPENAI_API_KEY" ;;
*) echo "" ;;
esac
}
+47
View File
@@ -0,0 +1,47 @@
#!/bin/bash
# Get cuda version by torch
CUDA_VERSION=`python -c "import torch;print(torch.version.cuda.replace('.', '') if torch.cuda.is_available() else '')"`
DEVICE="cpu"
CPU_OPT="basic"
if [ "${CUDA_VERSION}" = "" ]; then
echo "CUDA not support, use cpu version"
else
DEVICE="cu${CUDA_VERSION//./}"
echo "CUDA version: $CUDA_VERSION, download path: $DEVICE"
fi
echo "Checking CPU support:"
CPU_SUPPORT=$(lscpu)
echo "$CPU_SUPPORT" | grep -q "avx "
if [ $? -eq 0 ]; then
echo "CPU supports AVX."
# CPU_OPT="AVX"
# TODO AVX will failed on my cpu
else
echo "CPU does not support AVX."
fi
echo "$CPU_SUPPORT" | grep -q "avx2"
if [ $? -eq 0 ]; then
echo "CPU supports AVX2."
CPU_OPT="AVX2"
else
echo "CPU does not support AVX2."
fi
echo "$CPU_SUPPORT" | grep -q "avx512"
if [ $? -eq 0 ]; then
echo "CPU supports AVX512."
CPU_OPT="AVX512"
else
echo "CPU does not support AVX512."
fi
EXTRA_INDEX_URL="https://jllllll.github.io/llama-cpp-python-cuBLAS-wheels/$CPU_OPT/$DEVICE"
echo "install llama-cpp-python from --extra-index-url ${EXTRA_INDEX_URL}"
python -m pip install llama-cpp-python --force-reinstall --no-cache --prefer-binary --extra-index-url=$EXTRA_INDEX_URL
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
default_input_lens="8,8,256,1024"
default_output_lens="256,512,1024,1024"
default_parallel_nums="1,2,4,16,32"
input_lens=${1:-$default_input_lens}
output_lens=${2:-$default_output_lens}
parallel_nums=${3:-$default_parallel_nums}
run_benchmark() {
local model_name=$1
local model_type=$2
DB_GPT_MODEL_BENCHMARK=true python pilot/utils/benchmarks/llm/llm_benchmarks.py --model_name ${model_name} --model_type ${model_type} --input_lens ${input_lens} --output_lens ${output_lens} --parallel_nums ${parallel_nums}
}
run_benchmark "vicuna-7b-v1.5" "huggingface"
run_benchmark "vicuna-7b-v1.5" "vllm"
run_benchmark "baichuan2-7b" "huggingface"
run_benchmark "baichuan2-7b" "vllm"
+106
View File
@@ -0,0 +1,106 @@
#!/bin/bash
# This script is used for setting up the environment required for DB-GPT on https://www.autodl.com/
# Usage: source /etc/network_turbo && curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/eosphoros-ai/DB-GPT/main/scripts/setup_autodl_env.sh | bash
# autodl usage:
# conda activate dbgpt
# cd /root/DB-GPT
# bash scripts/examples/load_examples.sh
# dbgpt start webserver --port 6006
DEFAULT_PROXY="true"
USE_PROXY=$DEFAULT_PROXY
initialize_conda() {
conda init bash
eval "$(conda shell.bash hook)"
source ~/.bashrc
if [[ $USE_PROXY == "true" ]]; then
source /etc/network_turbo
# unset http_proxy && unset https_proxy
fi
}
setup_conda_environment() {
conda create -n dbgpt python=3.10 -y
conda activate dbgpt
}
install_sys_packages() {
apt-get update -y && apt-get install git-lfs -y
}
clone_repositories() {
cd /root && git clone https://github.com/eosphoros-ai/DB-GPT.git
mkdir -p /root/DB-GPT/models && cd /root/DB-GPT/models
git clone https://www.modelscope.cn/Jerry0/text2vec-large-chinese.git
git clone https://www.modelscope.cn/qwen/Qwen2-0.5B-Instruct.git
rm -rf /root/DB-GPT/models/text2vec-large-chinese/.git
rm -rf /root/DB-GPT/models/Qwen2-0.5B-Instruct/.git
}
install_dbgpt_packages() {
conda activate dbgpt && cd /root/DB-GPT && pip install -e ".[default]" && pip install transformers_stream_generator einops
cp .env.template .env && sed -i 's/LLM_MODEL=glm-4-9b-chat/LLM_MODEL=qwen2-0.5b-instruct/' .env
}
clean_up() {
rm -rf `pip cache dir`
apt-get clean
rm -f ~/.bash_history
history -c
}
clean_local_data() {
rm -rf /root/DB-GPT/pilot/data
rm -rf /root/DB-GPT/pilot/message
rm -f /root/DB-GPT/logs/*
rm -f /root/DB-GPT/logsDbChatOutputParser.log
rm -rf /root/DB-GPT/pilot/meta_data/alembic/versions/*
rm -rf /root/DB-GPT/pilot/meta_data/*.db
}
usage() {
echo "USAGE: $0 [--use-proxy]"
echo " [--use-proxy] Use proxy settings (Optional)"
echo " [-h|--help] Usage message"
}
# Command line arguments parsing
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--use-proxy)
USE_PROXY="true"
shift
;;
-h|--help)
help="true"
shift
;;
*)
usage
exit 1
;;
esac
done
if [[ $help ]]; then
usage
exit 0
fi
# Main execution
if [[ $USE_PROXY == "true" ]]; then
echo "Using proxy settings..."
source /etc/network_turbo
fi
initialize_conda
setup_conda_environment
install_sys_packages
clone_repositories
install_dbgpt_packages
clean_up
+525
View File
@@ -0,0 +1,525 @@
#!/usr/bin/env python
# /// script
# dependencies = [
# "tomli",
# "click",
# "inquirer",
# "regex",
# ]
# [tool.uv]
# exclude-newer = "2025-03-20T00:00:00Z"
# ///
"""
Enhanced interactive version update script for dbgpt-mono project.
Features:
- Collects all files that need version updates
- Shows a preview of all changes before applying
- Allows user to confirm or reject changes
- Supports dry-run mode to only show changes without applying them
- Can selectively apply changes to specific packages
- Supports standard version formats (X.Y.Z) and pre-release versions (X.Y.Z-beta, X.Y.ZrcN)
- Only updates version numbers without changing file formatting
- Supports _version.py files commonly found in Python packages
Usage:
uv run version_update.py NEW_VERSION [options]
Options:
-y, --yes Apply changes without confirmation
-d, --dry-run Only show changes without applying them
-f, --filter PKG Only update packages containing this string
-h, --help Show help message
Examples:
uv run version_update.py 0.8.0 # Standard version
uv run version_update.py 0.7.0rc0 # Release candidate
uv run version_update.py 0.7.0-beta.1 # Beta version
uv run version_update.py 0.8.0 --yes # Apply all changes without prompting
uv run version_update.py 0.8.0 --dry-run # Only show what would change
uv run version_update.py 0.8.0 --filter dbgpt-core # Only update dbgpt-core package
"""
import argparse
import json
import re
import sys
from dataclasses import dataclass
from pathlib import Path
from typing import List, Optional
import tomli
@dataclass
class VersionChange:
"""Represents a single version change in a file."""
file_path: Path
file_type: str
old_version: str
new_version: str
package_name: str
def __str__(self):
rel_path = self.file_path.as_posix()
return f"{self.package_name:<20} {self.file_type:<12} {rel_path:<50} {self.old_version} -> {self.new_version}"
class VersionUpdater:
"""Class to handle version updates across the project."""
def __init__(self, new_version: str, root_dir: Path, args: argparse.Namespace):
self.new_version = new_version
self.root_dir = root_dir
self.args = args
self.changes: List[VersionChange] = []
# Support: X.Y.Z, X.Y.ZrcN, X.Y.Z-alpha.N, X.Y.Z-beta.N, X.Y.Z-rc.N
self.version_pattern = re.compile(
r"^\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?$|^\d+\.\d+\.\d+[a-zA-Z][a-zA-Z0-9.]*$"
)
def validate_version(self) -> bool:
"""Validate the version format."""
if not self.version_pattern.match(self.new_version):
print("Error: Invalid version format. Examples of valid formats:")
print(" - Standard: 0.7.0, 1.0.0")
print(" - Pre-release: 0.7.0rc0, 0.7.0-beta.1, 1.0.0-alpha.2")
return False
return True
def find_main_config(self) -> Optional[Path]:
"""Find the main project configuration file."""
root_config = self.root_dir / "pyproject.toml"
if not root_config.exists():
# Try to find it in subdirectories
possible_files = list(self.root_dir.glob("**/pyproject.toml"))
if possible_files:
root_config = possible_files[0]
print(f"Found root configuration at: {root_config}")
else:
print("Error: Could not find the project configuration file")
return None
return root_config
def collect_toml_changes(self, file_path: Path, package_name: str) -> bool:
"""Collect version changes needed in a TOML file."""
try:
# Read the entire file content to preserve formatting
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
# Parse the TOML content to extract version information
with open(file_path, "rb") as f:
data = tomli.load(f)
# Check for project.version or tool.poetry.version
if "project" in data and "version" in data["project"]:
old_version = data["project"]["version"]
self.changes.append(
VersionChange(
file_path=file_path,
file_type="pyproject.toml",
old_version=old_version,
new_version=self.new_version,
package_name=package_name,
)
)
return True
# Check for tool.poetry.version
elif (
"tool" in data
and "poetry" in data["tool"]
and "version" in data["tool"]["poetry"]
):
old_version = data["tool"]["poetry"]["version"]
self.changes.append(
VersionChange(
file_path=file_path,
file_type="pyproject.toml",
old_version=old_version,
new_version=self.new_version,
package_name=package_name,
)
)
return True
return False
except Exception as e:
print(f"Error analyzing {file_path}: {str(e)}")
return False
def collect_setup_py_changes(self, file_path: Path, package_name: str) -> bool:
"""Collect version changes needed in a setup.py file."""
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
# Find version pattern - more flexible to detect different formats
version_pattern = r'version\s*=\s*["\']([^"\']+)["\']'
match = re.search(version_pattern, content)
if match:
old_version = match.group(1)
self.changes.append(
VersionChange(
file_path=file_path,
file_type="setup.py",
old_version=old_version,
new_version=self.new_version,
package_name=package_name,
)
)
return True
return False
except Exception as e:
print(f"Error analyzing {file_path}: {str(e)}")
return False
def collect_version_py_changes(self, file_path: Path, package_name: str) -> bool:
"""Collect version changes needed in a _version.py file."""
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
# Collect version pattern - more flexible to detect different formats
# e.g. version = "0.7.0"
version_pattern = r'version\s*=\s*["\']([^"\']+)["\']'
match = re.search(version_pattern, content)
if match:
old_version = match.group(1)
self.changes.append(
VersionChange(
file_path=file_path,
file_type="_version.py",
old_version=old_version,
new_version=self.new_version,
package_name=package_name,
)
)
return True
return False
except Exception as e:
print(f"Error analyzing {file_path}: {str(e)}")
return False
def collect_json_changes(self, file_path: Path, package_name: str) -> bool:
"""Collect version changes needed in a JSON file."""
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
data = json.loads(content)
if "version" in data:
old_version = data["version"]
self.changes.append(
VersionChange(
file_path=file_path,
file_type="package.json",
old_version=old_version,
new_version=self.new_version,
package_name=package_name,
)
)
return True
return False
except Exception as e:
print(f"Error analyzing {file_path}: {str(e)}")
return False
def find_workspace_members(self, workspace_members: List[str]) -> List[Path]:
"""Find all workspace member directories."""
members = []
for pattern in workspace_members:
# Handle glob patterns
if "*" in pattern:
found = list(self.root_dir.glob(pattern))
members.extend(found)
else:
path = self.root_dir / pattern
if path.exists():
members.append(path)
return members
def collect_all_changes(self) -> bool:
"""Collect all version changes needed across the project."""
# Find main project configuration
root_config = self.find_main_config()
if not root_config:
return False
# Start with the main config file
self.collect_toml_changes(root_config, "root-project")
# Find and parse workspace members from configuration
workspace_members = []
try:
with open(root_config, "rb") as f:
data = tomli.load(f)
if (
"tool" in data
and "uv" in data["tool"]
and "workspace" in data["tool"]["uv"]
):
workspace_members = data["tool"]["uv"]["workspace"].get("members", [])
except Exception as e:
print(f"Warning: Could not parse workspace members: {str(e)}")
# Find all package directories
package_dirs = self.find_workspace_members(workspace_members)
print(f"Found {len(package_dirs)} workspace packages to check")
# Check each package directory for version files
for pkg_dir in package_dirs:
package_name = pkg_dir.name
# Skip if filter is applied and doesn't match
if self.args.filter and self.args.filter not in package_name:
continue
# Check for pyproject.toml
pkg_toml = pkg_dir / "pyproject.toml"
if pkg_toml.exists():
self.collect_toml_changes(pkg_toml, package_name)
# Check for setup.py
setup_py = pkg_dir / "setup.py"
if setup_py.exists():
self.collect_setup_py_changes(setup_py, package_name)
# Check for package.json
package_json = pkg_dir / "package.json"
if package_json.exists():
self.collect_json_changes(package_json, package_name)
# Check for _version.py files
version_py_files = list(pkg_dir.glob("**/_version.py"))
for version_py in version_py_files:
self.collect_version_py_changes(version_py, package_name)
return len(self.changes) > 0
def apply_changes(self) -> int:
"""Apply all collected changes."""
applied_count = 0
for change in self.changes:
try:
if change.file_type == "pyproject.toml":
self._update_toml_file(change.file_path)
elif change.file_type == "setup.py":
self._update_setup_py_file(change.file_path)
elif change.file_type == "package.json":
self._update_json_file(change.file_path)
elif change.file_type == "_version.py":
self._update_version_py_file(change.file_path)
applied_count += 1
print(f"✅ Updated {change.file_path}")
except Exception as e:
print(f"❌ Failed to update {change.file_path}: {str(e)}")
return applied_count
def _update_toml_file(self, file_path: Path) -> None:
"""Update version in a TOML file using regex to preserve formatting."""
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
updated = False
# Update project.version
project_version_pattern = (
r'(\[project\][^\[]*?version\s*=\s*["\'](.*?)["\']\s*)'
)
if re.search(project_version_pattern, content, re.DOTALL):
project_pattern = r'(\[project\][^\[]*?version\s*=\s*["\'](.*?)["\']\s*)'
content = re.sub(
project_pattern,
lambda m: m.group(0).replace(m.group(2), self.new_version),
content,
flags=re.DOTALL,
)
updated = True
poetry_version_pattern = (
r'(\[tool\.poetry\][^\[]*?version\s*=\s*["\'](.*?)["\']\s*)'
)
if re.search(poetry_version_pattern, content, re.DOTALL):
poetry_pattern = (
r'(\[tool\.poetry\][^\[]*?version\s*=\s*["\'](.*?)["\']\s*)'
)
content = re.sub(
poetry_pattern,
lambda m: m.group(0).replace(m.group(2), self.new_version),
content,
flags=re.DOTALL,
)
updated = True
if not updated:
version_line_pattern = r'(^version\s*=\s*["\'](.*?)["\']\s*$)'
content = re.sub(
version_line_pattern,
lambda m: m.group(0).replace(m.group(2), self.new_version),
content,
flags=re.MULTILINE,
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)
def _update_setup_py_file(self, file_path: Path) -> None:
"""Update version in a setup.py file."""
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
# Find and replace version
version_pattern = r'(version\s*=\s*["\'])([^"\']+)(["\'])'
updated_content = re.sub(
version_pattern, rf"\g<1>{self.new_version}\g<3>", content
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(updated_content)
def _update_version_py_file(self, file_path: Path) -> None:
"""Update version in a _version.py file."""
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
version_pattern = r'(version\s*=\s*["\'])([^"\']+)(["\'])'
updated_content = re.sub(
version_pattern, rf"\g<1>{self.new_version}\g<3>", content
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(updated_content)
def _update_json_file(self, file_path: Path) -> None:
"""Update version in a JSON file while preserving formatting."""
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
version_pattern = r'("version"\s*:\s*")([^"]+)(")'
updated_content = re.sub(
version_pattern, rf"\g<1>{self.new_version}\g<3>", content
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(updated_content)
def show_changes(self) -> None:
"""Display the collected changes."""
if not self.changes:
print("No changes to apply.")
return
print("\n" + "=" * 100)
print(f"Version changes to apply: {self.new_version}")
print("=" * 100)
print(f"{'Package':<20} {'File Type':<12} {'Path':<50} {'Version Change'}")
print("-" * 100)
for change in self.changes:
print(str(change))
print("=" * 100)
print(f"Total: {len(self.changes)} file(s) to update")
print("=" * 100)
def prompt_for_confirmation(self) -> bool:
"""Prompt the user for confirmation."""
if self.args.yes:
return True
response = input("\nApply these changes? [y/N]: ").strip().lower()
return response in ["y", "yes"]
def run(self) -> bool:
"""Run the updater."""
if not self.validate_version():
return False
# Collect all changes
if not self.collect_all_changes():
print("No files found that need version updates.")
return False
# Show the changes
self.show_changes()
# If dry run, exit now
if self.args.dry_run:
print("\nDry run complete. No changes were applied.")
return True
# Prompt for confirmation
if not self.prompt_for_confirmation():
print("\nOperation cancelled. No changes were applied.")
return False
# Apply the changes
applied_count = self.apply_changes()
print(
f"\n🎉 Version update complete! Updated {applied_count} files to version {self.new_version}"
)
return True
def parse_args():
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
description="Update version numbers across the dbgpt-mono project",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=__doc__.split("\n\n")[2], # Extract usage examples
)
parser.add_argument(
"version", help="New version number (supports standard and pre-release formats)"
)
parser.add_argument(
"-y", "--yes", action="store_true", help="Apply changes without confirmation"
)
parser.add_argument(
"-d",
"--dry-run",
action="store_true",
help="Only show changes without applying them",
)
parser.add_argument(
"-f", "--filter", help="Only update packages containing this string"
)
return parser.parse_args()
def main():
"""Main entry point for the script."""
args = parse_args()
# Initialize the updater
updater = VersionUpdater(new_version=args.version, root_dir=Path("../"), args=args)
# Run the updater
success = updater.run()
sys.exit(0 if success else 1)
if __name__ == "__main__":
main()