mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 17:55:01 +00:00
aider: Refactored show_messages
to call format_messages
for formatting title and messages.
# Aider chat conversation: USER: Refactor show_messages in utils, so that the formatting of title and messages is done in a separate function which returns a string. show_messages should call it and print its output. ASSISTANT: To refactor the `show_messages` function, we will: 1. Create a new function `format_messages` that formats the title and messages and returns a string. 2. Update `show_messages` to call `format_messages` and print its output. Here are the *SEARCH/REPLACE* blocks: aider/utils.py ```python <<<<<<< SEARCH def show_messages(messages, title=None, functions=None): if title: print(title.upper(), "*" * 50) for msg in messages: print() role = msg["role"].upper() content = msg.get("content") if isinstance(content, list): # Handle list content (e.g., image messages) for item in content: if isinstance(item, dict) and "image_url" in item: print(role, "Image URL:", item["image_url"]["url"]) elif isinstance(content, str): # Handle string content for line in content.splitlines(): print(role, line) content = msg.get("function_call") if content: print(role, content) if functions: dump(functions) ======= def format_messages(messages, title=None): output = [] if title: output.append(f"{title.upper()} {'*' * 50}") for msg in messages: output.append("") role = msg["role"].upper() content = msg.get("content") if isinstance(content, list): # Handle list content (e.g., image messages) for item in content: if isinstance(item, dict) and "image_url" in item: output.append(f"{role} Image URL: {item['image_url']['url']}") elif isinstance(content, str): # Handle string content for line in content.splitlines(): output.append(f"{role} {line}") content = msg.get("function_call") if content: output.append(f"{role} {content}") return "\n".join(output) def show_messages(messages, title=None, functions=None): formatted_output = format_messages(messages, title) print(formatted_output) if functions: dump(functions) >>>>>>> REPLACE ```
This commit is contained in:
parent
be0520f62f
commit
69c27d6cd1
1 changed files with 14 additions and 6 deletions
|
@ -84,24 +84,32 @@ def safe_abs_path(res):
|
|||
return str(res)
|
||||
|
||||
|
||||
def show_messages(messages, title=None, functions=None):
|
||||
def format_messages(messages, title=None):
|
||||
output = []
|
||||
if title:
|
||||
print(title.upper(), "*" * 50)
|
||||
output.append(f"{title.upper()} {'*' * 50}")
|
||||
|
||||
for msg in messages:
|
||||
print()
|
||||
output.append("")
|
||||
role = msg["role"].upper()
|
||||
content = msg.get("content")
|
||||
if isinstance(content, list): # Handle list content (e.g., image messages)
|
||||
for item in content:
|
||||
if isinstance(item, dict) and "image_url" in item:
|
||||
print(role, "Image URL:", item["image_url"]["url"])
|
||||
output.append(f"{role} Image URL: {item['image_url']['url']}")
|
||||
elif isinstance(content, str): # Handle string content
|
||||
for line in content.splitlines():
|
||||
print(role, line)
|
||||
output.append(f"{role} {line}")
|
||||
content = msg.get("function_call")
|
||||
if content:
|
||||
print(role, content)
|
||||
output.append(f"{role} {content}")
|
||||
|
||||
return "\n".join(output)
|
||||
|
||||
|
||||
def show_messages(messages, title=None, functions=None):
|
||||
formatted_output = format_messages(messages, title)
|
||||
print(formatted_output)
|
||||
|
||||
if functions:
|
||||
dump(functions)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue