Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Switch git commit to use gpt-35-turbo by default #59

Merged
merged 5 commits into from
May 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/gpt_review/_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Dict

from knack import CLICommandsLoader
from knack.arguments import ArgumentsContext
from knack.commands import CommandGroup
from git.repo import Repo

Expand Down Expand Up @@ -39,7 +40,7 @@ def _diff() -> str:
return Repo.init(_find_git_dir()).git.diff(None, cached=True)


def _commit_message() -> str:
def _commit_message(fast: bool = False, large: bool = False) -> str:
"""
Create a commit message with GPT.

Expand All @@ -53,17 +54,17 @@ def _commit_message() -> str:
diff = _diff()
logging.debug("Diff: %s", diff)

return _request_goal(diff, goal)
return _request_goal(diff, goal, fast=fast, large=large)


def _commit() -> Dict[str, str]:
def _commit(gpt4: bool = False, large: bool = False) -> Dict[str, str]:
"""
Run git commit with a commit message generated by GPT.

Returns:
response (dict): The response from GPT-4.
"""
message = _commit_message()
message = _commit_message(fast=not gpt4, large=large)
logging.debug("Commit Message: %s", message)
repo = Repo.init(_find_git_dir())
commit = repo.git.commit(message=message)
Expand All @@ -75,5 +76,21 @@ class GitCommandGroup(GPTCommandGroup):

@staticmethod
def load_command_table(loader: CLICommandsLoader) -> None:
with CommandGroup(loader, "git", "gpt_review._git#{}") as group:
with CommandGroup(loader, "git", "gpt_review._git#{}", is_preview=True) as group:
group.command("commit", "_commit", is_preview=True)

@staticmethod
def load_arguments(loader: CLICommandsLoader) -> None:
with ArgumentsContext(loader, "git commit") as args:
args.argument(
"gpt4",
help="Use gpt-4 for prompts instead of gpt-35-turbo.",
default=False,
action="store_true",
)
args.argument(
"large",
help="Use gpt-4-32k for prompts.",
default=False,
action="store_true",
)