devzone 0.56.0 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,171 +0,0 @@
1
- #!/usr/bin/env bash
2
- # devzone llm bench (#593), sourced by llm.sh (uses its NS, k, preset_read
3
- # and refuse): llama-bench of the model in a Kubernetes Job of the
4
- # namespace devzone-llm (image full-<llamaBuild> of the chart, same build as the
5
- # server, pulled only here), then a table, a threads recommendation and whether
6
- # the speed is enough for opencode.
7
- # devzone llm bench [--apply] [--threads LIST] [--prompt N] [--gen N]
8
- # --apply sets threads=<best> on the release llm (helm upgrade, values kept).
9
- # Env: LLM_BENCH_ATTENTE (seconds, 1800: wait limit and activeDeadlineSeconds of
10
- # the Job, which stops by itself if the call is interrupted), LLM_BENCH_POLL
11
- # (seconds, 5), LLM_BENCH_SIGNE (seconds, 30: a progress line at least this
12
- # often, so that the connection of kubectl exec is not cut), LLM_BENCH_MIN_PP (50 tok/s, prompt reading), LLM_BENCH_MIN_TG (8 tok/s,
13
- # generation). The Job is deleted at the end, even on failure. bash 3.2 (macOS).
14
-
15
- BENCH_JOB=llm-bench
16
-
17
- # Server present, read with the rights of the namespace (the account of the pod
18
- # cannot read a namespace, a cluster resource: installed would fail for it)
19
- bench_present() { k get deployment llm >/dev/null 2>&1; }
20
-
21
- # Job deleted (no error when it is already gone)
22
- bench_cleanup() { k delete job "$BENCH_JOB" --ignore-not-found --wait=false >/dev/null 2>&1 || true; }
23
-
24
- # Phase of the Job for the progress line, read from the state of the container
25
- # (not the phase of the pod): waiting (ContainerCreating, PullImage...) is
26
- # pulling, running or terminated is measuring. The caller keeps the phase
27
- # monotone: once measuring, it never goes back to pulling.
28
- bench_phase() {
29
- local etat
30
- etat="$(k get pods -l app=llm-bench -o jsonpath='{.items[0].status.containerStatuses[0].state.running.startedAt}|{.items[0].status.containerStatuses[0].state.terminated.reason}' 2>/dev/null || true)"
31
- case "$etat" in
32
- "|" | "") echo "pulling the image" ;;
33
- *) echo "measuring" ;;
34
- esac
35
- }
36
-
37
- # Waits for the Job: 0 done, 1 failed, 2 timeout. Writes a line (phase,
38
- # elapsed time) at least every LLM_BENCH_SIGNE seconds
39
- bench_wait() {
40
- local waited=0 poll="${LLM_BENCH_POLL:-5}" limit="${LLM_BENCH_ATTENTE:-1800}" beat="${LLM_BENCH_SIGNE:-30}" st last="" phase="pulling the image"
41
- while [ "$waited" -lt "$limit" ]; do
42
- st="$(k get job "$BENCH_JOB" -o jsonpath='{.status.succeeded}/{.status.failed}' 2>/dev/null || true)"
43
- case "$st" in
44
- 1/*) return 0 ;;
45
- */[1-9]*) return 1 ;;
46
- esac
47
- if [ -z "$last" ] || [ $((waited - last)) -ge "$beat" ]; then
48
- # Monotone: once measuring, the phase is not read again
49
- [ "$phase" = measuring ] || phase="$(bench_phase)"
50
- echo " … $phase, ${waited}s elapsed"
51
- last=$waited
52
- fi
53
- sleep "$poll"
54
- waited=$((waited + poll))
55
- done
56
- return 2
57
- }
58
-
59
- # Table "threads pp tg" (tok/s) from the JSON of llama-bench (logs of the Job:
60
- # the array is the part between the line "[" and the line "]")
61
- bench_rows() {
62
- sed -n '/^\[/,/^\]/p' | jq -r '
63
- group_by(.n_threads)[]
64
- | [.[0].n_threads,
65
- (map(select(.n_prompt > 0 and .n_gen == 0)) | .[0].avg_ts // 0),
66
- (map(select(.n_gen > 0 and .n_prompt == 0)) | .[0].avg_ts // 0)]
67
- | @tsv' 2>/dev/null
68
- }
69
-
70
- # Best row (generation speed, then fewer threads) and the verdict, from the
71
- # rows on stdin: prints the table then "best=<n>" and "ok=0|1"
72
- bench_report() {
73
- awk -v mpp="${LLM_BENCH_MIN_PP:-50}" -v mtg="${LLM_BENCH_MIN_TG:-8}" '
74
- { t[NR] = $1; pp[NR] = $2; tg[NR] = $3 }
75
- END {
76
- printf "%-8s %-22s %s\n", "threads", "prompt (tok/s)", "generation (tok/s)"
77
- b = 0
78
- for (i = 1; i <= NR; i++) {
79
- printf "%-8s %-22.1f %.1f\n", t[i], pp[i], tg[i]
80
- if (b == 0 || tg[i] > tg[b] || (tg[i] == tg[b] && t[i] + 0 < t[b] + 0)) b = i
81
- }
82
- if (b == 0) exit 1
83
- print "best=" t[b]
84
- print "ok=" ((pp[b] >= mpp && tg[b] >= mtg) ? 1 : 0)
85
- }'
86
- }
87
-
88
- # Commands proposed to the user, by place: the Kubernetes workspace runs the
89
- # bench through devzone workspace services (DEVZONE_SERVICES_ADMIN, set by
90
- # services-admin.sh); the Docker container keeps devzone llm
91
- bench_cmds() {
92
- if [ -n "${DEVZONE_SERVICES_ADMIN:-}" ]; then
93
- CMD_APPLY="devzone workspace services bench llm --apply"
94
- CMD_LIGHT="devzone workspace services disable llm && devzone workspace services enable llm --preset light"
95
- else
96
- CMD_APPLY="devzone llm bench --apply"
97
- CMD_LIGHT="devzone disable llm && devzone enable llm --preset light"
98
- fi
99
- }
100
-
101
- bench_apply() {
102
- helm --kube-context devzone upgrade llm "$CHART_CODE/charts/devzone-llm" -n "$NS" --reset-then-reuse-values --set "threads=$1" >/dev/null || return 1
103
- wait_ready
104
- }
105
-
106
- bench() {
107
- local apply="" want="" arg threads="" prompt="" gen="" sets logs rows report best ok
108
- local -a args
109
- for arg in "$@"; do
110
- if [ -n "$want" ]; then
111
- case "$want" in
112
- threads) threads="$arg" ;;
113
- prompt) prompt="$arg" ;;
114
- gen) gen="$arg" ;;
115
- esac
116
- want=""
117
- continue
118
- fi
119
- case "$arg" in
120
- --apply) apply=1 ;;
121
- --threads | --prompt | --gen) want="${arg#--}" ;;
122
- *) refuse "unknown argument: $arg (devzone llm bench [--apply] [--threads 4,8] [--prompt 128] [--gen 32])" ;;
123
- esac
124
- done
125
- [ -z "$want" ] || refuse "--$want needs a value"
126
- # In the pod only devzone workspace services (DEVZONE_SERVICES_ADMIN) has rights on the namespace
127
- if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ] && [ -z "${DEVZONE_SERVICES_ADMIN:-}" ]; then
128
- echo "devzone: llm bench runs from your computer: devzone workspace services bench llm" >&2
129
- exit 2
130
- fi
131
- bench_present || refuse "bench: the module is not enabled (devzone enable llm)"
132
- sets="$(llm_preset_sets "$(preset_read)") bench.enabled=true"
133
- [ -z "$threads" ] || sets="$sets bench.threads=${threads//,/\\,}" # helm --set: a comma separates keys
134
- [ -z "$prompt" ] || sets="$sets bench.prompt=$prompt"
135
- [ -z "$gen" ] || sets="$sets bench.gen=$gen"
136
- sets="$sets bench.deadline=${LLM_BENCH_ATTENTE:-1800}"
137
- args=()
138
- for arg in $sets; do args+=(--set "$arg"); done
139
- trap bench_cleanup EXIT INT TERM
140
- bench_cleanup
141
- echo "▶ llama-bench in the namespace $NS (image full-<build>: larger than the server image, pulled on first use; the server keeps running, so the numbers are a bit low)…"
142
- helm template llm "$CHART_CODE/charts/devzone-llm" -n "$NS" "${args[@]}" --show-only templates/bench-job.yaml | k apply -f - >/dev/null || return 1
143
- bench_wait || {
144
- echo "devzone: llm: bench Job failed or timed out (LLM_BENCH_ATTENTE=${LLM_BENCH_ATTENTE:-1800}s): kubectl --context devzone -n $NS logs job/$BENCH_JOB" >&2
145
- k logs "job/$BENCH_JOB" --tail=5 >&2 2>/dev/null || true
146
- return 1
147
- }
148
- logs="$(k logs "job/$BENCH_JOB" 2>/dev/null || true)"
149
- rows="$(printf '%s\n' "$logs" | bench_rows)"
150
- [ -n "$rows" ] || { echo "devzone: llm: no llama-bench result in the logs of the Job" >&2; return 1; }
151
- report="$(printf '%s\n' "$rows" | bench_report)"
152
- printf '%s\n' "$report" | grep -v '^best=\|^ok='
153
- best="$(printf '%s\n' "$report" | sed -n 's/^best=//p')"
154
- ok="$(printf '%s\n' "$report" | sed -n 's/^ok=//p')"
155
- echo "▶ Recommended: threads=$best"
156
- bench_cmds
157
- if [ "$ok" = 1 ]; then
158
- echo "✔ Fast enough for opencode (prompt >= ${LLM_BENCH_MIN_PP:-50} tok/s, generation >= ${LLM_BENCH_MIN_TG:-8} tok/s)"
159
- else
160
- echo "⚠ Too slow for opencode (needs prompt >= ${LLM_BENCH_MIN_PP:-50} tok/s and generation >= ${LLM_BENCH_MIN_TG:-8} tok/s)"
161
- if [ "$(preset_read)" != light ]; then
162
- echo " Lighter model (3B, context 16k, 2.1 GB download): $CMD_LIGHT"
163
- fi
164
- fi
165
- if [ -n "$apply" ]; then
166
- bench_apply "$best" || return 1
167
- echo "✔ threads=$best applied to the release llm"
168
- else
169
- echo " $CMD_APPLY sets threads=$best on the release"
170
- fi
171
- }
@@ -1,262 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Module llm (#586): local code model (llama.cpp llama-server, CPU) in the
3
- # cluster of the services, namespace devzone-llm, chart charts/devzone-llm.
4
- # llm.sh install [--preset default|light] [--context CTX]
5
- # llm.sh uninstall release removed, the volume llm-models is kept
6
- # llm.sh status | relay-start | relay-stop | policy (ingress from devzone-workspace)
7
- # llm.sh preset [--preset P] preset stored for the next install (Argo CD path)
8
- # llm.sh apply on|off [...] what `devzone enable|disable llm` runs
9
- # llm.sh delete-data [--yes] namespace and volume removed (the model is downloaded again)
10
- # llm.sh bench [--apply] llama-bench Job and threads recommendation (bench.sh)
11
- # First start = model download: LLM_ATTENTE (seconds, default 1800) is the wait.
12
- # Relay LLM_PORT (default 8089); opencode provider: opencode.sh. bash 3.2 (macOS).
13
- set -euo pipefail
14
-
15
- ICI="$(cd "$(dirname "$0")" && pwd)"
16
- RACINE="${DEVZONE_RACINE:-$(dirname "$(dirname "$ICI")")}"
17
- # shellcheck disable=SC2034 # read by cluster.sh (sourced library)
18
- ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
19
- # shellcheck source=SCRIPTDIR/../cluster.sh
20
- # shellcheck disable=SC1091
21
- . "$ICI/../cluster.sh"
22
- # shellcheck source=SCRIPTDIR/../chart-direct.sh
23
- # shellcheck disable=SC1091
24
- . "$ICI/../chart-direct.sh"
25
- # shellcheck source=SCRIPTDIR/../isolement.sh
26
- # shellcheck disable=SC1091
27
- . "$ICI/../isolement.sh"
28
- # shellcheck source=SCRIPTDIR/presets.sh
29
- # shellcheck disable=SC1091
30
- . "$ICI/presets.sh"
31
- # shellcheck source=SCRIPTDIR/bench.sh
32
- # shellcheck disable=SC1091
33
- . "$ICI/bench.sh"
34
- # Memory check of the services cluster, shared with the other modules (#608)
35
- # shellcheck source=SCRIPTDIR/../memoire.sh
36
- # shellcheck disable=SC1091
37
- . "$ICI/../memoire.sh"
38
-
39
- NS=devzone-llm
40
- STATE_DIR="$RACINE/workspace/.llm"
41
- LLM_PORT="${LLM_PORT:-8089}"
42
- LLM_ATTENTE="${LLM_ATTENTE:-1800}"
43
- LLM_SIZE="${LLM_SIZE:-8Gi}"
44
-
45
- refuse() { echo "devzone: llm: $*" >&2; exit 2; }
46
-
47
- k() { kubectl --context devzone -n "$NS" "$@"; }
48
-
49
- installed() { compte_admin "$(compte_ctx)" get namespace "$NS" >/dev/null 2>&1; }
50
-
51
- # Preset stored by the last install, "default" without one
52
- preset_read() {
53
- local p
54
- p="$(cat "$STATE_DIR/preset" 2>/dev/null || true)"
55
- llm_preset_name "$p" 2>/dev/null || echo default
56
- }
57
-
58
- # --preset P and --context C of the arguments: PRESET and WANTED_CTX are set
59
- parse_args() {
60
- local want="" arg
61
- PRESET=""
62
- WANTED_CTX=""
63
- for arg in "$@"; do
64
- if [ -n "$want" ]; then
65
- case "$want" in
66
- preset) PRESET="$arg" ;;
67
- context) WANTED_CTX="$arg" ;;
68
- esac
69
- want=""
70
- continue
71
- fi
72
- case "$arg" in
73
- --preset) want=preset ;;
74
- --context) want=context ;;
75
- *) refuse "unknown argument: $arg (devzone enable llm [--preset light] [--context CTX])" ;;
76
- esac
77
- done
78
- [ -z "$want" ] || refuse "--$want needs a value"
79
- if [ -n "$PRESET" ]; then
80
- PRESET="$(llm_preset_name "$PRESET")" || refuse "unknown preset (default or light)"
81
- fi
82
- }
83
-
84
- # Stores the preset: the explicit one, else the one already stored
85
- preset_store() {
86
- parse_args "$@"
87
- [ -n "$PRESET" ] || PRESET="$(preset_read)"
88
- mkdir -p "$STATE_DIR"
89
- printf '%s\n' "$PRESET" >"$STATE_DIR/preset"
90
- }
91
-
92
- # Ingress from the workspace namespace (the pod of the workspace reaches
93
- # llm:8080), next to the same-namespace rule of namespace_isoler
94
- policy() {
95
- kubectl --context devzone -n "$NS" apply -f - >/dev/null <<YAML
96
- apiVersion: networking.k8s.io/v1
97
- kind: NetworkPolicy
98
- metadata:
99
- name: devzone-llm-workspace
100
- labels:
101
- app.kubernetes.io/managed-by: devzone
102
- spec:
103
- podSelector: {}
104
- ingress:
105
- - from:
106
- - namespaceSelector:
107
- matchLabels:
108
- kubernetes.io/metadata.name: devzone-workspace
109
- YAML
110
- }
111
-
112
- # Waits for the deployment, a progress line each minute (the model is
113
- # downloaded on the first start)
114
- wait_ready() {
115
- local waited=0 step=60
116
- echo "▶ Waiting for the model (first start: download, several minutes; timeout ${LLM_ATTENTE}s, LLM_ATTENTE)…"
117
- while [ "$waited" -lt "$LLM_ATTENTE" ]; do
118
- if k rollout status deployment/llm --timeout="${step}s" >/dev/null 2>&1; then
119
- return 0
120
- fi
121
- waited=$((waited + step))
122
- echo " … ${waited}s/${LLM_ATTENTE}s: model not ready yet"
123
- done
124
- echo "devzone: llm: not ready after ${LLM_ATTENTE}s: kubectl --context devzone -n $NS logs deploy/llm -c fetch-model" >&2
125
- return 1
126
- }
127
-
128
- install() {
129
- local ctx sets minimum_go=12 astuce=""
130
- local -a args
131
-
132
- preset_store "$@"
133
- # The light preset (3B) asks for 8 Gi, the 7B model for 12 Gi
134
- if [ "$(preset_read)" = light ]; then
135
- minimum_go=8
136
- else
137
- astuce="--preset light (8 Go)"
138
- fi
139
- verifier_memoire_module llm "$minimum_go" "$astuce" || return 2
140
-
141
- ctx="$(cluster_lu)"
142
- if [ -z "$ctx" ]; then
143
- ctx="$(cluster_choisir "$WANTED_CTX")" || return 2
144
- cluster_ecrire "$ctx"
145
- fi
146
- cluster_preparer "$ctx"
147
- contexte_devzone_poser "$ctx" || { echo "devzone: llm: cannot set the devzone context on $ctx" >&2; return 1; }
148
- echo "▶ Local model on the cluster $ctx (namespace $NS, preset $(preset_read))…"
149
- compte_namespace "$ctx" "$NS"
150
- namespace_isoler "$NS" >/dev/null
151
- policy
152
- sets="$(llm_preset_sets "$(preset_read)") size=$LLM_SIZE"
153
- read -r -a args <<<"$sets"
154
- chart_install llm "$NS" "${args[@]}" || return 1
155
- wait_ready || return 1
156
- relais_arreter llm
157
- relais_lancer llm "$ctx" "$NS" svc/llm "$LLM_PORT:8080"
158
- bash "$ICI/opencode.sh" set
159
- echo "✔ Local model ready: http://llm.$NS.svc.cluster.local:8080/v1 (127.0.0.1:$LLM_PORT here)"
160
- }
161
-
162
- # The release leaves, the volume (model) and the namespace stay
163
- uninstall() {
164
- local ctx
165
- ctx="$(cluster_lu)"
166
- relais_arreter llm
167
- bash "$ICI/opencode.sh" unset
168
- if [ -n "$ctx" ] && installed; then
169
- contexte_devzone_poser "$ctx" || true
170
- helm --kube-context devzone uninstall llm -n "$NS" >/dev/null 2>&1 || true
171
- echo "✔ llm removed from $ctx; volume llm-models kept (devzone llm delete-data removes it)"
172
- fi
173
- }
174
-
175
- delete_data() {
176
- local ctx yes="" answer
177
- ctx="$(cluster_lu)"
178
- [ "${1:-}" != --yes ] || yes=1
179
- installed || { echo "devzone: llm: nothing to delete"; return 0; }
180
- if [ -z "$yes" ]; then
181
- cluster_interactif || refuse "no terminal: devzone llm delete-data --yes"
182
- printf 'Delete the namespace %s and the downloaded model? [y/N] ' "$NS" >&2
183
- read -r answer || answer=""
184
- case "$answer" in y | Y | yes | o | O | oui) ;; *) echo "Aborted: nothing deleted."; return 0 ;; esac
185
- fi
186
- uninstall
187
- compte_retirer "$ctx" "$NS" >/dev/null 2>&1 || true
188
- compte_admin "$ctx" delete namespace "$NS" --wait=true >/dev/null
189
- cluster_liberer "$ctx"
190
- echo "✔ namespace $NS and model volume deleted"
191
- }
192
-
193
- status() {
194
- local ctx mem
195
- ctx="$(cluster_lu)"
196
- if [ -z "$ctx" ] || ! installed; then
197
- echo "disabled"
198
- return 0
199
- fi
200
- if [ "$(k get deployment llm -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
201
- echo "not ready on $ctx: starting (first download) or failed, devzone apply"
202
- return 0
203
- fi
204
- mem="$(k get deployment llm -o jsonpath='{.spec.template.spec.containers[0].resources.limits.memory}' 2>/dev/null || true)"
205
- if relais_actif llm; then
206
- echo "ready on $ctx: $(llm_preset_file "$(preset_read)"), memory limit ${mem:-?}, reachable 127.0.0.1:$LLM_PORT"
207
- else
208
- echo "ready on $ctx: $(llm_preset_file "$(preset_read)"), memory limit ${mem:-?}, relay stopped: devzone apply"
209
- fi
210
- }
211
-
212
- relay_start() {
213
- local ctx
214
- ctx="$(cluster_lu)"
215
- [ -z "$ctx" ] || ! installed || relais_lancer llm "$ctx" "$NS" svc/llm "$LLM_PORT:8080"
216
- }
217
-
218
- # Writes llm=off in the state file (bad argument, no cluster)
219
- state_off() {
220
- [ -f "$ETAT" ] || return 0
221
- grep -v '^llm=' "$ETAT" >"$ETAT.tmp" || true
222
- echo "llm=off" >>"$ETAT.tmp"
223
- mv "$ETAT.tmp" "$ETAT"
224
- }
225
-
226
- # What `devzone enable|disable llm` runs: on installs (or restarts the relay),
227
- # off removes the release; a failure leaves a marker read by devzone status
228
- apply() {
229
- local action="${1:-}" current marker="$ETAT-echec-llm"
230
- shift || true
231
- if [ "$action" = on ]; then
232
- current="$(status)"
233
- if [[ "$current" == *"relay stopped"* ]]; then
234
- relay_start
235
- echo "devzone: llm: relay restarted"
236
- elif [[ "$current" == "ready on"* ]]; then
237
- bash "$ICI/opencode.sh" set && echo "devzone: llm already active, nothing to do."
238
- elif ! bash "${BASH_SOURCE[0]}" install "$@"; then
239
- state_off
240
- echo llm >"$marker"
241
- return 1
242
- fi
243
- rm -f "$marker"
244
- else
245
- uninstall
246
- rm -f "$marker"
247
- fi
248
- }
249
-
250
- case "${1:-}" in
251
- install) install "${@:2}" ;;
252
- uninstall) uninstall ;;
253
- status) status ;;
254
- preset) preset_store "${@:2}" ;;
255
- policy) policy ;;
256
- apply) apply "${@:2}" ;;
257
- delete-data) delete_data "${2:-}" ;;
258
- bench) bench "${@:2}" ;;
259
- relay-start) relay_start ;;
260
- relay-stop) relais_arreter llm ;;
261
- *) echo "devzone llm: status | bench [--apply] | delete-data [--yes]" >&2; exit 1 ;;
262
- esac
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env bash
2
- # opencode provider of the local model (#586), in a file apart managed by devzone:
3
- # opencode.sh set provider devzone-llm (model local) put in the config
4
- # opencode.sh unset provider removed (the rest of the file is kept)
5
- # opencode.sh url base URL of the model seen from here
6
- # File: ~/.config/opencode/config.json. opencode (1.19) reads it on its own, for
7
- # the interactive session and for `opencode run`, with no environment variable,
8
- # before opencode.json(c) (devzone enable ia) and OPENCODE_CONFIG_CONTENT (devzone
9
- # agent), which keep the priority; providers merge, nothing of ia is replaced.
10
- # URL: cluster DNS in the Kubernetes workspace pod, the relay of the container
11
- # (127.0.0.1:LLM_PORT) elsewhere. bash 3.2 (macOS).
12
- set -euo pipefail
13
-
14
- FILE="$HOME/.config/opencode/config.json"
15
-
16
- base_url() {
17
- if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
18
- echo "http://llm.devzone-llm.svc.cluster.local:8080/v1"
19
- else
20
- echo "http://127.0.0.1:${LLM_PORT:-8089}/v1"
21
- fi
22
- }
23
-
24
- # jq program $1 applied to the file (or {}), written back atomically
25
- rewrite() {
26
- local current="{}" out
27
- [ ! -f "$FILE" ] || current="$(cat "$FILE")"
28
- mkdir -p "$(dirname "$FILE")"
29
- out="$(printf '%s' "$current" | jq --arg url "$(base_url)" "$1")" || {
30
- echo "devzone: llm: $FILE is not valid JSON: provider not touched" >&2
31
- return 1
32
- }
33
- # Nothing left but the schema: the file was ours, it goes
34
- if [ "$(printf '%s' "$out" | jq -c 'del(."$schema") | length')" = 0 ] && [ "$1" != "$SET" ]; then
35
- rm -f "$FILE"
36
- else
37
- printf '%s\n' "$out" >"$FILE.tmp" && mv "$FILE.tmp" "$FILE"
38
- fi
39
- }
40
-
41
- # shellcheck disable=SC2016 # jq programs, $url is a jq variable
42
- SET='."$schema" = (."$schema" // "https://opencode.ai/config.json")
43
- | .provider["devzone-llm"] = {npm: "@ai-sdk/openai-compatible", name: "devzone local model",
44
- options: {baseURL: $url}, models: {local: {name: "Local code model"}}}'
45
- # shellcheck disable=SC2016
46
- UNSET='if .provider then del(.provider["devzone-llm"]) | (if .provider == {} then del(.provider) else . end) else . end'
47
-
48
- case "${1:-}" in
49
- set) rewrite "$SET" ;;
50
- unset) [ ! -f "$FILE" ] || rewrite "$UNSET" ;;
51
- url) base_url ;;
52
- *)
53
- echo "usage: opencode.sh set|unset|url" >&2
54
- exit 1
55
- ;;
56
- esac
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Presets of the local model (#586), sourced by llm.sh and argocd/services-hook.sh.
3
- # The values are the ones documented in charts/devzone-llm/values.yaml: the
4
- # Hugging Face URL is pinned to a commit (resolve/<commit>) and the sha256 is
5
- # the one of the file, checked by the init container of the chart.
6
- # llm_preset_name <name> canonical preset (default | light), 1 when unknown
7
- # llm_preset_sets <name> helm parameters key=value, space separated
8
- # llm_preset_file <name> file name of the model of the preset
9
- # bash 3.2 (macOS).
10
-
11
- LLM_HF_7B="https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct-GGUF/resolve/13fb94bfda8c8cf22497dc57b78f391a9acb426a"
12
- LLM_HF_3B="https://huggingface.co/Qwen/Qwen2.5-Coder-3B-Instruct-GGUF/resolve/f74adce6aa16316c625447af059dbebe4983757c"
13
-
14
- llm_preset_name() {
15
- case "${1:-}" in
16
- "" | default | qwen2.5-coder-7b-instruct-q4_k_m) echo default ;;
17
- light | qwen2.5-coder-3b-instruct-q4_k_m) echo light ;;
18
- *) return 1 ;;
19
- esac
20
- }
21
-
22
- llm_preset_file() {
23
- case "$(llm_preset_name "${1:-}")" in
24
- default) echo qwen2.5-coder-7b-instruct-q4_k_m.gguf ;;
25
- light) echo qwen2.5-coder-3b-instruct-q4_k_m.gguf ;;
26
- esac
27
- }
28
-
29
- llm_preset_sets() {
30
- local name file
31
- name="$(llm_preset_name "${1:-}")" || return 1
32
- file="$(llm_preset_file "$name")"
33
- case "$name" in
34
- default)
35
- printf 'model.url=%s/%s model.file=%s model.sha256=%s' "$LLM_HF_7B" "$file" "$file" \
36
- 509287f78cb4d4cf6b3843734733b914b2c158e43e22a7f4bf5e963800894d3c
37
- ;;
38
- light)
39
- printf 'model.url=%s/%s model.file=%s model.sha256=%s memory=3Gi resources.limits.memory=4Gi contextSize=16384' \
40
- "$LLM_HF_3B" "$file" "$file" 724fb256bec1ff062b2f65e4569e871ad2e95ab2a3989723d1769c54294730b7
41
- ;;
42
- esac
43
- }
@@ -1,6 +0,0 @@
1
- apiVersion: v2
2
- name: devzone-llm
3
- description: Local code model of devzone, llama.cpp llama-server on CPU with a GGUF model on a volume (#586)
4
- type: application
5
- version: 0.1.0
6
- appVersion: "b12407"
@@ -1,65 +0,0 @@
1
- {{- if .Values.bench.enabled }}
2
- # One-off llama-bench of the model (#593), never rendered by default. The
3
- # volume is ReadWriteOnce: the pod must land on the node of the server pod.
4
- apiVersion: batch/v1
5
- kind: Job
6
- metadata:
7
- name: llm-bench
8
- namespace: {{ .Release.Namespace }}
9
- labels:
10
- app: llm-bench
11
- app.kubernetes.io/name: llm-bench
12
- app.kubernetes.io/part-of: devzone
13
- app.kubernetes.io/managed-by: devzone
14
- spec:
15
- backoffLimit: 0
16
- activeDeadlineSeconds: {{ .Values.bench.deadline }}
17
- ttlSecondsAfterFinished: {{ .Values.bench.ttl }}
18
- template:
19
- metadata:
20
- labels:
21
- app: llm-bench
22
- app.kubernetes.io/managed-by: devzone
23
- spec:
24
- restartPolicy: Never
25
- affinity:
26
- podAffinity:
27
- requiredDuringSchedulingIgnoredDuringExecution:
28
- - topologyKey: kubernetes.io/hostname
29
- labelSelector:
30
- matchLabels:
31
- app: llm
32
- containers:
33
- - name: bench
34
- image: {{ .Values.image }}:full-{{ .Values.llamaBuild }}
35
- command:
36
- - /app/llama-bench
37
- args:
38
- - -m
39
- - /models/{{ .Values.model.file }}
40
- - -p
41
- - {{ .Values.bench.prompt | quote }}
42
- - -n
43
- - {{ .Values.bench.gen | quote }}
44
- - -r
45
- - {{ .Values.bench.repetitions | quote }}
46
- - -t
47
- - {{ .Values.bench.threads | quote }}
48
- - -o
49
- - json
50
- resources:
51
- requests:
52
- cpu: {{ .Values.resources.requests.cpu }}
53
- memory: {{ .Values.memory }}
54
- limits:
55
- memory: {{ .Values.resources.limits.memory }}
56
- volumeMounts:
57
- - name: models
58
- mountPath: /models
59
- readOnly: true
60
- volumes:
61
- - name: models
62
- persistentVolumeClaim:
63
- claimName: {{ .Values.claim }}
64
- readOnly: true
65
- {{- end }}