Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new flag to disable the printing of the welcome message #93

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gptcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ def __exit__(self, *args):


class CLIChatListener(ChatListener):
def __init__(self, markdown: bool):
def __init__(self, markdown: bool, print_welcome: bool):
self.markdown = markdown
self.print_welcome = print_welcome
self.console = Console()

def on_chat_start(self):
console = Console(width=80)
console.print(Markdown(TERMINAL_WELCOME))
if self.print_welcome:
console.print(Markdown(TERMINAL_WELCOME))

def on_chat_clear(self):
self.console.print("[bold]Cleared the conversation.[/bold]")
Expand Down
1 change: 1 addition & 0 deletions gptcli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GptCliConfig:
default_assistant: str = "general"
markdown: bool = True
show_price: bool = True
print_welcome: bool = True
api_key: Optional[str] = os.environ.get("OPENAI_API_KEY")
openai_api_key: Optional[str] = os.environ.get("OPENAI_API_KEY")
openai_base_url: Optional[str] = os.environ.get("OPENAI_BASE_URL")
Expand Down
13 changes: 10 additions & 3 deletions gptcli/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def parse_args(config: GptCliConfig):
help="Disable price logging.",
default=config.show_price,
)
parser.add_argument(
"--no_welcome",
action="store_false",
dest="print_welcome",
help="Deactivate the welcome message being printed to the top of the terminal.",
default=config.print_welcome,
)
parser.add_argument(
"--version",
"-v",
Expand Down Expand Up @@ -230,9 +237,9 @@ def run_non_interactive(args, assistant):


class CLIChatSession(ChatSession):
def __init__(self, assistant: Assistant, markdown: bool, show_price: bool):
def __init__(self, assistant: Assistant, markdown: bool, show_price: bool, print_welcome: bool):
listeners = [
CLIChatListener(markdown),
CLIChatListener(markdown, print_welcome),
LoggingChatListener(),
]

Expand All @@ -246,7 +253,7 @@ def __init__(self, assistant: Assistant, markdown: bool, show_price: bool):
def run_interactive(args, assistant):
logger.info("Starting a new chat session. Assistant config: %s", assistant.config)
session = CLIChatSession(
assistant=assistant, markdown=args.markdown, show_price=args.show_price
assistant=assistant, markdown=args.markdown, show_price=args.show_price, print_welcome=args.print_welcome
)
history_filename = os.path.expanduser("~/.config/gpt-cli/history")
os.makedirs(os.path.dirname(history_filename), exist_ok=True)
Expand Down