forked from OpenInterpreter/open-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable active line highlighting, export to
md
, allow running from …
…executable Disable active line highlighting, export to `md`, allow running from executable
- Loading branch information
Showing
11 changed files
with
100 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
interpreter/terminal_interface/utils/export_to_markdown.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
def export_to_markdown(messages: list[dict], export_path: str): | ||
markdown = messages_to_markdown(messages) | ||
with open(export_path, 'w') as f: | ||
f.write(markdown) | ||
print(f"Exported current conversation to {export_path}") | ||
|
||
|
||
def messages_to_markdown(messages: list[dict]) -> str: | ||
# Convert interpreter.messages to Markdown text | ||
markdown_content = "" | ||
previous_role = None | ||
for chunk in messages: | ||
current_role = chunk["role"] | ||
if current_role == previous_role: | ||
rendered_chunk = "" | ||
else: | ||
rendered_chunk = f"## {current_role}\n\n" | ||
previous_role = current_role | ||
|
||
# User query message | ||
if chunk["role"] == "user": | ||
rendered_chunk += chunk["content"] + "\n\n" | ||
markdown_content += rendered_chunk | ||
continue | ||
|
||
# Message | ||
if chunk["type"] == "message": | ||
rendered_chunk += chunk["content"] + "\n\n" | ||
|
||
# Code | ||
if chunk["type"] == "code" or chunk["type"] == "console": | ||
code_format = chunk.get("format", "") | ||
rendered_chunk += f"```{code_format}\n{chunk['content']}\n```\n\n" | ||
|
||
markdown_content += rendered_chunk | ||
|
||
return markdown_content |