Fix handling of -q and -s, add pre-commit checks.
This commit is contained in:
parent
ad10af8f4f
commit
df2f5e01a5
2
.flake8
2
.flake8
@ -1,6 +1,6 @@
|
||||
[flake8]
|
||||
exclude = .git,__pycache__,.venv
|
||||
per-file-ignores = __init__.py:F401
|
||||
per-file-ignores = __init__.py:F401, tests/test_ai.py:E501
|
||||
max-line-length = 140
|
||||
max-complexity = 10
|
||||
select = B,C,E,F,W,T4,B9
|
||||
|
||||
11
.pre-commit-config.yaml
Normal file
11
.pre-commit-config.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: 'v1.1.1'
|
||||
hooks:
|
||||
- id: mypy
|
||||
args: [--config-file=mypy.ini, --install-types, --non-interactive]
|
||||
|
||||
- repo: https://github.com/pycqa/flake8
|
||||
rev: 6.0.0
|
||||
hooks:
|
||||
- id: flake8
|
||||
@ -9,6 +9,7 @@ import argparse
|
||||
from .utils import terminal_width, pp, process_tags, display_chat
|
||||
from .storage import save_answers, create_chat, get_tags
|
||||
from .api_client import ai, openai_api_key
|
||||
from itertools import zip_longest
|
||||
|
||||
|
||||
def run_print_command(args: argparse.Namespace, config: dict) -> None:
|
||||
@ -32,23 +33,20 @@ def process_and_display_chat(args: argparse.Namespace,
|
||||
question_list = args.question if args.question is not None else []
|
||||
source_list = args.source if args.source is not None else []
|
||||
|
||||
for question, source in zip(question_list, source_list):
|
||||
with open(source) as r:
|
||||
question_parts.append(f"{question}\n\n```\n{r.read().strip()}\n```")
|
||||
|
||||
if len(question_list) > len(source_list):
|
||||
for question in question_list[len(source_list):]:
|
||||
for question, source in zip_longest(question_list, source_list, fillvalue=None):
|
||||
if question is not None and source is not None:
|
||||
with open(source) as r:
|
||||
question_parts.append(f"{question}\n\n```\n{r.read().strip()}\n```")
|
||||
elif question is not None:
|
||||
question_parts.append(question)
|
||||
else:
|
||||
for source in source_list[len(question_list):]:
|
||||
elif source is not None:
|
||||
with open(source) as r:
|
||||
question_parts.append(f"```\n{r.read().strip()}\n```")
|
||||
|
||||
question = '\n\n'.join(question_parts)
|
||||
|
||||
chat = create_chat(question, tags, extags, config)
|
||||
full_question = '\n\n'.join(question_parts)
|
||||
chat = create_chat(full_question, tags, extags, config)
|
||||
display_chat(chat, dump, args.only_source_code)
|
||||
return chat, question, tags
|
||||
return chat, full_question, tags
|
||||
|
||||
|
||||
def handle_question(args: argparse.Namespace,
|
||||
|
||||
@ -51,7 +51,7 @@ def create_chat(question: Optional[str],
|
||||
extags: Optional[List[str]],
|
||||
config: Dict[str, Any]
|
||||
) -> List[Dict[str, str]]:
|
||||
chat = []
|
||||
chat: List[Dict[str, str]] = []
|
||||
append_message(chat, 'system', config['system'].strip())
|
||||
for file in sorted(pathlib.Path(config['db']).iterdir()):
|
||||
if file.suffix == '.yaml':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user