Spaces:
Sleeping
Sleeping
Deploy Agenda Parser
Browse files- chroma/answer.py +7 -2
- chroma/report.py +9 -2
- chroma/summarize.py +5 -1
chroma/answer.py
CHANGED
|
@@ -31,6 +31,10 @@ Completer = Callable[..., str]
|
|
| 31 |
DEFAULT_CHAR_BUDGET = int(os.getenv("ANSWER_CHAR_BUDGET", "16000"))
|
| 32 |
# How many chunks to pull from the relevance query before packing to the budget.
|
| 33 |
DEFAULT_N_RESULTS = int(os.getenv("ANSWER_N_RESULTS", "16"))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
ANSWER_SYSTEM = (
|
| 36 |
"You are a civic-records analyst answering a resident's question about ONE item on "
|
|
@@ -78,8 +82,9 @@ def budget_for(max_sections: int) -> tuple[int, int]:
|
|
| 78 |
char budget is capped so the prompt still fits the local model's context window.
|
| 79 |
"""
|
| 80 |
n = int(max_sections or 0)
|
| 81 |
-
char_budget = min(DEFAULT_CHAR_BUDGET, max(6000, n *
|
| 82 |
-
|
|
|
|
| 83 |
return char_budget, max_tokens
|
| 84 |
|
| 85 |
|
|
|
|
| 31 |
DEFAULT_CHAR_BUDGET = int(os.getenv("ANSWER_CHAR_BUDGET", "16000"))
|
| 32 |
# How many chunks to pull from the relevance query before packing to the budget.
|
| 33 |
DEFAULT_N_RESULTS = int(os.getenv("ANSWER_N_RESULTS", "16"))
|
| 34 |
+
# Ceiling on a single-pass item answer's length (the thoroughness slider scales up to
|
| 35 |
+
# this). Raise ANSWER_MAX_TOKENS for longer answers — pair it with a bigger LLAMA_N_CTX
|
| 36 |
+
# and GPU_DURATION_ANSWER so the generation fits the context + ZeroGPU window.
|
| 37 |
+
ANSWER_MAX_TOKENS = int(os.getenv("ANSWER_MAX_TOKENS", "1536"))
|
| 38 |
|
| 39 |
ANSWER_SYSTEM = (
|
| 40 |
"You are a civic-records analyst answering a resident's question about ONE item on "
|
|
|
|
| 82 |
char budget is capped so the prompt still fits the local model's context window.
|
| 83 |
"""
|
| 84 |
n = int(max_sections or 0)
|
| 85 |
+
char_budget = min(DEFAULT_CHAR_BUDGET, max(6000, n * 320))
|
| 86 |
+
# Scale so the UI's max thoroughness (~120) reaches ANSWER_MAX_TOKENS.
|
| 87 |
+
max_tokens = min(ANSWER_MAX_TOKENS, max(640, round(n * ANSWER_MAX_TOKENS / 120)))
|
| 88 |
return char_budget, max_tokens
|
| 89 |
|
| 90 |
|
chroma/report.py
CHANGED
|
@@ -12,11 +12,18 @@ The LLM call is injectable via ``complete`` (defaults to
|
|
| 12 |
|
| 13 |
from __future__ import annotations
|
| 14 |
|
|
|
|
| 15 |
from typing import Callable
|
| 16 |
|
| 17 |
from .chunking import chunk_text
|
| 18 |
from .store import AgendaStore
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
Completer = Callable[..., str]
|
| 21 |
|
| 22 |
# Above this many characters of joined notes, do an extra hierarchical reduce pass
|
|
@@ -121,8 +128,8 @@ def generate_report(
|
|
| 121 |
store: AgendaStore | None = None,
|
| 122 |
complete: Completer | None = None,
|
| 123 |
max_chunks: int | None = None,
|
| 124 |
-
map_max_tokens: int =
|
| 125 |
-
reduce_max_tokens: int =
|
| 126 |
progress: Callable[[float, str], None] | None = None,
|
| 127 |
) -> str:
|
| 128 |
"""Build a query-framed markdown report from loader ``documents``.
|
|
|
|
| 12 |
|
| 13 |
from __future__ import annotations
|
| 14 |
|
| 15 |
+
import os
|
| 16 |
from typing import Callable
|
| 17 |
|
| 18 |
from .chunking import chunk_text
|
| 19 |
from .store import AgendaStore
|
| 20 |
|
| 21 |
+
# Per-step output caps (env-tunable). The reduce step writes the final report, so it
|
| 22 |
+
# gets the larger budget; raise REPORT_REDUCE_TOKENS for longer reports (pair with a
|
| 23 |
+
# bigger LLAMA_N_CTX + GPU_DURATION_REPORT).
|
| 24 |
+
_MAP_MAX_TOKENS = int(os.getenv("REPORT_MAP_TOKENS", "512"))
|
| 25 |
+
_REDUCE_MAX_TOKENS = int(os.getenv("REPORT_REDUCE_TOKENS", "2048"))
|
| 26 |
+
|
| 27 |
Completer = Callable[..., str]
|
| 28 |
|
| 29 |
# Above this many characters of joined notes, do an extra hierarchical reduce pass
|
|
|
|
| 128 |
store: AgendaStore | None = None,
|
| 129 |
complete: Completer | None = None,
|
| 130 |
max_chunks: int | None = None,
|
| 131 |
+
map_max_tokens: int = _MAP_MAX_TOKENS,
|
| 132 |
+
reduce_max_tokens: int = _REDUCE_MAX_TOKENS,
|
| 133 |
progress: Callable[[float, str], None] | None = None,
|
| 134 |
) -> str:
|
| 135 |
"""Build a query-framed markdown report from loader ``documents``.
|
chroma/summarize.py
CHANGED
|
@@ -12,12 +12,16 @@ can swap in a fake for testing or a different backend. It defaults to
|
|
| 12 |
|
| 13 |
from __future__ import annotations
|
| 14 |
|
|
|
|
| 15 |
from typing import Callable
|
| 16 |
|
| 17 |
from .chunking import chunk_text
|
| 18 |
|
| 19 |
Completer = Callable[..., str]
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
_MAP_SYSTEM = (
|
| 22 |
"You summarize sections of public-meeting agendas. Be factual and concise; "
|
| 23 |
"preserve agenda item numbers, topics, motions, names, dollar amounts, and dates."
|
|
@@ -59,7 +63,7 @@ def summarize_text(
|
|
| 59 |
overlap: int = 300,
|
| 60 |
style: str = "of about 5-10 bullet points",
|
| 61 |
map_max_tokens: int = 512,
|
| 62 |
-
reduce_max_tokens: int =
|
| 63 |
) -> str:
|
| 64 |
"""Summarize arbitrary text via single-pass or map-reduce over chunks.
|
| 65 |
|
|
|
|
| 12 |
|
| 13 |
from __future__ import annotations
|
| 14 |
|
| 15 |
+
import os
|
| 16 |
from typing import Callable
|
| 17 |
|
| 18 |
from .chunking import chunk_text
|
| 19 |
|
| 20 |
Completer = Callable[..., str]
|
| 21 |
|
| 22 |
+
# Final summary length cap (env-tunable); raise SUMMARY_REDUCE_TOKENS for longer summaries.
|
| 23 |
+
_SUMMARY_REDUCE_TOKENS = int(os.getenv("SUMMARY_REDUCE_TOKENS", "1024"))
|
| 24 |
+
|
| 25 |
_MAP_SYSTEM = (
|
| 26 |
"You summarize sections of public-meeting agendas. Be factual and concise; "
|
| 27 |
"preserve agenda item numbers, topics, motions, names, dollar amounts, and dates."
|
|
|
|
| 63 |
overlap: int = 300,
|
| 64 |
style: str = "of about 5-10 bullet points",
|
| 65 |
map_max_tokens: int = 512,
|
| 66 |
+
reduce_max_tokens: int = _SUMMARY_REDUCE_TOKENS,
|
| 67 |
) -> str:
|
| 68 |
"""Summarize arbitrary text via single-pass or map-reduce over chunks.
|
| 69 |
|