Skip to content

Commit

Permalink
GPT-commit: Refactor openai_service.py for dynamic argument parsing.
Browse files Browse the repository at this point in the history
Refactor `openai_service.py` to implement dynamic argument parsing for improved functionality.
  • Loading branch information
hwixley committed Jan 21, 2024
1 parent 95b3d4e commit ebc106d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/commands/scripts/services/openai_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class OpenAIService:
KEY_PATH = f"{REPO_PATH}/.wix-cli-data/.env"
KEY_NAME="OPENAI_API_KEY"
ENGINE="gpt-3.5-turbo"
ASSISTANT_MESSAGE = { "role": "system", "content": f"You are a developer pushing code to a git repository. You are writing a commit message for the changes you have made. You must use the following bash git outputs to write an informative and relevant commit message. Make sure to ignore cache files and mention specifically which functions, classes or variables were modified/created/deleted and why.{LOCAL_README}"}
ASSISTANT_MESSAGE_DEV = { "role": "system", "content": f"You are a developer pushing code to a git repository. You are writing a commit message for the changes you have made. You must use the following bash git outputs to write an informative and relevant commit message. Make sure to ignore cache files and mention specifically which functions, classes or variables were modified/created/deleted and why.{LOCAL_README}"}
ASSISTANT_MESSAGE = { "role": "system", "content": f"You are an assistant setup on a command line for the WIX-CLI project"}
SEPARATOR="-"*110
MAX_TOKENS=4097

Expand Down Expand Up @@ -52,14 +53,16 @@ def get_git_diff(self):
return f"`git diff` output: {os.popen('git diff').read()}, and `git status` output: {os.popen('git status').read()}."

def get_commit_title(self):
chat_history = [self.ASSISTANT_MESSAGE_DEV]
title_prompt = f"You are in a team of developers working on a project. Write a 1 line commit message less than or equal to 50 characters technically describing the following bash git outputs. {self.get_git_diff()} Do not mention anything about the branch these changes were made on. Mention specifically which functions, classes or variables were modified/created/deleted and why."
title_response = self.get_response(title_prompt)
title_response = self.get_response(title_prompt, chat_history)
return f"GPT-commit: {title_response}"

def get_commit_description(self):
chat_history = [self.ASSISTANT_MESSAGE_DEV]
title = self.get_commit_title()
description_prompt = f"You are in a team of developers working on a project. Write a 2 line commit message technically describing the following bash git outputs. {self.get_git_diff()} Do not repeat the title \"{title}\", and do not mention anything about the branch these changes were made on. Mention specifically which functions, classes or variables were modified/created/deleted and why."
description_response = self.get_response(description_prompt)
description_response = self.get_response(description_prompt, chat_history)
return (title, description_response)

def get_smart_commit(self):
Expand Down

0 comments on commit ebc106d

Please sign in to comment.