From c72d366935f9d7a4b49b51e0640ceb19005ab79e Mon Sep 17 00:00:00 2001 From: Mathias Date: Thu, 1 Oct 2026 16:57:01 +0200 Subject: [PATCH] feat(chat): per-request transcript budget so a long recording is not cut to its head (ADR-033) chat.Request.MaxChars overrides the Service cap when positive. The 18,000-char default (~22 min of speech) suits captions; an uploaded hour is ~50,000 chars and truncation keeps only the head. This is reuse of the existing chat path, not a fork. Co-Authored-By: Claude Sonnet 5.5 --- internal/adapters/chat/chat.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/adapters/chat/chat.go b/internal/adapters/chat/chat.go index 8cd0610..a774260 100644 --- a/internal/adapters/chat/chat.go +++ b/internal/adapters/chat/chat.go @@ -41,6 +41,11 @@ type Request struct { Transcript string History []Turn Question string + // MaxChars, when positive, overrides the Service's transcript budget for this + // request. The Service default is sized for YouTube captions (~22 minutes of + // speech); an uploaded recording is much longer, and truncation keeps only the + // head (ADR-033). Zero or negative means "use the Service default". + MaxChars int } // Reply is the model's answer plus whether the transcript was bounded to fit the @@ -113,7 +118,11 @@ func (s *Service) Answer(ctx context.Context, req Request) (Reply, error) { model = s.DefaultModel("") } - transcript, truncated := truncate(req.Transcript, s.maxChars) + budget := s.maxChars + if req.MaxChars > 0 { + budget = req.MaxChars + } + transcript, truncated := truncate(req.Transcript, budget) system := buildSystem(transcript, truncated) user := buildUser(req.History, req.Question)