mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
refac utils.split_chat_history_markdown
This commit is contained in:
parent
9fac20e432
commit
602a0c7c31
3 changed files with 30 additions and 29 deletions
|
@ -299,7 +299,7 @@ class Coder:
|
||||||
if not self.done_messages:
|
if not self.done_messages:
|
||||||
history_md = self.io.read_text(self.io.chat_history_file)
|
history_md = self.io.read_text(self.io.chat_history_file)
|
||||||
if history_md:
|
if history_md:
|
||||||
self.done_messages = self.summarizer.split_chat_history_markdown(history_md)
|
self.done_messages = utils.split_chat_history_markdown(history_md)
|
||||||
self.summarize_start()
|
self.summarize_start()
|
||||||
|
|
||||||
# validate the functions jsonschema
|
# validate the functions jsonschema
|
||||||
|
|
|
@ -104,34 +104,6 @@ class ChatSummary:
|
||||||
|
|
||||||
return [dict(role="user", content=summary)]
|
return [dict(role="user", content=summary)]
|
||||||
|
|
||||||
def split_chat_history_markdown(self, text):
|
|
||||||
messages = []
|
|
||||||
assistant = []
|
|
||||||
lines = text.splitlines(keepends=True)
|
|
||||||
for line in lines:
|
|
||||||
if line.startswith("# "):
|
|
||||||
continue
|
|
||||||
if line.startswith(">"):
|
|
||||||
continue
|
|
||||||
if line.startswith("#### /"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if line.startswith("#### "):
|
|
||||||
if assistant:
|
|
||||||
assistant = "".join(assistant)
|
|
||||||
if assistant.strip():
|
|
||||||
messages.append(dict(role="assistant", content=assistant))
|
|
||||||
assistant = []
|
|
||||||
|
|
||||||
content = line[5:]
|
|
||||||
if content.strip() and content.strip() != "<blank>":
|
|
||||||
messages.append(dict(role="user", content=line[5:]))
|
|
||||||
continue
|
|
||||||
|
|
||||||
assistant.append(line)
|
|
||||||
|
|
||||||
return messages
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
|
@ -105,3 +105,32 @@ def show_messages(messages, title=None, functions=None):
|
||||||
|
|
||||||
if functions:
|
if functions:
|
||||||
dump(functions)
|
dump(functions)
|
||||||
|
|
||||||
|
|
||||||
|
def split_chat_history_markdown(text):
|
||||||
|
messages = []
|
||||||
|
assistant = []
|
||||||
|
lines = text.splitlines(keepends=True)
|
||||||
|
for line in lines:
|
||||||
|
if line.startswith("# "):
|
||||||
|
continue
|
||||||
|
if line.startswith(">"):
|
||||||
|
continue
|
||||||
|
if line.startswith("#### /"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if line.startswith("#### "):
|
||||||
|
if assistant:
|
||||||
|
assistant = "".join(assistant)
|
||||||
|
if assistant.strip():
|
||||||
|
messages.append(dict(role="assistant", content=assistant))
|
||||||
|
assistant = []
|
||||||
|
|
||||||
|
content = line[5:]
|
||||||
|
if content.strip() and content.strip() != "<blank>":
|
||||||
|
messages.append(dict(role="user", content=line[5:]))
|
||||||
|
continue
|
||||||
|
|
||||||
|
assistant.append(line)
|
||||||
|
|
||||||
|
return messages
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue