Skip to content

Commit

Permalink
- Control vertical overflow *-vo/--vertical-overflow*
Browse files Browse the repository at this point in the history
- Check program version *--version/-v*
- Fully disable busy bar *-B 0*
  • Loading branch information
Simatwa committed Jan 13, 2024
1 parent ff25586 commit 8ef304c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 31 deletions.
2 changes: 1 addition & 1 deletion WebChatGPT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__all__ = ["ChatGPT"]

__version__ = "0.2.5"
__version__ = "0.2.6"
__author__ = "Smartwa"
__repo__ = "https://github.com/Simatwa/WebChatGPT"
__info__ = "Reverse Engineering of ChatGPT Web-version."
88 changes: 61 additions & 27 deletions WebChatGPT/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def stream_output(
title_generator: object = None,
title_generator_params: dict = {},
code_theme: str = "monokai",
frame: bool = False,
vertical_overflow: str = "ellipsis",
) -> None:
"""Stdout streaming response
Expand All @@ -68,14 +68,14 @@ def stream_output(
title_generator (object, optional): Function for generating title. Defaults to None.
title_generator_params (dict, optional): Kwargs for `title_generator` function. Defaults to {}.
code_theme (str, optional): Theme for styling codes. Defaults to `monokai`
frame (bool, optional): Flag for response-framing
vertical_overflow (str, optional): Response rendering vertical overflow behavior. Defaults to ellipsis.
"""
render_this = ""
with Live(
render_this,
transient=transient,
refresh_per_second=16,
vertical_overflow="visible",
vertical_overflow=vertical_overflow,
) as live:
for entry in iterable:
render_this += entry
Expand Down Expand Up @@ -106,7 +106,7 @@ def stream_console_output(
title_generator: object = None,
title_generator_params: dict = {},
code_theme: str = "monokai",
frame: bool = False,
vertical_overflow: str = "ellipsis",
) -> None:
"""Stdout streaming response without frame
Expand All @@ -119,14 +119,14 @@ def stream_console_output(
title_generator (object, optional): Function for generating title. Defaults to None.
title_generator_params (dict, optional): Kwargs for `title_generator` function. Defaults to {}.
code_theme (str, optional): Theme for styling codes. Defaults to `monokai`
frame (bool, optional): Flag for response-framing
vertical_overflow (str, optional): Response rendering vertical overflow behavior. Defaults to ellipsis.
"""
console = Console(style=style)
with Live(
console=console,
transient=transient,
refresh_per_second=16,
vertical_overflow="visible",
vertical_overflow=vertical_overflow,
) as live:
for entry in iterable:
live.update(
Expand All @@ -137,6 +137,7 @@ def stream_console_output(
class busy_bar:
querying = None
__spinner = (
(),
("-", "\\", "|", "/"),
(
"█■■■■",
Expand Down Expand Up @@ -233,6 +234,7 @@ def __init__(self, cookie_path, model, index, timeout, *args, **kwargs):
self.show_title = False
self.code_theme = "monokai"
self.quiet = False
self.vertical_overflow = "ellipsis"

def output_bond(
self,
Expand Down Expand Up @@ -681,6 +683,7 @@ def default(self, line):
),
title_generator=self.generate_title if self.show_title else None,
code_theme=self.code_theme,
vertical_overflow=self.vertical_overflow,
)
"""
if self.prettify:
Expand Down Expand Up @@ -739,8 +742,8 @@ def chat():
@click.option(
"-B",
"--busy-bar-index",
help="Busy bar index [0:/, 1:■█■■■, 2:⣻]",
type=click.IntRange(0, 2),
help="Busy bar index [0: None, 1:/, 2:■█■■■, 3:⣻]",
type=click.IntRange(0, 3),
default=1,
envvar="busy_bar_index",
)
Expand All @@ -754,6 +757,14 @@ def chat():
@click.option(
"-c", "--color", default=None, help="Font color for printing the contents"
)
@click.option(
"-vo",
"--vertical-overflow",
envvar="vertical_overflow",
help="Vertical overflow behaviour on content display",
type=click.Choice(["visible", "crop", "ellipsis"]),
default="ellipsis",
)
@click.option(
"-q",
"--quiet",
Expand All @@ -775,12 +786,12 @@ def interactive(
busy_bar_index,
code_theme,
color,
vertical_overflow,
quiet,
prettify,
show_title,
):
"""Chat with ChatGPT interactively"""
assert isinstance(busy_bar_index, int), "Index must be an integer only"
rich.print(
Panel(
f"""
Expand All @@ -801,6 +812,7 @@ def interactive(
bot.show_title = show_title
bot.code_theme = code_theme
bot.quiet = quiet
bot.vertical_overflow = vertical_overflow
if prompt:
bot.default(prompt)
bot.cmdloop()
Expand Down Expand Up @@ -843,6 +855,22 @@ def interactive(
@click.option(
"-c", "--color", default=None, help="Font color for printing the contents"
)
@click.option(
"-B",
"--busy-bar-index",
help="Busy bar index [0: None, 1:/, 2:■█■■■, 3:⣻]",
type=click.IntRange(0, 3),
default=1,
envvar="busy_bar_index",
)
@click.option(
"-vo",
"--vertical-overflow",
envvar="vertical_overflow",
help="Vertical overflow behaviour on content display",
type=click.Choice(["visible", "crop", "ellipsis"]),
default="ellipsis",
)
@click.option(
"-q",
"--quiet",
Expand All @@ -853,33 +881,39 @@ def interactive(
)
@click.option("--prettify/--raw", default=True, help="Prettify the markdowned response")
def generate(
cookie_path, model, index, timeout, prompt, code_theme, color, quiet, prettify
cookie_path,
model,
index,
timeout,
prompt,
code_theme,
color,
busy_bar_index,
vertical_overflow,
quiet,
prettify,
):
"""Generate a quick response with ChatGPT (Default)"""

bot = ChatGPT(cookie_path, model, index, timeout=timeout)
content = bot.chat(
prompt,
stream=True,
)
stdout_handler = stream_console_output if quiet else stream_output
stdout_handler(
content,
title="ChatGPT Quick Response",
is_markdown=prettify,
style=Style(
frame=False,
color=color,
),
code_theme=code_theme,
)
# bot = ChatGPT(cookie_path, model, index, timeout=timeout)
busy_bar.spin_index = busy_bar_index
bot = InteractiveChatGPT(cookie_path, model, index, timeout)
bot.prettify = prettify
bot.color = color
bot.code_theme = code_theme
bot.quiet = quiet
bot.vertical_overflow = vertical_overflow
bot.default(prompt)


@error_handler(exit_on_error=True)
def main():
dotenv.load_dotenv(os.path.join(os.getcwd(), ".env"))
args = sys.argv
if (
if len(args) > 1 and args[1] in ("-v", "--version"):
print(f"webchatgpt {__version__}")
sys.exit(0)
elif (
len(args) > 1
and args[1] not in ["generate", "interactive"]
and not "--help" in args
Expand Down
10 changes: 9 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,12 @@ More console chat manipulation features.
## v0.2.5

**What's new?**
- Visible vertical overflow
- Visible vertical overflow

## v0.2.6

**What's new?**

- Control vertical overflow *-vo/--vertical-overflow*
- Check program version *--version/-v*
- Fully disable busy bar *-B 0*
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p align="center">
<a href="https://github.com/Simatwa/WebChatGPT/actions/workflows/python-test.yml"><img src="https://github.com/Simatwa/WebChatGPT/actions/workflows/python-test.yml/badge.svg" alt="Python Test"/></a>
<a href="LICENSE"><img alt="License" src="https://img.shields.io/static/v1?logo=GPL&color=Blue&message=GNUv3&label=License"/></a>
<a href="https://pypi.org/project/webchatgpt"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=v0.2.5&color=green"/></a>
<a href="https://pypi.org/project/webchatgpt"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=v0.2.6&color=green"/></a>
<a href="https://github.com/psf/black"><img alt="Black" src="https://img.shields.io/static/v1?logo=Black&label=Code-style&message=Black"/></a>
<a href="#"><img alt="Passing" src="https://img.shields.io/static/v1?logo=Docs&label=Docs&message=Passing&color=green"/></a>
<a href="#"><img alt="coverage" src="https://img.shields.io/static/v1?logo=Coverage&label=Coverage&message=90%&color=yellowgreen"/></a>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="webchatgpt",
version="0.2.5",
version="0.2.6",
license="GNU v3",
author="Smartwa",
maintainer="Smartwa",
Expand Down

0 comments on commit 8ef304c

Please sign in to comment.