From 521e0469d52b255010cc37a473d35d415ca4d0ea Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 10:06:51 -0600 Subject: [PATCH 01/15] fix: update gemini model --- .github/actions/auto-pr-description/generate_pr_description.js | 2 +- .../actions/auto-release-description/generate_pr_description.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 9ca4472..472191e 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -107,7 +107,7 @@ ${diffContent}`; * Call Gemini API with the given prompt */ async function callGeminiAPI(prompt, apiKey) { - const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${apiKey}`, { + const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ diff --git a/.github/actions/auto-release-description/generate_pr_description.js b/.github/actions/auto-release-description/generate_pr_description.js index 60c3753..1f03180 100644 --- a/.github/actions/auto-release-description/generate_pr_description.js +++ b/.github/actions/auto-release-description/generate_pr_description.js @@ -43,7 +43,7 @@ Keep it concise and focused on the most important changes.`; const combinedPrompt = `${promptTemplate}\n\nHere is the git diff:\n\n${diffContent}`; try { - const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${apiKey}`, { + const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ From a1ad3efeee289ecc67dda9fa549289666913b1c4 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 10:28:46 -0600 Subject: [PATCH 02/15] fix: rate limit requests to gemini --- .../auto-pr-description/generate_pr_description.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 472191e..33d6215 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -16,6 +16,11 @@ function estimateTokens(text) { return Math.ceil(text.length / CHARS_PER_TOKEN); } + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + /** * Split diff into chunks by file boundaries */ @@ -157,6 +162,10 @@ async function processChunks(chunks, apiKey) { for (let i = 0; i < Math.min(chunks.length, MAX_CHUNKS); i++) { const chunk = chunks[i]; + if (i > 0) { + // sleep for 3 seconds + sleep(3 * 1000); + } console.error(`Processing chunk ${i + 1}/${Math.min(chunks.length, MAX_CHUNKS)} (${chunk.file || 'unknown file'})`); try { From f5be5729d3f1c00fa879767366d5f162f0bce501 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 10:31:17 -0600 Subject: [PATCH 03/15] fix: limit tokens to 100,000 --- .github/actions/auto-pr-description/generate_pr_description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 33d6215..41425c3 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -7,7 +7,7 @@ const path = require('path'); const MAX_TOKENS_PER_REQUEST = 100000; // Conservative limit for Gemini 2.5 Flash const CHARS_PER_TOKEN = 4; // Rough estimation const MAX_CHARS_PER_CHUNK = MAX_TOKENS_PER_REQUEST * CHARS_PER_TOKEN; -const MAX_CHUNKS = 10; // Limit to prevent excessive API calls +const MAX_CHUNKS = 1; // Limit to prevent excessive API calls /** * Estimate token count for text (rough approximation) From 4f9f2890289852b289f55e3aa38615d2d807098f Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 10:37:59 -0600 Subject: [PATCH 04/15] fix: change calculation for chunking --- .github/actions/auto-pr-description/generate_pr_description.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 41425c3..3311a2f 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -34,7 +34,7 @@ function chunkDiffByFiles(diffContent) { // Check if this is a new file header if (line.startsWith('diff --git') || line.startsWith('+++') || line.startsWith('---')) { // If we have content and it's getting large, save current chunk - if (currentChunk && estimateTokens(currentChunk) > MAX_CHARS_PER_CHUNK / 2) { + if (currentChunk && estimateTokens(currentChunk + '\n' + line) > MAX_TOKENS_PER_REQUEST) { fileChunks.push({ content: currentChunk.trim(), file: currentFile, From 2e4a1fd71969cb7997ec313bb1e903c8d7ba46f7 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 10:48:13 -0600 Subject: [PATCH 05/15] fix: simplify large diff pr creation --- .../generate_pr_description.js | 46 ++++--------------- 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 3311a2f..f8604d9 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -6,8 +6,8 @@ const path = require('path'); // Configuration constants const MAX_TOKENS_PER_REQUEST = 100000; // Conservative limit for Gemini 2.5 Flash const CHARS_PER_TOKEN = 4; // Rough estimation -const MAX_CHARS_PER_CHUNK = MAX_TOKENS_PER_REQUEST * CHARS_PER_TOKEN; -const MAX_CHUNKS = 1; // Limit to prevent excessive API calls +//const MAX_CHARS_PER_CHUNK = MAX_TOKENS_PER_REQUEST * CHARS_PER_TOKEN; +const MAX_CHUNKS = 3; // Limit to prevent excessive API calls /** * Estimate token count for text (rough approximation) @@ -183,7 +183,7 @@ async function processChunks(chunks, apiKey) { if (chunkResults.length === 0) { throw new Error('Failed to process any chunks'); } - + sleep(3*1000); // Combine results from multiple chunks const combinedPrompt = `Combine these pull request descriptions into a single, coherent PR description. Use the same format: @@ -225,41 +225,13 @@ Create a unified description that captures the overall changes across all files. console.error('Large diff detected, using chunking strategy...'); // For extremely large diffs, first try to summarize - if (estimatedTokens > MAX_TOKENS_PER_REQUEST * 5) { - console.error('Extremely large diff detected, using summary approach...'); - const summaryPrompt = createSummaryPrompt(diffContent); - result = await callGeminiAPI(summaryPrompt, apiKey); - - // Create a simplified PR description based on the summary - const prPrompt = `Based on this summary of changes, create a pull request description using this format: - -## Description -Brief summary of changes (1-2 sentences max). - -## Changes -- [ ] Key change 1 -- [ ] Key change 2 -- [ ] Key change 3 (max 5 items) - -## Verification -- [ ] Test step 1 -- [ ] Test step 2 -- [ ] Test step 3 (max 3 items) - -Summary: ${result}`; - - result = await callGeminiAPI(prPrompt, apiKey); - } else { - // Chunk the diff and process - const chunks = chunkDiffByFiles(diffContent); - console.error(`Split diff into ${chunks.length} chunks`); - - if (chunks.length > MAX_CHUNKS) { - console.error(`Warning: Too many chunks (${chunks.length}), processing first ${MAX_CHUNKS} chunks only`); - } - - result = await processChunks(chunks, apiKey); + console.error('Extremely large diff detected, using summary approach...'); + const chunks = chunkDiffByFiles(diffContent); + console.error(`Split diff into ${chunks.length} chunks`); + if (chunks.length > MAX_CHUNKS) { + console.error(`Warning: Too many chunks (${chunks.length}), processing first ${MAX_CHUNKS} chunks only`); } + result = await processChunks(chunks, apiKey); } else { // Small diff, process normally result = await callGeminiAPI(createPRPrompt(diffContent), apiKey); From 1297ab4593c951a44f643b9acc7f3bbaf1c9a87a Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 10:57:12 -0600 Subject: [PATCH 06/15] fix: enhance split functionality. --- .../generate_pr_description.js | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index f8604d9..11861c9 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -21,6 +21,27 @@ function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } + +function splitStringByTokens(str, maxTokens) { + const words = str.split(' '); + const result = []; + let currentLine = ''; + + for (const word of words) { + if (estimateTokens(currentLine + word) <= maxTokens) { + currentLine += (currentLine ? ' ' : '') + word; + } else { + if (currentLine) result.push(currentLine); + currentLine = word; + } + } + + if (currentLine) result.push(currentLine); + + return result; +} + + /** * Split diff into chunks by file boundaries */ @@ -35,11 +56,22 @@ function chunkDiffByFiles(diffContent) { if (line.startsWith('diff --git') || line.startsWith('+++') || line.startsWith('---')) { // If we have content and it's getting large, save current chunk if (currentChunk && estimateTokens(currentChunk + '\n' + line) > MAX_TOKENS_PER_REQUEST) { - fileChunks.push({ - content: currentChunk.trim(), - file: currentFile, - type: 'file-chunk' - }); + if(estimateTokens(currentChunk) > MAX_TOKENS_PER_REQUEST) { + const split_chunk = splitStringByTokens(currentChunk, MAX_TOKENS_PER_REQUEST); + split_chunk.forEach((chunk) => { + fileChunks.push({ + content: chunk.trim(), + file: currentFile, + type: 'file-chunk' + }); + }) + }else { + fileChunks.push({ + content: currentChunk.trim(), + file: currentFile, + type: 'file-chunk' + }); + } currentChunk = ''; } @@ -224,8 +256,6 @@ Create a unified description that captures the overall changes across all files. if (estimatedTokens > MAX_TOKENS_PER_REQUEST) { console.error('Large diff detected, using chunking strategy...'); - // For extremely large diffs, first try to summarize - console.error('Extremely large diff detected, using summary approach...'); const chunks = chunkDiffByFiles(diffContent); console.error(`Split diff into ${chunks.length} chunks`); if (chunks.length > MAX_CHUNKS) { From 4f63a681d38bc32938ba473e82eeb354d8ec9660 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 10:58:10 -0600 Subject: [PATCH 07/15] chore: add debugging by printing the number of estimated tokens being sent. --- .github/actions/auto-pr-description/generate_pr_description.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 11861c9..4ebce35 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -144,6 +144,7 @@ ${diffContent}`; * Call Gemini API with the given prompt */ async function callGeminiAPI(prompt, apiKey) { + console.log(`Sending prompt with an estimated ${estimateTokens(prompt)} tokens`); const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, From 6987d475001ffb02e2bbd56aaa2c92e72638daa3 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 11:24:15 -0600 Subject: [PATCH 08/15] fix: split even the first line --- .../auto-pr-description/generate_pr_description.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 4ebce35..3ca8681 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -53,6 +53,7 @@ function chunkDiffByFiles(diffContent) { for (const line of lines) { // Check if this is a new file header + console.log(`Line is estimated at ${estimateTokens(line)} tokens`); if (line.startsWith('diff --git') || line.startsWith('+++') || line.startsWith('---')) { // If we have content and it's getting large, save current chunk if (currentChunk && estimateTokens(currentChunk + '\n' + line) > MAX_TOKENS_PER_REQUEST) { @@ -78,10 +79,22 @@ function chunkDiffByFiles(diffContent) { // Start new chunk currentChunk = line + '\n'; + // Extract filename for reference if (line.startsWith('+++')) { currentFile = line.replace('+++ b/', '').replace('+++ a/', ''); } + if(estimateTokens(currentChunk) > MAX_TOKENS_PER_REQUEST){ + const split_chunk = splitStringByTokens(currentChunk, MAX_TOKENS_PER_REQUEST); + currentChunk = split_chunk[split_chunk.length-1]; + for(let i = 0; i < split_chunk.length -1;i++){ + fileChunks.push({ + content: split_chunk[i].trim(), + file: currentFile, + type: 'file-chunk' + }); + } + } } else { currentChunk += line + '\n'; } From 7e5442cc34c50a0b11a82d485e01aba10f7fadf7 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 11:27:39 -0600 Subject: [PATCH 09/15] chore: add debug logging --- .github/actions/auto-pr-description/generate_pr_description.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 3ca8681..9a05266 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -46,6 +46,7 @@ function splitStringByTokens(str, maxTokens) { * Split diff into chunks by file boundaries */ function chunkDiffByFiles(diffContent) { + console.log('chunkDiffByFiles'); const fileChunks = []; const lines = diffContent.split('\n'); let currentChunk = ''; @@ -198,6 +199,7 @@ async function callGeminiAPI(prompt, apiKey) { * Process diff chunks and combine results */ async function processChunks(chunks, apiKey) { + console.log('processchunks'); if (chunks.length === 1) { // Single chunk, process normally return await callGeminiAPI(createPRPrompt(chunks[0].content), apiKey); From 22dd81c0e82af562dc6d8a6f682520af56ab8800 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 11:38:27 -0600 Subject: [PATCH 10/15] bypass gemini call for debugging purposes --- .github/actions/auto-pr-description/generate_pr_description.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 9a05266..5c99146 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -159,6 +159,7 @@ ${diffContent}`; */ async function callGeminiAPI(prompt, apiKey) { console.log(`Sending prompt with an estimated ${estimateTokens(prompt)} tokens`); + return 'gemini'; /* const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -193,6 +194,7 @@ async function callGeminiAPI(prompt, apiKey) { } return json.candidates[0].content.parts[0].text; + */ } /** From 40ab5cd4e15a2ea44cc6d69588db21de86636e73 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 11:41:46 -0600 Subject: [PATCH 11/15] log the pr body --- .github/actions/auto-pr-description/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/auto-pr-description/action.yml b/.github/actions/auto-pr-description/action.yml index cd0c490..365d981 100644 --- a/.github/actions/auto-pr-description/action.yml +++ b/.github/actions/auto-pr-description/action.yml @@ -80,6 +80,8 @@ runs: printf '%s\n' "$DESCRIPTION" > pr_body.md fi + cat pr_body.md + # Add JIRA ticket link if found PR_TITLE=$(gh pr view ${{ inputs.pr-number }} --json title --jq '.title') TICKET_ID=$(echo "$PR_TITLE" | grep -oE '[A-Z]+-[0-9]+' || true) From 3c96fded14c56174120e5f41a7d481272fe2195b Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 11:44:10 -0600 Subject: [PATCH 12/15] chore: send debug logs to console.error --- .../auto-pr-description/generate_pr_description.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 5c99146..8929ec8 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -46,7 +46,7 @@ function splitStringByTokens(str, maxTokens) { * Split diff into chunks by file boundaries */ function chunkDiffByFiles(diffContent) { - console.log('chunkDiffByFiles'); + console.error('chunkDiffByFiles'); const fileChunks = []; const lines = diffContent.split('\n'); let currentChunk = ''; @@ -54,7 +54,7 @@ function chunkDiffByFiles(diffContent) { for (const line of lines) { // Check if this is a new file header - console.log(`Line is estimated at ${estimateTokens(line)} tokens`); + console.error(`Line is estimated at ${estimateTokens(line)} tokens`); if (line.startsWith('diff --git') || line.startsWith('+++') || line.startsWith('---')) { // If we have content and it's getting large, save current chunk if (currentChunk && estimateTokens(currentChunk + '\n' + line) > MAX_TOKENS_PER_REQUEST) { @@ -158,7 +158,7 @@ ${diffContent}`; * Call Gemini API with the given prompt */ async function callGeminiAPI(prompt, apiKey) { - console.log(`Sending prompt with an estimated ${estimateTokens(prompt)} tokens`); + console.error(`Sending prompt with an estimated ${estimateTokens(prompt)} tokens`); return 'gemini'; /* const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`, { method: 'POST', @@ -201,7 +201,7 @@ async function callGeminiAPI(prompt, apiKey) { * Process diff chunks and combine results */ async function processChunks(chunks, apiKey) { - console.log('processchunks'); + console.error('processchunks'); if (chunks.length === 1) { // Single chunk, process normally return await callGeminiAPI(createPRPrompt(chunks[0].content), apiKey); From fc7d41052570a5f322eee5f0f64c5685b50d448c Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 11:59:19 -0600 Subject: [PATCH 13/15] chore: add more debugging --- .../generate_pr_description.js | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 8929ec8..4af885c 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -23,6 +23,7 @@ function sleep(ms) { function splitStringByTokens(str, maxTokens) { + console.error('splitStringByTokens'); const words = str.split(' '); const result = []; let currentLine = ''; @@ -51,30 +52,23 @@ function chunkDiffByFiles(diffContent) { const lines = diffContent.split('\n'); let currentChunk = ''; let currentFile = ''; + let tokenCount = 0; for (const line of lines) { // Check if this is a new file header console.error(`Line is estimated at ${estimateTokens(line)} tokens`); + tokenCount += estimateTokens(line); + console.error(`Total tokens for this chunk is ${tokenCount}`); if (line.startsWith('diff --git') || line.startsWith('+++') || line.startsWith('---')) { // If we have content and it's getting large, save current chunk - if (currentChunk && estimateTokens(currentChunk + '\n' + line) > MAX_TOKENS_PER_REQUEST) { - if(estimateTokens(currentChunk) > MAX_TOKENS_PER_REQUEST) { - const split_chunk = splitStringByTokens(currentChunk, MAX_TOKENS_PER_REQUEST); - split_chunk.forEach((chunk) => { - fileChunks.push({ - content: chunk.trim(), - file: currentFile, - type: 'file-chunk' - }); - }) - }else { - fileChunks.push({ - content: currentChunk.trim(), - file: currentFile, - type: 'file-chunk' - }); - } + if (currentChunk && tokenCount > MAX_TOKENS_PER_REQUEST) { + fileChunks.push({ + content: currentChunk.trim(), + file: currentFile, + type: 'file-chunk' + }); currentChunk = ''; + tokenCount = 0; } // Start new chunk @@ -85,7 +79,7 @@ function chunkDiffByFiles(diffContent) { if (line.startsWith('+++')) { currentFile = line.replace('+++ b/', '').replace('+++ a/', ''); } - if(estimateTokens(currentChunk) > MAX_TOKENS_PER_REQUEST){ + if(tokenCount > MAX_TOKENS_PER_REQUEST){ const split_chunk = splitStringByTokens(currentChunk, MAX_TOKENS_PER_REQUEST); currentChunk = split_chunk[split_chunk.length-1]; for(let i = 0; i < split_chunk.length -1;i++){ From 96a94cba619120f78639abf291538292f7e64db2 Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 12:03:31 -0600 Subject: [PATCH 14/15] chore: remove debug logging --- .../actions/auto-pr-description/generate_pr_description.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index 4af885c..ef0007a 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -4,7 +4,7 @@ const fs = require('fs'); const path = require('path'); // Configuration constants -const MAX_TOKENS_PER_REQUEST = 100000; // Conservative limit for Gemini 2.5 Flash +const MAX_TOKENS_PER_REQUEST = 80000; // Conservative limit for Gemini 2.5 Flash const CHARS_PER_TOKEN = 4; // Rough estimation //const MAX_CHARS_PER_CHUNK = MAX_TOKENS_PER_REQUEST * CHARS_PER_TOKEN; const MAX_CHUNKS = 3; // Limit to prevent excessive API calls @@ -56,9 +56,9 @@ function chunkDiffByFiles(diffContent) { for (const line of lines) { // Check if this is a new file header - console.error(`Line is estimated at ${estimateTokens(line)} tokens`); + //console.error(`Line is estimated at ${estimateTokens(line)} tokens`); tokenCount += estimateTokens(line); - console.error(`Total tokens for this chunk is ${tokenCount}`); + //console.error(`Total tokens for this chunk is ${tokenCount}`); if (line.startsWith('diff --git') || line.startsWith('+++') || line.startsWith('---')) { // If we have content and it's getting large, save current chunk if (currentChunk && tokenCount > MAX_TOKENS_PER_REQUEST) { From 5ad93a362fb2abf97b7c3ec9c8ff55f4e48020fc Mon Sep 17 00:00:00 2001 From: Ansel Robateau Date: Sun, 2 Nov 2025 12:05:42 -0600 Subject: [PATCH 15/15] feat: activate gemini calls --- .../actions/auto-pr-description/generate_pr_description.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/actions/auto-pr-description/generate_pr_description.js b/.github/actions/auto-pr-description/generate_pr_description.js index ef0007a..7eac3cd 100644 --- a/.github/actions/auto-pr-description/generate_pr_description.js +++ b/.github/actions/auto-pr-description/generate_pr_description.js @@ -153,7 +153,6 @@ ${diffContent}`; */ async function callGeminiAPI(prompt, apiKey) { console.error(`Sending prompt with an estimated ${estimateTokens(prompt)} tokens`); - return 'gemini'; /* const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, @@ -188,7 +187,6 @@ async function callGeminiAPI(prompt, apiKey) { } return json.candidates[0].content.parts[0].text; - */ } /** @@ -208,7 +206,7 @@ async function processChunks(chunks, apiKey) { const chunk = chunks[i]; if (i > 0) { // sleep for 3 seconds - sleep(3 * 1000); + sleep(5 * 1000); } console.error(`Processing chunk ${i + 1}/${Math.min(chunks.length, MAX_CHUNKS)} (${chunk.file || 'unknown file'})`); @@ -227,7 +225,7 @@ async function processChunks(chunks, apiKey) { if (chunkResults.length === 0) { throw new Error('Failed to process any chunks'); } - sleep(3*1000); + sleep(5*1000); // Combine results from multiple chunks const combinedPrompt = `Combine these pull request descriptions into a single, coherent PR description. Use the same format: