Add aliases to gui arguments, fix logs variable

This commit is contained in:
Heiner Lohaus 2024-11-19 17:25:40 +01:00
parent 8f3fbee0d8
commit 6e674ca33d
4 changed files with 13 additions and 9 deletions

View File

@ -6,6 +6,7 @@ last_provider: ProviderType = None
last_model: str = None last_model: str = None
version: str = None version: str = None
log_handler: callable = print log_handler: callable = print
logs: list = []
def log(text): def log(text):
if logging: if logging:

View File

@ -1060,7 +1060,6 @@ a:-webkit-any-link {
.log { .log {
white-space: pre-wrap; white-space: pre-wrap;
font-family: Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace;
} }
.log.hidden { .log.hidden {

View File

@ -2,8 +2,12 @@ from argparse import ArgumentParser
def gui_parser(): def gui_parser():
parser = ArgumentParser(description="Run the GUI") parser = ArgumentParser(description="Run the GUI")
parser.add_argument("-host", type=str, default="0.0.0.0", help="hostname") parser.add_argument("--host", type=str, default="0.0.0.0", help="hostname")
parser.add_argument("-port", type=int, default=8080, help="port") parser.add_argument_alias('-h', '--host')
parser.add_argument("-debug", action="store_true", help="debug mode") parser.add_argument("--port", type=int, default=8080, help="port")
parser.add_argument_alias('-p', '--port')
parser.add_argument("--debug", action="store_true", help="debug mode")
parser.add_argument_alias('-d', '--debug')
parser.add_argument_alias('-debug', '--debug')
parser.add_argument("--ignore-cookie-files", action="store_true", help="Don't read .har and cookie files.") parser.add_argument("--ignore-cookie-files", action="store_true", help="Don't read .har and cookie files.")
return parser return parser

View File

@ -142,10 +142,10 @@ class Api:
def _create_response_stream(self, kwargs: dict, conversation_id: str, provider: str) -> Iterator: def _create_response_stream(self, kwargs: dict, conversation_id: str, provider: str) -> Iterator:
if debug.logging: if debug.logging:
logs = [] debug.logs = []
print_callback = debug.log_handler print_callback = debug.log_handler
def log_handler(text: str): def log_handler(text: str):
logs.append(text) debug.logs.append(text)
print_callback(text) print_callback(text)
debug.log_handler = log_handler debug.log_handler = log_handler
try: try:
@ -176,10 +176,10 @@ class Api:
yield self._format_json("content", str(ImageResponse(images, chunk.alt))) yield self._format_json("content", str(ImageResponse(images, chunk.alt)))
elif not isinstance(chunk, FinishReason): elif not isinstance(chunk, FinishReason):
yield self._format_json("content", str(chunk)) yield self._format_json("content", str(chunk))
if logs: if debug.logs:
for log in logs: for log in debug.logs:
yield self._format_json("log", str(log)) yield self._format_json("log", str(log))
logs = [] debug.logs = []
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
yield self._format_json('error', get_error_message(e)) yield self._format_json('error', get_error_message(e))