kitchen: bridge-whisper remaining pitchwell tree
This commit is contained in:
parent
0145c5977d
commit
79aa5c9339
1 changed files with 45 additions and 0 deletions
45
kitchen/bin/rh-chat.sh
Executable file
45
kitchen/bin/rh-chat.sh
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
# rabbithole chat helper — talkative defaults (temperature 1.05)
|
||||
set -euo pipefail
|
||||
MODEL="${1:?model}"
|
||||
SYSTEM_FILE="${2:?system file or -}"
|
||||
USER_MSG="${3:?user message}"
|
||||
OUT="${4:?out path}"
|
||||
TEMP="${TEMP:-1.05}"
|
||||
TOP_P="${TOP_P:-0.95}"
|
||||
NUM_PREDICT="${NUM_PREDICT:-900}"
|
||||
BASE="${OLLAMA_HOST:-http://127.0.0.1:11436}"
|
||||
|
||||
if [[ "$SYSTEM_FILE" == "-" ]]; then
|
||||
SYS=$(cat)
|
||||
else
|
||||
SYS=$(cat "$SYSTEM_FILE")
|
||||
fi
|
||||
|
||||
python3 - "$MODEL" "$SYS" "$USER_MSG" "$OUT" "$TEMP" "$TOP_P" "$NUM_PREDICT" "$BASE" <<'PY'
|
||||
import json, sys, urllib.request
|
||||
model, system, user, out, temp, top_p, num_predict, base = sys.argv[1:9]
|
||||
body = {
|
||||
"model": model,
|
||||
"stream": False,
|
||||
"options": {
|
||||
"temperature": float(temp),
|
||||
"top_p": float(top_p),
|
||||
"num_predict": int(num_predict),
|
||||
},
|
||||
"messages": [
|
||||
{"role": "system", "content": system},
|
||||
{"role": "user", "content": user},
|
||||
],
|
||||
}
|
||||
req = urllib.request.Request(
|
||||
base.rstrip("/") + "/api/chat",
|
||||
data=json.dumps(body).encode(),
|
||||
headers={"Content-Type": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=300) as r:
|
||||
text = (json.load(r).get("message") or {}).get("content") or ""
|
||||
open(out, "w").write(text.strip() + "\n")
|
||||
print("ok", out, "chars", len(text), "temp", temp)
|
||||
PY
|
||||
Loading…
Add table
Add a link
Reference in a new issue