moved 'read_config' to storage.py and added 'write_config'
This commit is contained in:
parent
6ed459be6f
commit
f371a6146e
@ -8,7 +8,7 @@ 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, ConfigType
|
from .utils import terminal_width, print_tag_args, print_chat_hist, display_source_code, print_tags_frequency, ConfigType
|
||||||
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, get_tags_unique, read_file, read_config, dump_data
|
||||||
from .api_client import ai, openai_api_key, print_models
|
from .api_client import ai, openai_api_key, print_models
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
|
|
||||||
@ -21,12 +21,6 @@ def tags_completer(prefix, parsed_args, **kwargs):
|
|||||||
return get_tags_unique(config, prefix)
|
return get_tags_unique(config, prefix)
|
||||||
|
|
||||||
|
|
||||||
def read_config(path: str) -> ConfigType:
|
|
||||||
with open(path, 'r') as f:
|
|
||||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
def create_question_with_hist(args: argparse.Namespace,
|
def create_question_with_hist(args: argparse.Namespace,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
) -> tuple[list[dict[str, str]], str, list[str]]:
|
) -> tuple[list[dict[str, str]], str, list[str]]:
|
||||||
|
|||||||
@ -22,6 +22,17 @@ def read_file(fname: pathlib.Path, tags_only: bool = False) -> Dict[str, Any]:
|
|||||||
"file": fname.name}
|
"file": fname.name}
|
||||||
|
|
||||||
|
|
||||||
|
def read_config(path: str) -> ConfigType:
|
||||||
|
with open(path, 'r') as f:
|
||||||
|
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def write_config(path: str, config: ConfigType) -> None:
|
||||||
|
with open(path, 'w') as f:
|
||||||
|
yaml.dump(config, f)
|
||||||
|
|
||||||
|
|
||||||
def dump_data(data: Dict[str, Any]) -> str:
|
def dump_data(data: Dict[str, Any]) -> str:
|
||||||
with io.StringIO() as fd:
|
with io.StringIO() as fd:
|
||||||
fd.write(f'TAGS: {" ".join(data["tags"])}\n')
|
fd.write(f'TAGS: {" ".join(data["tags"])}\n')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user