|
6 | 6 | from pathlib import Path
|
7 | 7 | from pydantic import BaseModel, Field
|
8 | 8 | from rich.panel import Panel
|
9 |
| -from typing import Optional |
10 | 9 | import click, os, shutil, subprocess, sys, tempfile
|
11 | 10 |
|
12 | 11 |
|
13 | 12 | class CommitMessage(BaseModel):
|
14 |
| - # Use Optional[str] instead of str | None for Python 3.9 compatibility |
15 |
| - git_message_detail: Optional[str] = Field( # noqa: UP007 |
| 13 | + # Note we get better results if the message_detail is first. |
| 14 | + git_message_detail: str | None = Field( |
16 | 15 | default="",
|
17 | 16 | description="An optional detailed explanation of the changes made in this commit,"
|
18 | 17 | " if the summary doesn't provide enough context",
|
@@ -103,9 +102,9 @@ def commit(response_token_size, yes, skip_pre_commit, files): # noqa: PLR0915
|
103 | 102 | chain = prompt | structured_llm
|
104 | 103 | response = chain.invoke({"diff_context": diff_context, "languages": languages})
|
105 | 104 |
|
106 |
| - commit_message = response["git_message_summary"] |
107 |
| - if response.get("git_message_detail"): |
108 |
| - commit_message += f"\n\n{response['git_message_detail']}" |
| 105 | + commit_message = response.git_message_summary |
| 106 | + if response.git_message_detail: |
| 107 | + commit_message += f"\n\n{response.git_message_detail}" |
109 | 108 |
|
110 | 109 | console.print(Panel(OurMarkdown(commit_message)))
|
111 | 110 |
|
|
0 commit comments