Skip to content

Commit c4321c6

Browse files
committed
Add shared Black Belt CLI AI engine transport
1 parent 707e5c0 commit c4321c6

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎bin/blackbelt-engine.sh‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Shared Black Belt AI transport. The CLI front ends send canonical JSON here.
5+
# Default engine: Ollama on localhost. Override with BBEA_ENGINE_URL and BBEA_MODEL.
6+
ENGINE_URL="${BBEA_ENGINE_URL:-http://127.0.0.1:11434/api/generate}"
7+
MODEL="${BBEA_MODEL:-llama3.1:8b}"
8+
PROMPT_FILE="${BBEA_SYSTEM_PROMPT:-black.belt/sharp/system.prompt}"
9+
10+
if [[ ! -f "$PROMPT_FILE" ]]; then
11+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
12+
ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
13+
PROMPT_FILE="$ROOT/black.belt/sharp/system.prompt"
14+
fi
15+
16+
if [[ ! -f "$PROMPT_FILE" ]]; then
17+
echo "Black Belt system prompt not found: $PROMPT_FILE" >&2
18+
exit 2
19+
fi
20+
21+
INPUT="$(cat)"
22+
if [[ -z "${INPUT//[[:space:]]/}" ]]; then
23+
echo "No JSON audit input received." >&2
24+
exit 2
25+
fi
26+
27+
python3 - "$PROMPT_FILE" "$MODEL" "$INPUT" <<'PY' | curl --fail-with-body -sS "$ENGINE_URL" -H 'Content-Type: application/json' --data-binary @-
28+
import json, pathlib, sys
29+
prompt_path, model, audit_input = sys.argv[1], sys.argv[2], sys.argv[3]
30+
system_prompt = pathlib.Path(prompt_path).read_text(encoding='utf-8')
31+
try:
32+
parsed = json.loads(audit_input)
33+
except json.JSONDecodeError as exc:
34+
raise SystemExit(f"Invalid audit JSON: {exc}")
35+
request = {
36+
"model": model,
37+
"system": system_prompt,
38+
"prompt": json.dumps(parsed, ensure_ascii=False, separators=(",", ":")),
39+
"stream": False,
40+
"format": "json"
41+
}
42+
print(json.dumps(request, ensure_ascii=False))
43+
PY

0 commit comments

Comments
 (0)