review.bot.misc
#
Miscellaneous functions.
Module Contents#
Functions#
|
Get the OpenAI client with the configuration file initialization. |
|
Start logging to standard output. |
|
Add line numbers to the added lines in a given patch string. |
|
Clean |
|
Join the list of the content. |
|
Parse a given text block containing suggestions. |
Attributes#
- review.bot.misc.LOG#
- review.bot.misc.get_client(config_file: str = None) openai.OpenAI | openai.AzureOpenAI #
Get the OpenAI client with the configuration file initialization.
- review.bot.misc.open_logger(loglevel='DEBUG', formatstr='%(name)-20s - %(levelname)-8s - %(message)s')#
Start logging to standard output.
- Parameters:
- loglevel
str
,optional
Standard logging level. One of the following:
"DEBUG"
(default)"INFO"
"WARNING"
"ERROR"
"CRITICAL"
- formatstr
str
,optional
Format string. See
logging.Formatter
.
- loglevel
- Returns:
logging.RootLogger
Root logging object.
Examples
Output logging to stdout at the
'INFO'
level.>>> import review.bot as review_bot >>> review_bot.open_logger('INFO')
- review.bot.misc.add_line_numbers(patch)#
Add line numbers to the added lines in a given patch string.
The function takes a patch string and adds line numbers to the lines that start with a ‘+’. It returns a new patch string with added line numbers. Line numbers are added immediately to the left of any ‘+’.
- Parameters:
- patch
str
The patch string containing the changes in the file.
- patch
- Returns:
str
The modified patch string with line numbers added to the added lines.
Examples
>>> patch = '''@@ -1,3 +1,5 @@ ... +from itertools import permutations ... + ... import numpy as np ... import pytest''' >>> add_line_numbers(patch) '@@ -1,3 +1,5 @@ 1 +from itertools import permutations ... + ... import numpy as np ... import pytest'
- review.bot.misc.clean_string(input_text: str)#
Clean
type
andlines
strings.Clean type and lines strings in the LLM output, in case some unwanted characters are mixed with the desired content.
- review.bot.misc.clean_content(raw_content: List, text_block=None)#
Join the list of the content.
Join the list of the content, that might be split due to preprocessing, and cleans starting commas if they appear.
- review.bot.misc.parse_suggestions(text_block: str)#
Parse a given text block containing suggestions.
Returns a list of dictionaries with keys: filename, lines, type, and text.
- Parameters:
- text_block
str
The text block containing suggestions.
- text_block
- Returns:
Examples
>>> tblock = ''' ... [tests/test_geometric_objects.py], [259-260], [SUGGESTION]: Replace `Rectangle` with `Quadrilateral` for clarity and consistency with the name of the class being tested. ... ''' >>> parse_suggestions(tblock) [{'filename': 'tests/test_geometric_objects.py', 'lines': '259-260', 'type': 'SUGGESTION', 'text': 'Replace `Rectangle` with `Quadrilateral` for clarity and consistency with the name of the class being tested.'}]