Skip to content

Commit

Permalink
Better markdown white space
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Dec 31, 2024
1 parent b2ddef8 commit 673fc43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions chatlas/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,11 @@ def export(
is_html = filename.suffix == ".html"

# Get contents from each turn
contents = ""
content_arr: list[str] = []
for turn in turns:
turn_content = "\n\n".join(
[
str(content)
str(content).strip()
for content in turn.contents
if include == "all" or isinstance(content, ContentText)
]
Expand All @@ -963,7 +963,8 @@ def export(
turn_content = f"<shiny-{msg_type}-message content='{content_attr}'></shiny-{msg_type}-message>"
else:
turn_content = f"## {turn.role.capitalize()}\n\n{turn_content}"
contents += f"{turn_content}\n\n"
content_arr.append(turn_content)
contents = "\n\n".join(content_arr)

# Shiny chat message components requires container elements
if is_html:
Expand Down
4 changes: 2 additions & 2 deletions chatlas/_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __str__(self):
args_str = self._arguments_str()
func_call = f"{self.name}({args_str})"
comment = f"# tool request ({self.id})"
return f"\n```python\n{comment}\n{func_call}\n```\n"
return f"```python\n{comment}\n{func_call}\n```\n"

def _repr_markdown_(self):
return self.__str__()
Expand Down Expand Up @@ -246,7 +246,7 @@ def __str__(self):
return json.dumps(self.value, indent=2)

def _repr_markdown_(self):
return f"""\n```json\n{self.__str__()}\n```\n"""
return f"""```json\n{self.__str__()}\n```"""

def __repr__(self, indent: int = 0):
return " " * indent + f"<ContentJson value={self.value}>"

0 comments on commit 673fc43

Please sign in to comment.