File size: 2,412 Bytes
dc7b96e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -euo pipefail

DG_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PYTHON="${DG_HAYSTACK_PYTHON:-$DG_ROOT/.venv-haystack/bin/python}"
REPO=""
CONFIG=""
HELP_LOCAL=0
DRY_RUN=0

usage() {
  cat <<'EOF'
Runs Haystack BM25 RAG against the local DiffusionGemma OpenAI-compatible profile.

Usage:
  scripts/run_haystack_local.sh [--repo PATH] [--config PATH] [--dry-run|--smoke-import|--task TEXT]

Default config:
  configs/client_profiles/haystack.dg.json

Examples:
  scripts/run_haystack_local.sh --repo /repo --dry-run
  scripts/run_haystack_local.sh --repo /repo --smoke-import
  scripts/run_haystack_local.sh --repo /repo --task "Where is add(a, b) implemented?"
EOF
}

while [[ $# -gt 0 ]]; do
  case "$1" in
    --repo)
      REPO="$2"
      shift 2
      ;;
    --config)
      CONFIG="$2"
      shift 2
      ;;
    --help-local)
      HELP_LOCAL=1
      shift
      ;;
    --)
      shift
      break
      ;;
    *)
      break
      ;;
  esac
done

for arg in "$@"; do
  if [[ "$arg" == "--dry-run" ]]; then
    DRY_RUN=1
    break
  fi
done

if [[ "$HELP_LOCAL" == "1" ]]; then
  usage
  exit 0
fi

if [[ -z "$REPO" ]]; then
  REPO="$PWD"
fi
REPO="$(cd "$REPO" && pwd)"

python_path() {
  if [[ "$PYTHON" == *.exe ]] && command -v wslpath >/dev/null 2>&1; then
    wslpath -w "$1"
    return
  fi
  if [[ "${OS:-}" == "Windows_NT" ]] && command -v cygpath >/dev/null 2>&1; then
    cygpath -w "$1"
  else
    printf '%s\n' "$1"
  fi
}

if [[ ! -x "$PYTHON" && "$DRY_RUN" != "1" ]]; then
  "$DG_ROOT/scripts/install_haystack_local.sh" >/tmp/dg-haystack-install.log
fi

if [[ -z "$CONFIG" ]]; then
  if [[ -s "$REPO/.dg-agent/haystack.dg.json" ]]; then
    CONFIG="$REPO/.dg-agent/haystack.dg.json"
  else
    CONFIG="$DG_ROOT/configs/client_profiles/haystack.dg.json"
  fi
fi

export OPENAI_BASE_URL="${OPENAI_BASE_URL:-http://127.0.0.1:8090/v1}"
export OPENAI_API_KEY="${OPENAI_API_KEY:-dummy}"
export HAYSTACK_MODEL="${HAYSTACK_MODEL:-diffusiongemma-local}"
export DG_AGENT_CALLER_CWD="${DG_AGENT_CALLER_CWD:-$REPO}"

REPO_FOR_PY="$(python_path "$REPO")"
CONFIG_FOR_PY="$(python_path "$CONFIG")"
RUNNER_FOR_PY="$(python_path "$DG_ROOT/scripts/dg_haystack_runner.py")"

if [[ -x "$PYTHON" ]]; then
  exec "$PYTHON" "$RUNNER_FOR_PY" --repo "$REPO_FOR_PY" --config "$CONFIG_FOR_PY" "$@"
fi

exec python3 "$RUNNER_FOR_PY" --repo "$REPO_FOR_PY" --config "$CONFIG_FOR_PY" "$@"