cmm: tags completion now uses 'Message.tags_from_dir' (fixes tag completion for me)
This commit is contained in:
parent
2013c2817d
commit
4d8dbd3f15
@ -6,13 +6,13 @@ import yaml
|
|||||||
import sys
|
import sys
|
||||||
import argcomplete
|
import argcomplete
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
from pathlib import Path
|
||||||
from .utils import terminal_width, print_tag_args, print_chat_hist, display_source_code, 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_unique, read_file, dump_data
|
from .storage import save_answers, create_chat_hist, 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 .chat import ChatDB
|
||||||
from .message import MessageFilter
|
from .message import Message, MessageFilter
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -20,9 +20,8 @@ default_config = '.config.yaml'
|
|||||||
|
|
||||||
|
|
||||||
def tags_completer(prefix: str, parsed_args: Any, **kwargs: Any) -> list[str]:
|
def tags_completer(prefix: str, parsed_args: Any, **kwargs: Any) -> list[str]:
|
||||||
with open(parsed_args.config, 'r') as f:
|
config = Config.from_file(parsed_args.config)
|
||||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
return list(Message.tags_from_dir(Path(config.db), prefix=prefix))
|
||||||
return get_tags_unique(config, prefix)
|
|
||||||
|
|
||||||
|
|
||||||
def create_question_with_hist(args: argparse.Namespace,
|
def create_question_with_hist(args: argparse.Namespace,
|
||||||
@ -65,8 +64,8 @@ def tags_cmd(args: argparse.Namespace, config: Config) -> None:
|
|||||||
"""
|
"""
|
||||||
Handler for the 'tags' command.
|
Handler for the 'tags' command.
|
||||||
"""
|
"""
|
||||||
chat = ChatDB.from_dir(cache_path=pathlib.Path('.'),
|
chat = ChatDB.from_dir(cache_path=Path('.'),
|
||||||
db_path=pathlib.Path(config.db))
|
db_path=Path(config.db))
|
||||||
if args.list:
|
if args.list:
|
||||||
tags_freq = chat.tags_frequency(args.prefix, args.contain)
|
tags_freq = chat.tags_frequency(args.prefix, args.contain)
|
||||||
for tag, freq in tags_freq.items():
|
for tag, freq in tags_freq.items():
|
||||||
@ -128,7 +127,7 @@ def print_cmd(args: argparse.Namespace, config: Config) -> None:
|
|||||||
"""
|
"""
|
||||||
Handler for the 'print' command.
|
Handler for the 'print' command.
|
||||||
"""
|
"""
|
||||||
fname = pathlib.Path(args.file)
|
fname = Path(args.file)
|
||||||
if fname.suffix == '.yaml':
|
if fname.suffix == '.yaml':
|
||||||
with open(args.file, 'r') as f:
|
with open(args.file, 'r') as f:
|
||||||
data = yaml.load(f, Loader=yaml.FullLoader)
|
data = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user