Skip to content

Commit 76287d6

Browse files
fixed issue for not take too much tokens
1 parent cd13bc0 commit 76287d6

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ inputs:
3636
description: 'Only report security issues: true | false'
3737
required: false
3838
default: 'false'
39+
max_diff_chars:
40+
description: 'Max diff size in characters sent to the LLM (default: 20000)'
41+
required: false
42+
default: '20000'
3943
github_token:
4044
description: 'GitHub token for posting comments (defaults to GITHUB_TOKEN)'
4145
required: false
@@ -54,3 +58,4 @@ runs:
5458
POST_INLINE: ${{ inputs.post_inline }}
5559
SECURITY_ONLY: ${{ inputs.security_only }}
5660
GITHUB_TOKEN: ${{ inputs.github_token }}
61+
MAX_DIFF_CHARS: ${{ inputs.max_diff_chars }}

src/ai_reviewer/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Config(BaseSettings):
4646
post_summary: bool = True
4747
post_inline: bool = True
4848
security_only: bool = False
49+
max_diff_chars: int = 20000
4950

5051
@property
5152
def resolved_model(self) -> str:

src/ai_reviewer/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ async def run() -> None:
2626
print("[ai-reviewer] No diff found (all files ignored or empty PR). Skipping.")
2727
return
2828

29+
if len(diff) > config.max_diff_chars:
30+
diff = diff[: config.max_diff_chars]
31+
print(f"[ai-reviewer] Diff truncated to {config.max_diff_chars} chars to save tokens")
32+
2933
print(f"[ai-reviewer] Diff size: {len(diff)} chars")
3034

3135
# 2. Run LLM review

0 commit comments

Comments
 (0)