Compare commits

..

11 Commits

Author SHA1 Message Date
3245690d4d chat: 'msg_gather()' now supports globbing 2023-09-28 07:51:56 +02:00
37341ccebe question: moved around some code 2023-09-28 07:19:00 +02:00
8031271c18 chat: added message file format as ChatDB class member 2023-09-27 08:15:35 +02:00
5e392e782e message: added function 'rm_file()' and test 2023-09-27 08:14:56 +02:00
589b92c9b6 test_question_cmd: modified tests to use '.msg' file suffix 2023-09-26 18:29:23 +02:00
3c4f93cc51 test_chat: added test for file_path collision detection 2023-09-26 18:29:23 +02:00
f01ccb7d36 test_chat: changed all tests to use the new '.msg' suffix 2023-09-26 18:29:23 +02:00
68aab144ca test_message: changed all tests to use the new '.msg' suffix 2023-09-26 18:29:23 +02:00
ffcf500acb message: fixed tag matching for YAML file format 2023-09-26 18:29:23 +02:00
e3e79cf736 chat: switched to new message suffix and formats
- no longer using file suffix to choose the format
- added 'mformat' argument to 'write_xxx()' functions
- file suffix is now set by 'Message.to_file()' per default
2023-09-26 18:29:23 +02:00
1cd52acf2d message: introduced file suffix '.msg'
- '.msg' suffix is always used for writing
- 'Message.to_file()' will set the file suffix if the given file_path has none
- added 'mformat' argument to 'Message.to_file()' for choosing the file format
- '.txt' and '.yaml' suffixes are only supported for reading
2023-09-26 18:29:23 +02:00
3 changed files with 2 additions and 47 deletions

View File

@ -2,26 +2,7 @@ import argparse
from pathlib import Path from pathlib import Path
from ..configuration import Config from ..configuration import Config
from ..chat import ChatDB from ..chat import ChatDB
from ..message import MessageFilter, Message from ..message import MessageFilter
msg_suffix = Message.file_suffix_write
def convert(args: argparse.Namespace, config: Config) -> None:
"""
Convert messages to a new format. Also used to change the suffix,
to the latest default message file suffix.
"""
chat = ChatDB.from_dir(Path(config.cache),
Path(config.db))
# read all known message files
msgs = chat.msg_gather(loc='disk', glob='*.*')
# make a set of all message IDs
# msg_ids = set([m.msg_id() for m in msgs])
# set requested format and write all messages
chat.set_msg_format(args.format)
chat.msg_write(msgs)
def hist_cmd(args: argparse.Namespace, config: Config) -> None: def hist_cmd(args: argparse.Namespace, config: Config) -> None:

View File

@ -10,10 +10,6 @@ from ..ai_factory import create_ai
from ..ai import AI, AIResponse from ..ai import AI, AIResponse
class QuestionCmdError(Exception):
pass
def add_file_as_text(question_parts: list[str], file: str) -> None: def add_file_as_text(question_parts: list[str], file: str) -> None:
""" """
Add the given file as plain text to the question part list. Add the given file as plain text to the question part list.
@ -84,12 +80,7 @@ def create_message(chat: ChatDB, args: argparse.Namespace) -> Message:
to the cache directory. to the cache directory.
""" """
question_parts = [] question_parts = []
if args.create is not None: question_list = args.ask if args.ask is not None else []
question_list = args.create
elif args.ask is not None:
question_list = args.ask
else:
raise QuestionCmdError("No question found")
text_files = args.source_text if args.source_text is not None else [] text_files = args.source_text if args.source_text is not None else []
code_files = args.source_code if args.source_code is not None else [] code_files = args.source_code if args.source_code is not None else []

View File

@ -41,8 +41,6 @@ class TestMessageCreate(TestWithFakeAI):
self.args.AI = None self.args.AI = None
self.args.model = None self.args.model = None
self.args.output_tags = None self.args.output_tags = None
self.args.ask = None
self.args.create = None
# File 1 : no source code block, only text # File 1 : no source code block, only text
self.source_file1 = tempfile.NamedTemporaryFile(delete=False) self.source_file1 = tempfile.NamedTemporaryFile(delete=False)
self.source_file1_content = """This is just text. self.source_file1_content = """This is just text.
@ -206,21 +204,6 @@ It is embedded code
""")) """))
class TestCreateOption(TestMessageCreate):
def test_message_file_created(self) -> None:
self.args.create = ["How does question --create work?"]
self.args.ask = None
cache_dir_files = self.message_list(self.cache_dir)
self.assertEqual(len(cache_dir_files), 0)
create_message(self.chat, self.args)
cache_dir_files = self.message_list(self.cache_dir)
self.assertEqual(len(cache_dir_files), 1)
message = Message.from_file(cache_dir_files[0])
self.assertIsInstance(message, Message)
self.assertEqual(message.question, Question("How does question --create work?")) # type: ignore [union-attr]
class TestQuestionCmd(TestWithFakeAI): class TestQuestionCmd(TestWithFakeAI):
def setUp(self) -> None: def setUp(self) -> None: