review.bot.open_ai_interface#

Functions to interface with OpenAI.

Module Contents#

Functions#

review_patch(→ List[Dict])

Review a patch in a pull request and generate suggestions for improvement.

review_folder(→ List[Dict])

Reviews an specific file from the PR. The file must have been modified in the PR.

review_file(→ List[Dict])

Reviews an specific file from the PR. The file must have been modified in the PR.

review_patch_local(→ List[Dict])

Review a patch in a pull request and generate suggestions for improvement.

message_generation(→ str)

Generate the required message for each type of query request.

generate_suggestions(→ List[Dict[str, str]])

Generate suggestions for a given file source and patch.

Attributes#

LOG

OPEN_AI_MODEL

review.bot.open_ai_interface.LOG#
review.bot.open_ai_interface.OPEN_AI_MODEL#
review.bot.open_ai_interface.review_patch(owner: str, repo: str, pr: int, use_src: bool = False, filter_filename=None, gh_access_token: str = None, docs_only: bool = False, config_file: str = None) List[Dict]#

Review a patch in a pull request and generate suggestions for improvement.

Parameters:
ownerstr

The GitHub owner/organization of the repository.

repostr

The name of the repository on GitHub.

prstr

The pull request number.

use_srcbool, default: False

Use the source file as context for the patch. Works for small files and not for large ones.

filter_filenamestr, optional

If set, filters out all but the file matching this string.

gh_access_tokenstr, optional

GitHub token needed to communicate with the repository. By default, None, which means it will try to read an existing env variable named GITHUB_TOKEN.

config_filestr, optional

Path to OpenAI configuration file. By default, None.

Returns
——-
list[dict]

A dictionary containing suggestions for the reviewed patch.

review.bot.open_ai_interface.review_folder(owner: str, repo: str, pr: int, folder: str, gh_access_token: str = None, config_file: str = None) List[Dict]#

Reviews an specific file from the PR. The file must have been modified in the PR.

Parameters:
ownerstr

The GitHub owner/organization of the repository.

repostr

The name of the repository on GitHub.

prstr

The pull request number.

folderstr

Name of the folder you want to review.

gh_access_tokenstr, optional

GitHub token needed to communicate with the repository. By default, None, which means it will try to read an existing env variable named GITHUB_TOKEN.

config_filestr, optional

Path to OpenAI configuration file. By default, None.

Returns:
List[Dict]

List of dictionaries with the PR suggestions.

review.bot.open_ai_interface.review_file(owner: str, repo: str, pr: int, filename: str, gh_access_token: str = None, config_file: str = None) List[Dict]#

Reviews an specific file from the PR. The file must have been modified in the PR.

Parameters:
ownerstr

The GitHub owner/organization of the repository.

repostr

The name of the repository on GitHub.

prstr

The pull request number.

filenamestr

Name of the file you want to review.

gh_access_tokenstr, optional

GitHub token needed to communicate with the repository. By default, None, which means it will try to read an existing env variable named GITHUB_TOKEN.

config_filestr, optional

Path to OpenAI configuration file. By default, None.

Returns:
List[Dict]

List of dictionaries with the PR suggestions.

review.bot.open_ai_interface.review_patch_local(repo: str, branch: str = None, use_src: bool = False, filter_filename: str = None, config_file: str = None) List[Dict]#

Review a patch in a pull request and generate suggestions for improvement.

Parameters:
repostr

The path to the local repository.

branchstr

Name of the branch you want to compare to main. By default, current branch.

use_srcbool, default: False

Use the source file as context for the patch. Works for small files and not for large ones.

filter_filenamestr, optional

If set, filters out all but the file matching this string.

config_filestr, optional

Path to OpenAI configuration file. By default, None.

Returns:
list[dict]

A dictionary containing suggestions for the reviewed patch.

review.bot.open_ai_interface.message_generation(filename: str, patch: str = None, file_src: str = None, docs_only: bool = False) str#

Generate the required message for each type of query request.

Parameters:
filenamestr

Name of the file being patched.

patchstr

The patch text containing line numbers and changes.

file_srcstr

The source file text including the file name and its contents.

docs_only: True

Flag to select whether to review the documentation only or not.

Returns:
list[dict]

A list with the messages to send to the LLM.

review.bot.open_ai_interface.generate_suggestions(filename, patch=None, file_src=None, config_file: str = None, docs_only=False) List[Dict[str, str]]#

Generate suggestions for a given file source and patch.

Parameters:
filenamestr

Name of the file being patched.

patchstr, optional

The patch text containing line numbers and changes.

file_src: str, optional

Source file of the patch.

config_filestr, optional

Path to OpenAI configuration file. By default, None.

docs_only: bool, optional

Whether to review documentation only or the whole code. By default False.

Returns
——-
list[dict]

A list of dictionaries containing suggestions for the patch.