-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add commit command to generate commit messages using LLM
- Integrates a new command to automatically generate commit messages using a language model - Enhances the CLI with a streamlined process for creating meaningful commit messages - Adds utility functions to extract content between tags and run subprocesses asynchronously
- Loading branch information
Showing
13 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from . import repo | ||
from . import commit, repo | ||
from ._app import app | ||
|
||
__all__ = ["app", "repo"] | ||
__all__ = ["app", "commit", "repo"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import typer | ||
|
||
import llm_cli.cmd as lc | ||
import llm_cli.utils as lu | ||
from llm_cli import cmd | ||
|
||
app: typer.Typer = typer.Typer(name="llm-cli", no_args_is_help=True) | ||
lu.add_command(app, lc.repo.app) | ||
lu.add_command(app, cmd.repo.app) | ||
lu.add_command(app, cmd.commit.app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import lazy_loader as lazy | ||
|
||
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from ._app import app | ||
from ._main import main | ||
|
||
__all__ = ["app", "main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import asyncio | ||
|
||
import typer | ||
|
||
app = typer.Typer(name="commit") | ||
|
||
|
||
@app.command() | ||
def main() -> None: | ||
from ._main import main | ||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import asyncio | ||
import string | ||
|
||
import git | ||
import litellm | ||
import typer | ||
|
||
import llm_cli as lc | ||
import llm_cli.utils as lu | ||
|
||
|
||
async def main(*, verify: bool = True) -> None: | ||
prompt_template = string.Template(lu.get_prompt("commit")) | ||
repo = git.Repo(search_parent_directories=True) | ||
diff: str = repo.git.diff("--cached", "--no-ext-diff") | ||
files: str = repo.git.ls_files() | ||
prompt: str = prompt_template.substitute({"GIT_DIFF": diff, "GIT_FILES": files}) | ||
resp: litellm.ModelResponse = await lc.output(prompt, prefix="<Answer>") | ||
choices: litellm.Choices = resp.choices[0] # pyright: ignore [reportAssignmentType] | ||
message: str = lu.extract_between_tags(choices.message.content) | ||
proc: asyncio.subprocess.Process = await lu.run( | ||
"git", | ||
"commit", | ||
f"--message={message}", | ||
"--verify" if verify else "--no-verify", | ||
"--edit", | ||
check=False, | ||
) | ||
if proc.returncode: | ||
raise typer.Exit(proc.returncode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from ._app import app | ||
from ._main import main | ||
|
||
__all__ = ["app"] | ||
__all__ = ["app", "main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from ._app import app | ||
from ._main import main | ||
|
||
__all__ = ["app"] | ||
__all__ = ["app", "main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
from . import git | ||
from ._add_command import add_command | ||
from ._extract_between_tags import extract_between_tags | ||
from ._get_app_dir import get_app_dir | ||
from ._get_prompt import get_prompt | ||
from ._repomix import repomix | ||
from ._run import run | ||
|
||
__all__ = ["add_command", "get_app_dir", "get_prompt", "git", "repomix", "run"] | ||
__all__ = [ | ||
"add_command", | ||
"extract_between_tags", | ||
"get_app_dir", | ||
"get_prompt", | ||
"git", | ||
"repomix", | ||
"run", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def extract_between_tags(content: str | None, tag: str = "Answer") -> str: | ||
if content is None: | ||
return "" | ||
start: int = content.find("<" + tag + ">") | ||
if start >= 0: | ||
start += len(tag) + 2 | ||
content = content[start:] | ||
end: int = content.find("</" + tag + ">") | ||
if end >= 0: | ||
content = content[:end] | ||
return content.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters