refactor: renamed (almost) all Chat/ChatDB functions

This commit is contained in:
2023-09-15 08:41:32 +02:00
parent aae8151a00
commit 378bba6002
5 changed files with 195 additions and 187 deletions
+15 -6
View File
@@ -52,7 +52,8 @@ def add_file_as_code(question_parts: list[str], file: str) -> None:
def create_message(chat: ChatDB, args: argparse.Namespace) -> Message:
"""
Creates (and writes) a new message from the given arguments.
Creates a new message from the given arguments and writes it
to the cache directory.
"""
question_parts = []
question_list = args.ask if args.ask is not None else []
@@ -73,18 +74,26 @@ def create_message(chat: ChatDB, args: argparse.Namespace) -> Message:
tags=args.output_tags, # FIXME
ai=args.AI,
model=args.model)
chat.write_cache([message])
# only write the message (as a backup), don't add it
# to the current chat history
chat.cache_write([message])
return message
def make_request(ai: AI, chat: ChatDB, message: Message, args: argparse.Namespace) -> None:
"""
Make an AI request with the give AI, chat history, message and CLI arguments.
Print all answers.
"""
ai.print()
chat.print(paged=False)
print(message.to_str() + '\n')
response: AIResponse = ai.request(message,
chat,
args.num_answers, # FIXME
args.output_tags) # FIXME
chat.write_cache(response.messages)
args.num_answers,
args.output_tags)
# write all answers to the cache, don't add them to the chat history
chat.cache_write(response.messages)
for idx, msg in enumerate(response.messages):
print(f"=== ANSWER {idx+1} ===")
print(msg.answer)
@@ -117,7 +126,7 @@ def question_cmd(args: argparse.Namespace, config: Config) -> None:
make_request(ai, chat, message, args)
# === REPEAT ===
elif args.repeat is not None:
lmessage = chat.latest_message(source='cache')
lmessage = chat.msg_latest(source='cache')
if lmessage is None:
print("No message found to repeat!")
sys.exit(1)
+1 -1
View File
@@ -11,7 +11,7 @@ def tags_cmd(args: argparse.Namespace, config: Config) -> None:
chat = ChatDB.from_dir(cache_path=Path('.'),
db_path=Path(config.db))
if args.list:
tags_freq = chat.tags_frequency(args.prefix, args.contain)
tags_freq = chat.msg_tags_frequency(args.prefix, args.contain)
for tag, freq in tags_freq.items():
print(f"- {tag}: {freq}")
# TODO: add renaming