Skip to content

Commit

Permalink
Merge pull request #2381 from hlohaus/info
Browse files Browse the repository at this point in the history
Add aliases to gui  arguments, fix logs variable
  • Loading branch information
hlohaus authored Nov 19, 2024
2 parents 1563946 + 6e674ca commit a0f3ea1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions g4f/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
last_model: str = None
version: str = None
log_handler: callable = print
logs: list = []

def log(text):
if logging:
Expand Down
1 change: 0 additions & 1 deletion g4f/gui/client/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions g4f/gui/gui_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

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
10 changes: 5 additions & 5 deletions g4f/gui/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def _prepare_conversation_kwargs(self, json_data: dict, kwargs: dict):

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:
Expand Down Expand Up @@ -176,10 +176,10 @@ def log_handler(text: str):
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))
Expand Down

0 comments on commit a0f3ea1

Please sign in to comment.