added option '-l' to list all tags and their frequency
This commit is contained in:
parent
32bd17594b
commit
5d55bed0ec
@ -28,7 +28,7 @@ pip install .
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
cmm [-h] [-p PRINT | -q QUESTION | -D | -d] [-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 ...]]] [-w] [-W]
|
||||
```
|
||||
|
||||
### Arguments
|
||||
@ -39,6 +39,7 @@ cmm [-h] [-p PRINT | -q QUESTION | -D | -d] [-c CONFIG] [-m MAX_TOKENS] [-T TEMP
|
||||
- `-d`, `--chat`: Print chat history as readable text.
|
||||
- `-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.
|
||||
- `-c`, `--config`: Config file name (defaults to `.config.yaml`).
|
||||
- `-m`, `--max-tokens`: Max tokens to use.
|
||||
- `-T`, `--temperature`: Temperature to use.
|
||||
|
||||
@ -7,8 +7,8 @@ import sys
|
||||
import argcomplete
|
||||
import argparse
|
||||
import pathlib
|
||||
from .utils import terminal_width, process_tags, display_chat, display_source_code
|
||||
from .storage import save_answers, create_chat, get_tags, read_file, dump_data
|
||||
from .utils import terminal_width, process_tags, display_chat, display_source_code, display_tags_frequency
|
||||
from .storage import save_answers, create_chat, get_tags, get_tags_unique, read_file, dump_data
|
||||
from .api_client import ai, openai_api_key
|
||||
from itertools import zip_longest
|
||||
|
||||
@ -60,6 +60,12 @@ def process_and_display_chat(args: argparse.Namespace,
|
||||
display_chat(chat, dump, args.only_source_code)
|
||||
return chat, full_question, tags
|
||||
|
||||
def process_and_display_tags(args: argparse.Namespace,
|
||||
config: dict,
|
||||
dump: bool=False
|
||||
) -> None:
|
||||
display_tags_frequency(get_tags(config, None), dump)
|
||||
|
||||
|
||||
def handle_question(args: argparse.Namespace,
|
||||
config: dict,
|
||||
@ -76,7 +82,7 @@ def handle_question(args: argparse.Namespace,
|
||||
def tags_completer(prefix, parsed_args, **kwargs):
|
||||
with open(parsed_args.config, 'r') as f:
|
||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||
return get_tags(config, prefix)
|
||||
return get_tags_unique(config, prefix)
|
||||
|
||||
|
||||
def create_parser() -> argparse.ArgumentParser:
|
||||
@ -88,6 +94,7 @@ def create_parser() -> argparse.ArgumentParser:
|
||||
group.add_argument('-q', '--question', nargs='*', help='Question to ask')
|
||||
group.add_argument('-D', '--chat-dump', help="Print chat history as Python structure", action='store_true')
|
||||
group.add_argument('-d', '--chat', help="Print chat history as readable text", action='store_true')
|
||||
group.add_argument('-l', '--list-tags', help="List all tags and their frequency", action='store_true')
|
||||
parser.add_argument('-c', '--config', help='Config file name.', default=default_config)
|
||||
parser.add_argument('-m', '--max-tokens', help='Max tokens to use', type=int)
|
||||
parser.add_argument('-T', '--temperature', help='Temperature to use', type=float)
|
||||
@ -133,6 +140,8 @@ def main() -> int:
|
||||
process_and_display_chat(args, config, dump=True)
|
||||
elif args.chat:
|
||||
process_and_display_chat(args, config)
|
||||
elif args.list_tags:
|
||||
process_and_display_tags(args, config)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
@ -105,4 +105,7 @@ def get_tags(config: Dict[str, Any], prefix: Optional[str]) -> List[str]:
|
||||
result.append(tag)
|
||||
else:
|
||||
result.append(tag)
|
||||
return list(set(result))
|
||||
return result
|
||||
|
||||
def get_tags_unique(config: Dict[str, Any], prefix: Optional[str]) -> List[str]:
|
||||
return list(set(get_tags(config, prefix)))
|
||||
|
||||
@ -73,3 +73,10 @@ def display_chat(chat, dump=False, source_code=False) -> None:
|
||||
print(message['content'])
|
||||
else:
|
||||
print(f"{message['role'].upper()}: {message['content']}")
|
||||
|
||||
def display_tags_frequency(tags: List[str], dump=False) -> None:
|
||||
if dump:
|
||||
pp(tags)
|
||||
return
|
||||
for tag in set(tags):
|
||||
print(f"-{tag} : {tags.count(tag)}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user