@lzhzzzzwill/cofos 1.1.1 → 1.1.3

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.
package/bin/cofos.js CHANGED
@@ -186,7 +186,7 @@ function main() {
186
186
  proc.stdout.setEncoding("utf-8");
187
187
  proc.stderr.setEncoding("utf-8");
188
188
 
189
- let buf = "", ready = false, generating = false, closed = false;
189
+ let buf = "", ready = false, generating = false, responseOpen = false, closed = false;
190
190
  const inputQ = [];
191
191
  const rl = createInterface({ input: process.stdin, terminal: true });
192
192
  rl.on("line", (l) => { inputQ.push(l); });
@@ -210,27 +210,35 @@ function main() {
210
210
  // dropping it keeps it from being prepended to the next one.
211
211
  if (!generating) { buf = ""; return; }
212
212
 
213
+ if (!responseOpen) {
214
+ const ri = buf.indexOf(RESPONSE);
215
+ if (ri === -1) {
216
+ // Keep enough tail to catch a RESPONSE marker split across chunks.
217
+ const keep = RESPONSE.length - 1;
218
+ if (buf.length > keep) buf = buf.slice(-keep);
219
+ return;
220
+ }
221
+ buf = buf.slice(ri + RESPONSE.length);
222
+ if (buf[0] === "\n") buf = buf.slice(1);
223
+ responseOpen = true;
224
+ }
225
+
213
226
  // Scan for DONE marker — stream everything before it.
214
227
  const di = buf.indexOf(DONE);
215
228
  if (di !== -1) {
216
- // Flush any pre-DONE content (cleaned of RESPONSE marker).
217
- let pre = buf.slice(0, di);
218
- const ri = pre.indexOf(RESPONSE);
219
- if (ri !== -1) pre = pre.slice(ri + RESPONSE.length);
229
+ const pre = buf.slice(0, di);
220
230
  if (pre) process.stdout.write(pre);
221
231
  buf = buf.slice(di + DONE.length);
222
232
  if (buf[0] === "\n") buf = buf.slice(1);
223
233
  generating = false;
234
+ responseOpen = false;
224
235
  console.log("");
225
236
  drain();
226
237
  } else {
227
- // Stream buffered content, keeping only enough tail to catch a
228
- // partial DONE marker.
229
- const keep = DONE.length;
238
+ // Stream buffered content, keeping enough tail to catch a partial DONE marker.
239
+ const keep = DONE.length - 1;
230
240
  if (buf.length > keep) {
231
- let out = buf.slice(0, -keep);
232
- const ri = out.indexOf(RESPONSE);
233
- if (ri !== -1) out = out.slice(ri + RESPONSE.length);
241
+ const out = buf.slice(0, -keep);
234
242
  if (out) process.stdout.write(out);
235
243
  buf = buf.slice(-keep);
236
244
  }
@@ -299,6 +307,7 @@ function main() {
299
307
  }
300
308
  if (/^\/(clear)$/.test(input)) {
301
309
  mlBuf = [];
310
+ responseOpen = false;
302
311
  proc.stdin.write(input + "\n");
303
312
  generating = true;
304
313
  return;
@@ -315,6 +324,7 @@ function main() {
315
324
  }
316
325
 
317
326
  // Forward to backend.
327
+ responseOpen = false;
318
328
  generating = true;
319
329
  proc.stdin.write(input + "\n");
320
330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lzhzzzzwill/cofos",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "COFOS 9B + RAG chat CLI with optional local PDF ingestion.",
5
5
  "type": "module",
6
6
  "bin": {
package/scripts/chat.py CHANGED
@@ -486,7 +486,7 @@ def main() -> None:
486
486
  pdf_changed = parse_pdfs_if_needed(runtime_root, config, force=args.rebuild_pdf_index)
487
487
  build_augmented_bm25_if_needed(runtime_root, config, force=args.rebuild_pdf_index or pdf_changed)
488
488
 
489
- print("[chat] Loading model (this may take 1-2 min on first run) ...", file=sys.stderr, flush=True)
489
+ print("[chat] Loading model weights. First run may download 12GB+ and take tens of minutes; cached runs are much faster ...", file=sys.stderr, flush=True)
490
490
 
491
491
  runner = StudentAdapterInference(
492
492
  config=config,