Malina commited on
Commit
bebc2cf
·
1 Parent(s): 3712e45

Etap 4: adaptacyjny przydzial budzetu syntezy na plik

Browse files

Sztywny limit 4000 znakow na plik przy budzecie 60 000 oznaczal, ze do syntezy
docieralo okolo czternastu plikow niezaleznie od tego, ile ich wgrano. Reszta
byla czytana, placono za nia wywolania MAP, i nie trafiala do Notatki.

Teraz budzet dzieli sie na liczbe plikow, z rezerwa na naglowek bloku i podloga
400 znakow. Zmierzone: przy 100 plikach po 4000 znakow do syntezy trafia 100
ze 100, wczesniej 14. Male zadania sa nietkniete, bo przydzial jest wtedy
znacznie wiekszy niz to, co MAP w ogole produkuje.

Files changed (1) hide show
  1. synthesis.py +15 -1
synthesis.py CHANGED
@@ -333,17 +333,31 @@ def _reduce_system(language: str) -> str:
333
  )
334
 
335
 
 
 
 
 
336
  def _reduce_user(prompt: str, kept: list[dict], skipped: list[dict], fmt: str = "") -> str:
337
  # Most-relevant first, so the budget fills with the files most likely to be used and
338
  # the grade is visible to REDUCE as it decides what to keep vs. set aside.
339
  ranked = sorted(kept, key=lambda k: RELEVANCE_ORDER.get(k.get("relevance", "medium"), 2),
340
  reverse=True)
 
 
 
 
 
 
 
 
 
341
  blocks, total, overflow = [], 0, []
342
  for item in ranked:
343
  topics = ", ".join(item.get("topics") or []) or "-"
344
  rel = item.get("relevance", "medium")
 
345
  block = (f"### File: {item['name']} (type: {item['category']}; relevance: {rel}; "
346
- f"topics: {topics})\n{item['notes']}\n")
347
  if total + len(block) > REDUCE_BUDGET:
348
  # This used to `break`, and the remaining files went nowhere: not into the
349
  # Note, not into Sources, not onto the "Not used" line. They simply vanished
 
333
  )
334
 
335
 
336
+ _MIN_SHARE = 400 # below this a file's notes carry nothing useful
337
+ _BLOCK_OVERHEAD = 140 # the '### File: ... (type; relevance; topics)' line
338
+
339
+
340
  def _reduce_user(prompt: str, kept: list[dict], skipped: list[dict], fmt: str = "") -> str:
341
  # Most-relevant first, so the budget fills with the files most likely to be used and
342
  # the grade is visible to REDUCE as it decides what to keep vs. set aside.
343
  ranked = sorted(kept, key=lambda k: RELEVANCE_ORDER.get(k.get("relevance", "medium"), 2),
344
  reverse=True)
345
+ # Every file gets a share of the budget rather than the first ones taking all of it.
346
+ # With a fixed 4000-char cap and a 60k budget only about fourteen files ever reached
347
+ # synthesis, however many were uploaded. Sharing it out means a 100-file task gives
348
+ # each file ~600 characters and all of them are seen. Small tasks are unaffected:
349
+ # the share is far above what MAP produces anyway. Below the floor the notes stop
350
+ # being worth sending, and the rest are carried to the set-aside list.
351
+ # Each block carries a header (name, type, grade, topics) on top of the notes,
352
+ # so reserve room for it or the last files are pushed out by the bookkeeping.
353
+ share = max(_MIN_SHARE, REDUCE_BUDGET // max(1, len(ranked)) - _BLOCK_OVERHEAD)
354
  blocks, total, overflow = [], 0, []
355
  for item in ranked:
356
  topics = ", ".join(item.get("topics") or []) or "-"
357
  rel = item.get("relevance", "medium")
358
+ notes = item["notes"][:share]
359
  block = (f"### File: {item['name']} (type: {item['category']}; relevance: {rel}; "
360
+ f"topics: {topics})\n{notes}\n")
361
  if total + len(block) > REDUCE_BUDGET:
362
  # This used to `break`, and the remaining files went nowhere: not into the
363
  # Note, not into Sources, not onto the "Not used" line. They simply vanished