Skip to content

Commit

Permalink
Fix --show-chat and --repl to respect --no-md (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lnx authored Feb 17, 2025
1 parent 9bd9420 commit 8fbd94f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ sgpt --role json_generator "random: user, password, email, address"
}
```

If the description of the role contains the words "APPLY MARKDOWN" (case sensitive), then chats will be displayed using markdown formatting.
If the description of the role contains the words "APPLY MARKDOWN" (case sensitive), then chats will be displayed using markdown formatting unless it is explicitly turned off with `--no-md`.

### Request cache
Control cache using `--cache` (default) and `--no-cache` options. This caching applies for all `sgpt` requests to OpenAI API:
Expand Down
4 changes: 3 additions & 1 deletion sgpt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def main(
show_chat: str = typer.Option(
None,
help="Show all messages from provided chat id.",
callback=ChatHandler.show_messages_callback,
rich_help_panel="Chat Options",
),
list_chats: bool = typer.Option(
Expand Down Expand Up @@ -183,6 +182,9 @@ def main(
# Non-interactive shell.
pass

if show_chat:
ChatHandler.show_messages(show_chat, md)

if sum((shell, describe_shell, code)) > 1:
raise BadArgumentUsage(
"Only one of --shell, --describe-shell, and --code options can be used at a time."
Expand Down
9 changes: 2 additions & 7 deletions sgpt/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def list_ids(cls, value: str) -> None:
typer.echo(chat_id)

@classmethod
def show_messages(cls, chat_id: str) -> None:
def show_messages(cls, chat_id: str, markdown: bool) -> None:
color = cfg.get("DEFAULT_COLOR")
if "APPLY MARKDOWN" in cls.initial_message(chat_id):
if "APPLY MARKDOWN" in cls.initial_message(chat_id) and markdown:
theme = cfg.get("CODE_THEME")
for message in cls.chat_session.get_messages(chat_id):
if message.startswith("assistant:"):
Expand All @@ -143,11 +143,6 @@ def show_messages(cls, chat_id: str) -> None:
running_color = color if index % 2 == 0 else "green"
typer.secho(message, fg=running_color)

@classmethod
@option_callback
def show_messages_callback(cls, chat_id: str) -> None:
cls.show_messages(chat_id)

def validate(self) -> None:
if self.initiated:
chat_role_name = self.role.get_role_name(self.initial_message(self.chat_id))
Expand Down
2 changes: 1 addition & 1 deletion sgpt/handlers/repl_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _get_multiline_input(cls) -> str:
def handle(self, init_prompt: str, **kwargs: Any) -> None: # type: ignore
if self.initiated:
rich_print(Rule(title="Chat History", style="bold magenta"))
self.show_messages(self.chat_id)
self.show_messages(self.chat_id, self.markdown)
rich_print(Rule(style="bold magenta"))

info_message = (
Expand Down
2 changes: 1 addition & 1 deletion tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_show_chat_no_use_markdown(completion, console_print):
assert result.exit_code == 0
assert chat_path.exists()

result = runner.invoke(app, ["--show-chat", chat_name])
result = runner.invoke(app, ["--show-chat", chat_name, "--no-md"])
assert result.exit_code == 0
console_print.assert_not_called()

Expand Down

0 comments on commit 8fbd94f

Please sign in to comment.