* Ein Modell wirklich laden und auf `{"status":"ok"}` warten. * * Waehrend des Ladens antwortet llama-server mit 503 und `Loading model`; das * ist der erwartete Zwischenstand und kein Fehler. Erst 200 mit `status: ok` * heisst geladen.
(model, port)
| 112 | * heisst geladen. |
| 113 | */ |
| 114 | async function loadSmoke(model, port) { |
| 115 | const started = Date.now(); |
| 116 | const child = spawn( |
| 117 | SERVER, |
| 118 | ['--host', '127.0.0.1', '--port', String(port), '-m', join('models', model), '-c', '512'], |
| 119 | { cwd: ROOT, stdio: ['ignore', 'pipe', 'pipe'] }, |
| 120 | ); |
| 121 | const output = []; |
| 122 | child.stdout.on('data', (d) => output.push(d.toString())); |
| 123 | child.stderr.on('data', (d) => output.push(d.toString())); |
| 124 | |
| 125 | let exited = null; |
| 126 | child.on('exit', (code, signal) => { exited = { code, signal }; }); |
| 127 | |
| 128 | const result = { ready: false, durationMs: 0, statuses: [], props: null, error: '' }; |
| 129 | const deadline = Date.now() + READY_TIMEOUT_MS; |
| 130 | while (Date.now() < deadline) { |
| 131 | if (exited !== null) { |
| 132 | result.error = `llama-server endete vorzeitig (code=${exited.code}, signal=${exited.signal})`; |
| 133 | break; |
| 134 | } |
| 135 | try { |
| 136 | const response = await fetch(`http://127.0.0.1:${port}/health`); |
| 137 | const body = await response.text(); |
| 138 | const seen = `${response.status} ${body.slice(0, 60)}`; |
| 139 | if (result.statuses[result.statuses.length - 1] !== seen) { |
| 140 | result.statuses.push(seen); |
| 141 | } |
| 142 | if (response.status === 200 && body.includes('"ok"')) { |
| 143 | result.ready = true; |
| 144 | break; |
| 145 | } |
| 146 | } catch { |
| 147 | // Der Port ist noch nicht offen. Erwartet in der ersten Sekunde. |
| 148 | } |
| 149 | await sleep(500); |
| 150 | } |
| 151 | result.durationMs = Date.now() - started; |
| 152 | |
| 153 | if (result.ready) { |
| 154 | try { |
| 155 | const props = await (await fetch(`http://127.0.0.1:${port}/props`)).json(); |
| 156 | result.props = { |
| 157 | model_path: props.model_path ?? '', |
| 158 | model_ftype: props.model_ftype ?? '', |
| 159 | n_ctx: props.default_generation_settings?.n_ctx ?? null, |
| 160 | total_slots: props.total_slots ?? null, |
| 161 | }; |
| 162 | } catch (error) { |
| 163 | result.error = `/props war nicht lesbar: ${error.message}`; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | if (exited === null) { |
| 168 | child.kill('SIGTERM'); |
| 169 | for (let i = 0; i < 50 && exited === null; i += 1) { |
| 170 | await sleep(100); |
| 171 | } |