Merge pull request #2381 from hlohaus/info

Add aliases to gui  arguments, fix logs variable
This commit is contained in:
H Lohaus 2024-11-19 17:26:05 +01:00 committed by GitHub
commit a0f3ea1443
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 9 deletions

View File

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

View File

@ -1060,7 +1060,6 @@ a:-webkit-any-link {
.log {
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 {

View File

@ -2,8 +2,12 @@ from argparse import ArgumentParser
def gui_parser():
parser = ArgumentParser(description="Run the GUI")
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("-debug", action="store_true", help="debug mode")
parser.add_argument("--host", type=str, default="0.0.0.0", help="hostname")
parser.add_argument_alias('-h', '--host')
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.")
return parser

View File

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