Skip to content

Commit

Permalink
Update code style for better readability and maintainability
Browse files Browse the repository at this point in the history
Various changes have been made to improve the readability and maintainability of the code. These changes include reformatting lists and function arguments for better visibility, updating syntax to meet PEP8 standards, and making sure all diffs are correctly formatted.
  • Loading branch information
use-the-fork committed Dec 29, 2023
1 parent be1b313 commit 46a4070
Show file tree
Hide file tree
Showing 43 changed files with 580 additions and 605 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
poetry install
- name: Run and upload benchmarks
run: ./scripts/run_and_upload_benchmarks.sh
run: poetry run ./scripts/run_and_upload_benchmarks.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
# Ensure that python doesn't import local mentat folder and that 'mentat' command calls mentat instead of switching folders.
working-directory: ./testbed
run: |
mentat
poetry run mentat
license-check:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions mentat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
def __dir__():
return __all__


# Make sure to bump this on Release x.y.z PR's!
__version__ = "1.0.7"
13 changes: 10 additions & 3 deletions mentat/agent_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@
class AgentHandler:

config = mentat.user_session.get("config")
agent_file_selection_prompt_path = config.ai.prompts.get("agent_file_selection_prompt", Path("text/agent_file_selection_prompt.txt"))
agent_command_prompt_path = config.ai.prompts.get("agent_command_selection_prompt", Path("text/agent_command_selection_prompt.txt"))
agent_file_selection_prompt_path = config.ai.prompts.get(
"agent_file_selection_prompt", Path("text/agent_file_selection_prompt.txt")
)
agent_command_prompt_path = config.ai.prompts.get(
"agent_command_selection_prompt",
Path("text/agent_command_selection_prompt.txt"),
)

def __init__(self):
self._agent_enabled = False

self.agent_file_message = ""
self.agent_file_selection_prompt = read_prompt(self.agent_file_selection_prompt_path)
self.agent_file_selection_prompt = read_prompt(
self.agent_file_selection_prompt_path
)
self.agent_command_prompt = read_prompt(self.agent_command_prompt_path)

# Make this property readonly because we have to set things when we enable agent mode
Expand Down
24 changes: 12 additions & 12 deletions mentat/code_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def display_context(self):

if config.run.auto_context_tokens > 0:
stream.send(f"{prefix}Auto-Context: Enabled")
stream.send(f"{prefix}Auto-Context Tokens: {config.run.auto_context_tokens}")
stream.send(
f"{prefix}Auto-Context Tokens: {config.run.auto_context_tokens}"
)
else:
stream.send(f"{prefix}Auto-Context: Disabled")

Expand Down Expand Up @@ -156,7 +158,9 @@ async def get_code_message(

if not is_context_sufficient(tokens_used):
raise ContextSizeInsufficient()
auto_tokens = min(get_max_tokens() - tokens_used, config.run.auto_context_tokens)
auto_tokens = min(
get_max_tokens() - tokens_used, config.run.auto_context_tokens
)

# Get auto included features
if config.run.auto_context_tokens > 0 and prompt:
Expand Down Expand Up @@ -191,9 +195,7 @@ def get_all_features(
config = mentat.user_session.get("config")

abs_exclude_patterns: Set[Path] = set()
for pattern in self.ignore_patterns.union(
config.run.file_exclude_glob_list
):
for pattern in self.ignore_patterns.union(config.run.file_exclude_glob_list):
if not Path(pattern).is_absolute():
abs_exclude_patterns.add(session_context.cwd / pattern)
else:
Expand Down Expand Up @@ -277,13 +279,11 @@ def include(
path = Path(path)

abs_exclude_patterns: Set[Path] = set()
all_exclude_patterns: Set[Union[str, Path]] = set(
[
*exclude_patterns,
*self.ignore_patterns,
*config.run.file_exclude_glob_list,
]
)
all_exclude_patterns: Set[Union[str, Path]] = set([
*exclude_patterns,
*self.ignore_patterns,
*config.run.file_exclude_glob_list,
])

for pattern in all_exclude_patterns:
if not Path(pattern).is_absolute():
Expand Down
1 change: 0 additions & 1 deletion mentat/code_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from mentat.session_context import SESSION_CONTEXT
from mentat.utils import get_relative_path


MIN_INTERVAL_LINES = 10


Expand Down
8 changes: 4 additions & 4 deletions mentat/command/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
class ConfigCommand(Command, command_name="config"):
@override
async def apply(self, *args: str) -> None:
from mentat.config import mid_session_config, update_config, get_config
from mentat.config import get_config, mid_session_config, update_config

session_context = SESSION_CONTEXT.get()
stream = session_context.stream


if len(args) == 0:
stream.send("No config option specified", color="yellow")
elif len(args) == 1 or len(args) == 2:
Expand Down Expand Up @@ -51,10 +51,10 @@ def argument_autocompletions(
"prompt_type",
"format",
"maximum_context",
"auto_context_tokens"
"auto_context_tokens",
]
elif argument_position == 1:
#TODO: Figure out a better way of doing this.
# TODO: Figure out a better way of doing this.
return []
else:
return []
Expand Down
2 changes: 1 addition & 1 deletion mentat/command/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _parse_include_input(user_input: str, max_num: int) -> Set[int] | None:
class SearchCommand(Command, command_name="search"):
@override
async def apply(self, *args: str) -> None:
config = mentat.user_session.get('config')
config = mentat.user_session.get("config")

session_context = SESSION_CONTEXT.get()
stream = session_context.stream
Expand Down
Loading

0 comments on commit 46a4070

Please sign in to comment.