mirror of
https://github.com/TheR1D/shell_gpt.git
synced 2026-07-03 14:10:18 +02:00
REPL conversation bug fix and minor improvements (#410)
This commit is contained in:
+1
-1
@@ -87,7 +87,7 @@ def main(
|
||||
show_chat: str = typer.Option(
|
||||
None,
|
||||
help="Show all messages from provided chat id.",
|
||||
callback=ChatHandler.show_messages,
|
||||
callback=ChatHandler.show_messages_callback,
|
||||
rich_help_panel="Chat Options",
|
||||
),
|
||||
list_chats: bool = typer.Option(
|
||||
|
||||
@@ -6,7 +6,7 @@ import typer
|
||||
from click import BadArgumentUsage
|
||||
|
||||
from ..config import cfg
|
||||
from ..role import SystemRole
|
||||
from ..role import DefaultRoles, SystemRole
|
||||
from ..utils import option_callback
|
||||
from .handler import Handler
|
||||
|
||||
@@ -102,15 +102,6 @@ class ChatHandler(Handler):
|
||||
|
||||
self.validate()
|
||||
|
||||
@classmethod
|
||||
def list_ids(cls, value: str) -> None:
|
||||
if not value:
|
||||
return
|
||||
# Prints all existing chat IDs to the console.
|
||||
for chat_id in cls.chat_session.list():
|
||||
typer.echo(chat_id)
|
||||
raise typer.Exit()
|
||||
|
||||
@property
|
||||
def initiated(self) -> bool:
|
||||
return self.chat_session.exists(self.chat_id)
|
||||
@@ -127,21 +118,31 @@ class ChatHandler(Handler):
|
||||
|
||||
@classmethod
|
||||
@option_callback
|
||||
def list_ids(cls, value: str) -> None:
|
||||
# Prints all existing chat IDs to the console.
|
||||
for chat_id in cls.chat_session.list():
|
||||
typer.echo(chat_id)
|
||||
|
||||
@classmethod
|
||||
def show_messages(cls, chat_id: str) -> None:
|
||||
# Prints all messages from a specified chat ID to the console.
|
||||
for index, message in enumerate(cls.chat_session.get_messages(chat_id)):
|
||||
color = "magenta" if index % 2 == 0 else "green"
|
||||
typer.secho(message, fg=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:
|
||||
# print("initial message:", self.initial_message)
|
||||
chat_role_name = self.role.get_role_name(self.initial_message)
|
||||
if not chat_role_name:
|
||||
raise BadArgumentUsage(
|
||||
f'Could not determine chat role of "{self.chat_id}"'
|
||||
)
|
||||
if self.role.name == "default":
|
||||
if self.role.name == DefaultRoles.DEFAULT.value:
|
||||
# If user didn't pass chat mode, we will use the one that was used to initiate the chat.
|
||||
self.role = SystemRole.get(chat_role_name)
|
||||
else:
|
||||
|
||||
+3
-1
@@ -56,7 +56,7 @@ class SystemRole:
|
||||
self.name = name
|
||||
if variables:
|
||||
role = role.format(**variables)
|
||||
self.role = ROLE_TEMPLATE.format(name=name, role=role)
|
||||
self.role = role
|
||||
|
||||
@classmethod
|
||||
def create_defaults(cls) -> None:
|
||||
@@ -143,6 +143,8 @@ class SystemRole:
|
||||
f'Role "{self.name}" already exists, overwrite it?',
|
||||
abort=True,
|
||||
)
|
||||
|
||||
self.role = ROLE_TEMPLATE.format(name=self.name, role=self.role)
|
||||
self._file_path.write_text(json.dumps(self.__dict__), encoding="utf-8")
|
||||
|
||||
def delete(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user