Compare commits
11 Commits
1ebfd0944a
...
3245690d4d
| Author | SHA1 | Date | |
|---|---|---|---|
| 3245690d4d | |||
| 37341ccebe | |||
| 8031271c18 | |||
| 5e392e782e | |||
| 589b92c9b6 | |||
| 3c4f93cc51 | |||
| f01ccb7d36 | |||
| 68aab144ca | |||
| ffcf500acb | |||
| e3e79cf736 | |||
| 1cd52acf2d |
@ -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:
|
||||||
|
|||||||
@ -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 []
|
||||||
|
|
||||||
|
|||||||
@ -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:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user