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

Minor codex improvements #1600

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions slither/detectors/functions/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def _run_codex(self, logging_file: str, prompt: str) -> str:

answer = ""
res = {}

if self.slither.codex_organization:
openai_module.organization = self.slither.codex_organization

try:
res = openai_module.Completion.create(
prompt=prompt,
Expand Down
3 changes: 2 additions & 1 deletion slither/slither.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Union, List, ValuesView, Type, Dict
from typing import Union, List, ValuesView, Type, Dict, Optional

from crytic_compile import CryticCompile, InvalidCompilation

Expand Down Expand Up @@ -90,6 +90,7 @@ def __init__(self, target: Union[str, CryticCompile], **kwargs):
self.codex_temperature = kwargs.get("codex_temperature", 0)
self.codex_max_tokens = kwargs.get("codex_max_tokens", 300)
self.codex_log = kwargs.get("codex_log", False)
self.codex_organization: Optional[str] = kwargs.get("codex_organization", None)

self.no_fail = kwargs.get("no_fail", False)

Expand Down
12 changes: 10 additions & 2 deletions slither/tools/documentation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def parse_args() -> argparse.Namespace:
default=False,
)

parser.add_argument(
"--include-tests",
help="Include the tests",
action="store_true",
default=False,
)

parser.add_argument(
"--retry",
help="Retry failed query (default 1). Each retry increases the temperature by 0.1",
Expand Down Expand Up @@ -202,6 +209,7 @@ def _handle_compilation_unit(
overwrite: bool,
force: bool,
retry: int,
include_test: bool,
) -> None:
logging_file: Optional[str]
if slither.codex_log:
Expand All @@ -210,9 +218,8 @@ def _handle_compilation_unit(
logging_file = None

for scope in compilation_unit.scopes.values():

# Dont send tests file
if (
if not include_test and (
".t.sol" in scope.filename.absolute
or "mock" in scope.filename.absolute.lower()
or "test" in scope.filename.absolute.lower()
Expand Down Expand Up @@ -271,6 +278,7 @@ def main() -> None:
args.overwrite,
args.force_answer_parsing,
int(args.retry),
args.include_tests,
)
except ImportError:
pass
Expand Down
7 changes: 7 additions & 0 deletions slither/utils/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def init_parser(parser: ArgumentParser, always_enable_codex: bool = False) -> No
default=defaults_flag_in_config["codex_max_tokens"],
)

group_codex.add_argument(
"--codex-organization",
help="Codex organization",
action="store",
default=None,
)


# TODO: investigate how to set the correct return type
# So that the other modules can work with openai
Expand Down