From 0bb30696de8cb647a3dbfaf5bcf16f8523b384e4 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Mon, 2 Nov 2026 14:51:25 -0300 Subject: [PATCH] automatic-ai-posts: raise max_tokens for reasoning models (NVIDIA Build) Nemotron spends the token budget on reasoning_content before answering; a 2048 budget was exhausted by ~7761 reasoning chars, returning empty content with finish_reason=length. Topic selection and category choice go 2048 -> 8192, image plan 4000 -> 8192, article rewrite 8192 -> 16384. max_tokens is only a cap, so concise answers cost the same as before. --- .../src/Modules/Ai/AiService.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/wp-content/plugins/automatic-ai-posts/src/Modules/Ai/AiService.php b/wp-content/plugins/automatic-ai-posts/src/Modules/Ai/AiService.php index a69f3aa..0552d19 100644 --- a/wp-content/plugins/automatic-ai-posts/src/Modules/Ai/AiService.php +++ b/wp-content/plugins/automatic-ai-posts/src/Modules/Ai/AiService.php @@ -86,7 +86,7 @@ final class AiService { } $prompt = PromptLibrary::select_topics($articles, $min, $max, $recent_titles); - $raw = $this->ask($prompt, 'topic selection', 2048, 0.2); + $raw = $this->ask($prompt, 'topic selection', 8192, 0.2); if ($raw === null) { return []; @@ -117,7 +117,7 @@ final class AiService { */ public function rewrite(array $article, string $language): ?array { $prompt = PromptLibrary::rewrite($article, $language); - $raw = $this->ask($prompt, 'article rewrite', 8192, 0.8); + $raw = $this->ask($prompt, 'article rewrite', 16384, 0.8); if ($raw === null) { return null; @@ -148,7 +148,7 @@ final class AiService { } $prompt = PromptLibrary::choose_category($title, $content, $categories, $language); - $raw = $this->ask($prompt, 'category choice', 2048, 0.2); + $raw = $this->ask($prompt, 'category choice', 8192, 0.2); if ($raw === null) { return 0; @@ -182,7 +182,7 @@ final class AiService { */ public function image_plan(string $title, string $content, string $language): ?array { $prompt = PromptLibrary::image_plan($title, $content, $language); - $raw = $this->ask($prompt, 'image plan', 4000, 0.7); + $raw = $this->ask($prompt, 'image plan', 8192, 0.7); if ($raw === null) { return null; @@ -205,7 +205,14 @@ final class AiService { ]; } - /** Calls the provider with retries. Returns null when every attempt failed. */ + /** + * Calls the provider with retries. Returns null when every attempt failed. + * + * Budgets are generous on purpose: reasoning models (e.g. Nemotron on + * NVIDIA Build) spend tokens on reasoning_content before answering, and an + * exhausted budget returns empty content with finish_reason "length". + * max_tokens is only a cap — the cost is per generated token. + */ private function ask(string $prompt, string $label, int $max_tokens, float $temperature): ?string { if (!$this->provider) { Logger::error('No AI provider configured.', 'ai');