Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Log resolved max_tokens per LLM call and promote title/event budgets to TITLE_MAX_TOKENS / EVENT_MAX_TOKENS
Murtaza Nasir5f3987bab219
diff --git a/src/services/llm.py b/src/services/llm.pyindex 2ee27cb3..581e2fcd 100644--- a/src/services/llm.py+++ b/src/services/llm.py@@ -244,6 +244,16 @@ def call_llm_completion(messages, temperature=0.7, response_format=None, stream=if response_format:completion_args["response_format"] = response_format+ # Make the resolved max_tokens visible in logs so users can confirm+ # their SUMMARY_MAX_TOKENS / CHAT_MAX_TOKENS / etc. settings actually+ # took effect for a given operation. The "key" used here is+ # max_completion_tokens for GPT-5 and max_tokens otherwise.+ budget_key = 'max_completion_tokens' if using_gpt5 else 'max_tokens'+ logger.info(+ f"LLM call: operation={operation_type or 'unspecified'}, model={TEXT_MODEL_NAME}, "+ f"{budget_key}={completion_args.get(budget_key, 'provider default')}"+ )+request_started_at = time.monotonic()response = client.chat.completions.create(**completion_args)@@ -370,6 +380,14 @@ def call_chat_completion(messages, temperature=0.7, response_format=None, streamif response_format:completion_args["response_format"] = response_format+ # Visibility: surface the resolved budget per call so admins can+ # confirm CHAT_MAX_TOKENS or per-call overrides took effect.+ budget_key = 'max_completion_tokens' if using_gpt5 else 'max_tokens'+ logger.info(+ f"Chat LLM call: operation={operation_type or 'unspecified'}, model={model_name}, "+ f"{budget_key}={completion_args.get(budget_key, 'provider default')}"+ )+request_started_at = time.monotonic()response = effective_client.chat.completions.create(**completion_args)diff --git a/src/tasks/processing.py b/src/tasks/processing.pyindex a385f378..21e107db 100644--- a/src/tasks/processing.py+++ b/src/tasks/processing.py@@ -357,7 +357,10 @@ Title:"""{"role": "user", "content": prompt_text}],temperature=0.7,- max_tokens=5000,+ # TITLE_MAX_TOKENS lets reasoning-model users (e.g. Kimi K2) raise+ # the budget so the model has room for hidden thinking tokens+ # before producing the title itself.+ max_tokens=int(os.environ.get("TITLE_MAX_TOKENS", "5000")),user_id=recording.user_id,operation_type='title_generation')@@ -853,7 +856,9 @@ You must respond with valid JSON format only."""],temperature=0.2,response_format={"type": "json_object"},- max_tokens=3000,+ # EVENT_MAX_TOKENS gives reasoning-model users a knob to raise+ # the budget when hidden thinking tokens crowd out the JSON output.+ max_tokens=int(os.environ.get("EVENT_MAX_TOKENS", "3000")),user_id=recording.user_id,operation_type='event_extraction')@@ -2189,7 +2194,9 @@ Title:"""{"role": "user", "content": prompt_text}],temperature=0.7,- max_tokens=100+ # Match the main title-generation path so reasoning-model users+ # have a single knob (TITLE_MAX_TOKENS) that covers both flows.+ max_tokens=int(os.environ.get("TITLE_MAX_TOKENS", "5000")))raw_response = completion.choices[0].message.content