added option '-a' to match all tags when selecting chat history entries

This commit is contained in:
juk0de 2023-08-05 11:41:36 +02:00
parent 5d55bed0ec
commit 8e4a02b932
3 changed files with 11 additions and 4 deletions

View File

@ -28,7 +28,7 @@ pip install .
## Usage
```bash
cmm [-h] [-p PRINT | -q QUESTION | -D | -d | -l] [-c CONFIG] [-m MAX_TOKENS] [-T TEMPERATURE] [-M MODEL] [-n NUMBER] [-t [TAGS [TAGS ...]]] [-e [EXTAGS [EXTAGS ...]]] [-o [OTAGS [OTAGS ...]]] [-w] [-W]
cmm [-h] [-p PRINT | -q QUESTION | -D | -d | -l] [-c CONFIG] [-m MAX_TOKENS] [-T TEMPERATURE] [-M MODEL] [-n NUMBER] [-t [TAGS [TAGS ...]]] [-e [EXTAGS [EXTAGS ...]]] [-o [OTAGS [OTAGS ...]]] [-a] [-w] [-W]
```
### Arguments
@ -37,6 +37,7 @@ cmm [-h] [-p PRINT | -q QUESTION | -D | -d | -l] [-c CONFIG] [-m MAX_TOKENS] [-T
- `-q`, `--question`: Question to ask.
- `-D`, `--chat-dump`: Print chat history as a Python structure.
- `-d`, `--chat`: Print chat history as readable text.
- `-a`, `--match-all-tags`: All given tags must match when selecting chat history entries.
- `-w`, `--with-tags`: Print chat history with tags.
- `-W`, `--with-tags`: Print chat history with filenames.
- `-l`, `--list-tags`: List all tags and their frequency.

View File

@ -56,7 +56,8 @@ def process_and_display_chat(args: argparse.Namespace,
full_question = '\n\n'.join(question_parts)
chat = create_chat(full_question, tags, extags, config,
args.with_tags, args.with_file)
args.match_all_tags, args.with_tags,
args.with_file)
display_chat(chat, dump, args.only_source_code)
return chat, full_question, tags
@ -104,6 +105,7 @@ def create_parser() -> argparse.ArgumentParser:
parser.add_argument('-S', '--only-source-code', help='Print only source code', action='store_true')
parser.add_argument('-w', '--with-tags', help="Print chat history with tags.", action='store_true')
parser.add_argument('-W', '--with-file', help="Print chat history with filename.", action='store_true')
parser.add_argument('-a', '--match-all-tags', help="All given tags must match when selecting chat history entries.", action='store_true')
tags_arg = parser.add_argument('-t', '--tags', nargs='*', help='List of tag names', metavar='TAGS')
tags_arg.completer = tags_completer # type: ignore
extags_arg = parser.add_argument('-e', '--extags', nargs='*', help='List of tag names to exclude', metavar='EXTAGS')

View File

@ -64,6 +64,7 @@ def create_chat(question: Optional[str],
tags: Optional[List[str]],
extags: Optional[List[str]],
config: Dict[str, Any],
match_all_tags: bool = False,
with_tags: bool = False,
with_file: bool = False
) -> List[Dict[str, str]]:
@ -78,8 +79,11 @@ def create_chat(question: Optional[str],
else:
continue
data_tags = set(data.get('tags', []))
tags_match = \
not tags or data_tags.intersection(tags)
tags_match: bool
if match_all_tags:
tags_match = not tags or set(tags).issubset(data_tags)
else:
tags_match = not tags or bool(data_tags.intersection(tags))
extags_do_not_match = \
not extags or not data_tags.intersection(extags)
if tags_match and extags_do_not_match: