cmm: the 'tag' command now uses the new 'ChatDB'
This commit is contained in:
parent
168c1f0f65
commit
cf4ce1081d
@ -7,10 +7,11 @@ import sys
|
|||||||
import argcomplete
|
import argcomplete
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
from .utils import terminal_width, print_tag_args, print_chat_hist, display_source_code, print_tags_frequency, ChatType
|
from .utils import terminal_width, print_tag_args, print_chat_hist, display_source_code, ChatType
|
||||||
from .storage import save_answers, create_chat_hist, get_tags, get_tags_unique, read_file, dump_data
|
from .storage import save_answers, create_chat_hist, get_tags_unique, read_file, dump_data
|
||||||
from .api_client import ai, openai_api_key, print_models
|
from .api_client import ai, openai_api_key, print_models
|
||||||
from .configuration import Config
|
from .configuration import Config
|
||||||
|
from .chat import ChatDB
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -61,8 +62,12 @@ def tag_cmd(args: argparse.Namespace, config: Config) -> None:
|
|||||||
"""
|
"""
|
||||||
Handler for the 'tag' command.
|
Handler for the 'tag' command.
|
||||||
"""
|
"""
|
||||||
|
chat = ChatDB.from_dir(cache_path=pathlib.Path('.'),
|
||||||
|
db_path=pathlib.Path(config.db))
|
||||||
if args.list:
|
if args.list:
|
||||||
print_tags_frequency(get_tags(config, None))
|
tags_freq = chat.tags_frequency(args.prefix, args.contain)
|
||||||
|
for tag, freq in tags_freq.items():
|
||||||
|
print(f"- {tag}: {freq}")
|
||||||
|
|
||||||
|
|
||||||
def config_cmd(args: argparse.Namespace, config: Config) -> None:
|
def config_cmd(args: argparse.Namespace, config: Config) -> None:
|
||||||
@ -195,6 +200,8 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
tag_group = tag_cmd_parser.add_mutually_exclusive_group(required=True)
|
tag_group = tag_cmd_parser.add_mutually_exclusive_group(required=True)
|
||||||
tag_group.add_argument('-l', '--list', help="List all tags and their frequency",
|
tag_group.add_argument('-l', '--list', help="List all tags and their frequency",
|
||||||
action='store_true')
|
action='store_true')
|
||||||
|
tag_cmd_parser.add_argument('-p', '--prefix', help="Filter tags by prefix")
|
||||||
|
tag_cmd_parser.add_argument('-c', '--contain', help="Filter tags by contained substring")
|
||||||
|
|
||||||
# 'config' command parser
|
# 'config' command parser
|
||||||
config_cmd_parser = cmdparser.add_parser('config',
|
config_cmd_parser = cmdparser.add_parser('config',
|
||||||
|
|||||||
@ -78,8 +78,3 @@ def print_chat_hist(chat: ChatType, dump: bool = False, source_code: bool = Fals
|
|||||||
print(message['content'])
|
print(message['content'])
|
||||||
else:
|
else:
|
||||||
print(f"{message['role'].upper()}: {message['content']}")
|
print(f"{message['role'].upper()}: {message['content']}")
|
||||||
|
|
||||||
|
|
||||||
def print_tags_frequency(tags: list[str]) -> None:
|
|
||||||
for tag in sorted(set(tags)):
|
|
||||||
print(f"- {tag}: {tags.count(tag)}")
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user