Skip to content

Commit

Permalink
chore: fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-luke committed Nov 10, 2023
1 parent 80183ca commit 455143c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jobs:

- name: Run self test
if : ${{ matrix.python-version == '3.11' }}
run: hatch run docstring-auditor --code-block-name docstring_auditor
run: hatch run docstring-auditor --code-block-name process_directory
23 changes: 11 additions & 12 deletions docstring_auditor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import time
import json
from typing import List, Optional, Dict, Tuple
import openai
from openai import OpenAI

client = OpenAI()


def extract_code_block(
Expand Down Expand Up @@ -222,11 +224,11 @@ def ask_for_critique(function: str, model: str) -> Dict[str, str]:
},
{"role": "user", "content": function},
]
response = openai.ChatCompletion.create(
model=model, temperature=0.0, messages=messages
response = client.chat.completions.create(
model=model, temperature=0.0, messages=messages, response_format= { "type":"json_object" }
)

response_str = response["choices"][0]["message"]["content"]
response_str = response.choices[0].message.content
response_dict = json.loads(response_str)

return response_dict
Expand Down Expand Up @@ -355,14 +357,14 @@ def process_file(
)
assert isinstance(function_or_method, str)
errors, warnings, solution = 0, 0, None
for i in range(3):
for i in range(1):
try:
critique = ask_for_critique(function_or_method, model)
errors, warnings, solution = report_concerns(critique)
break
except Exception as e:
print(e)
if i < 2:
if i < 0:
print(f"Retrying in {2 ** i} seconds...")
time.sleep(2**i)
else:
Expand All @@ -380,7 +382,7 @@ def process_directory(
directory_path: str,
model: str,
auto_fix: bool,
ignore_dirs: Optional[List[str]] = None,
ignore_dirs: Optional[List[str]] = ["tests"],
code_block_name: str = "",
) -> Tuple[int, int]:
"""
Expand All @@ -391,11 +393,11 @@ def process_directory(
directory_path : str
The path to the directory containing .py files to analyze the functions' docstrings.
model : str
The name of the OpenAI model to use for the docstring analysis.
The name of the model to use for the docstring analysis.
auto_fix : bool
Whether to automatically fix the docstring errors and warnings.
ignore_dirs : Optional[List[str]], optional
A list of directory names to ignore while processing .py files. By default, it ignores the "tests" directory.
A list of directory names to ignore while processing .py files. Defaults to ['tests'].
code_block_name : str, optional
The name of a single block of code that you want audited, rather than all the code blocks.
If you want all the code blocks audited, leave this blank.
Expand All @@ -405,9 +407,6 @@ def process_directory(
Tuple[int, int]
A tuple containing the total number of errors and warnings found in the docstrings of the .py files.
"""
if ignore_dirs is None:
ignore_dirs = ["tests"]

error_count = 0
warning_count = 0

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ docstring-auditor = "python docstring_auditor/main.py {args}"
[tool.hatch.envs.default]
dependencies = [
"click",
"openai==0.28",
"openai>=1.2.0",
]

[tool.hatch.envs.dev]
dependencies = [
"click",
"openai==0.28",
"openai>=1.2.0",
"mypy",
"black",
"pytest",
Expand Down

0 comments on commit 455143c

Please sign in to comment.