|
5 | 5 |
|
6 | 6 | import arrow |
7 | 7 | from langchain_core.output_parsers.pydantic import PydanticOutputParser |
8 | | -from langchain_core.prompts import PromptTemplate |
| 8 | +from langchain_core.prompts import ChatPromptTemplate, PromptTemplate |
9 | 9 | from pydantic import BaseModel, Field |
10 | 10 |
|
11 | 11 | from aicodebot import AICODEBOT_NO_EMOJI |
@@ -322,50 +322,61 @@ def generate_files_context(files): |
322 | 322 | """ |
323 | 323 | ) |
324 | 324 |
|
325 | | -COMMIT_TEMPLATE = ( |
| 325 | +COMMIT_SYSTEM_PROMPT = ( |
326 | 326 | EXPERT_SOFTWARE_ENGINEER |
327 | 327 | + get_personality_prompt() |
328 | 328 | + """ |
329 | 329 |
|
330 | | - I need you to generate a commit message for a change in a git repository.""" |
331 | | - + DIFF_CONTEXT_EXPLANATION |
332 | | - + """ |
| 330 | +You are an expert at writing exceptional Git commit messages that follow best practices. |
333 | 331 |
|
334 | | - Here's the DIFF that will be committed: |
| 332 | +CORE PRINCIPLES: |
| 333 | +• Write the full detailed message first, thinking through all changes comprehensively |
| 334 | +• Then distill that into a perfect summary line |
| 335 | +• Focus on WHY and WHAT functionality changed, not just HOW |
| 336 | +• Scale message length to change complexity - small changes get terse messages |
| 337 | +• Use imperative mood ("Add feature" not "Added feature") |
| 338 | +• Include an emoji from gitmoji when appropriate and helpful |
335 | 339 |
|
336 | | - BEGIN DIFF |
337 | | - {diff_context} |
338 | | - END DIFF |
| 340 | +COMMIT MESSAGE STRUCTURE: |
| 341 | +1. Summary line: <72 chars, imperative mood, capitalize after emoji, no period |
| 342 | +2. Blank line (if detail needed) |
| 343 | +3. Detailed explanation (if summary insufficient) |
| 344 | +
|
| 345 | +QUALITY GUIDELINES: |
| 346 | +• Explain WHY the change was made, not WHAT was changed (diff shows what) |
| 347 | +• Provide context: motivation, problem being solved, business impact |
| 348 | +• Explain trade-offs, alternatives considered, or implementation decisions |
| 349 | +• Keep body concise - wrap at 72 characters, focus on valuable context only |
| 350 | +• For simple changes, omit the body entirely if summary is sufficient |
| 351 | +• Never repeat information that's obvious from reading the diff |
| 352 | +
|
| 353 | +SAMPLE EXCELLENCE: |
| 354 | +🔐 Implement user authentication with JWT tokens |
| 355 | +
|
| 356 | +Replaces session-based auth to support mobile apps and API access. |
| 357 | +JWT tokens allow stateless authentication and better scaling. Tokens |
| 358 | +expire after 24h for security while maintaining user convenience. |
339 | 359 |
|
340 | | - Instructions for the commit message: |
341 | | - * Start with a short summary (less than 72 characters). |
342 | | - * Follow with a blank line and detailed text, but only if necessary. If the summary is sufficient, |
343 | | - then omit the detailed text. |
344 | | - * Determine what functionality was added or modified instead of just describing the exact changes. |
345 | | - * Use imperative mood (e.g., "Add feature") |
346 | | - * Be in GitHub-flavored markdown format. |
347 | | - * Have a length that scales with the length of the diff context. If the DIFF is a small change, |
348 | | - respond quickly with a terse message so we can go faster. |
349 | | - * Do not repeat information that is already known from the git commit. |
350 | | - * Be terse. |
351 | | - * Do not add anything other then description of code changes. |
352 | | -
|
353 | | - BEGIN SAMPLE COMMIT MESSAGE |
354 | | - Update README with better instructions for installation |
355 | | -
|
356 | | - The previous instructions were not clear enough for new users, so we've updated them |
357 | | - with more sample use cases and an improved installation process. This should help |
358 | | - new users get started faster. |
359 | | - END SAMPLE COMMIT MESSAGE |
360 | | -
|
361 | | - Formatting instructions: |
362 | | - Start your response with the commit message. No prefix or introduction. |
363 | | - Your entire response will be the commit message. No quotation marks. |
364 | | -
|
365 | | - Include an emoji from gitmoji when appropriate and helpful |
| 360 | +SIMPLE CHANGE EXAMPLE: |
| 361 | +🐛 Handle null values in user preferences |
| 362 | +
|
| 363 | +(no body needed - summary explains the fix completely) |
366 | 364 | """ |
367 | 365 | ) |
368 | 366 |
|
| 367 | +COMMIT_USER_TEMPLATE = """Generate a commit message for this git diff: |
| 368 | +
|
| 369 | +```diff |
| 370 | +{diff_context} |
| 371 | +``` |
| 372 | +
|
| 373 | +Languages: {languages} |
| 374 | +
|
| 375 | +Think about WHY this change was made - what problem does it solve? What's the motivation? |
| 376 | +Write a brief body explaining the context/reasoning (omit if summary is sufficient). |
| 377 | +Then create a perfect summary line under 72 characters. |
| 378 | +""" |
| 379 | + |
369 | 380 | DEBUG_TEMPLATE = ( |
370 | 381 | EXPERT_SOFTWARE_ENGINEER |
371 | 382 | + get_personality_prompt() |
@@ -450,7 +461,9 @@ def get_prompt(command, structured_output=False): |
450 | 461 | else: |
451 | 462 | prompt_map = { |
452 | 463 | "alignment": PromptTemplate(template=ALIGNMENT_TEMPLATE, input_variables=[]), |
453 | | - "commit": PromptTemplate(template=COMMIT_TEMPLATE, input_variables=["diff_context", "languages"]), |
| 464 | + "commit": ChatPromptTemplate.from_messages( |
| 465 | + [("system", COMMIT_SYSTEM_PROMPT), ("user", COMMIT_USER_TEMPLATE)] |
| 466 | + ), |
454 | 467 | "debug": PromptTemplate(template=DEBUG_TEMPLATE, input_variables=["command_output", "languages"]), |
455 | 468 | "fun_fact": PromptTemplate(template=FUN_FACT_TEMPLATE, input_variables=["topic"]), |
456 | 469 | "sidekick": PromptTemplate(template=SIDEKICK_TEMPLATE, input_variables=["task", "context", "languages"]), |
|
0 commit comments