mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-15 14:51:19 -08:00
Improve CLI commands
This commit is contained in:
parent
23d4c6eb38
commit
8e6ddfbf47
2 changed files with 15 additions and 12 deletions
|
|
@ -67,19 +67,22 @@ def run_api_args(args):
|
|||
)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Run gpt4free")
|
||||
parser = argparse.ArgumentParser(description="Run gpt4free", exit_on_error=False)
|
||||
subparsers = parser.add_subparsers(dest="mode", help="Mode to run the g4f in.")
|
||||
subparsers.add_parser("api", parents=[get_api_parser()], add_help=False)
|
||||
subparsers.add_parser("gui", parents=[gui_parser()], add_help=False)
|
||||
subparsers.add_parser("client", parents=[get_parser()], add_help=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
if args.mode == "api":
|
||||
run_api_args(args)
|
||||
elif args.mode == "gui":
|
||||
run_gui_args(args)
|
||||
elif args.mode == "client":
|
||||
run_client_args(args)
|
||||
else:
|
||||
parser.print_help()
|
||||
exit(1)
|
||||
try:
|
||||
args = parser.parse_args()
|
||||
if args.mode == "api":
|
||||
run_api_args(args)
|
||||
elif args.mode == "gui":
|
||||
run_gui_args(args)
|
||||
elif args.mode == "client":
|
||||
run_client_args(args)
|
||||
else:
|
||||
parser.print_help()
|
||||
exit(1)
|
||||
except argparse.ArgumentError:
|
||||
run_client_args(get_parser().parse_args())
|
||||
|
|
@ -317,7 +317,7 @@ def run_client_args(args):
|
|||
input_text = (" ".join(args.input[rest:])).strip() + input_text
|
||||
if media:
|
||||
input_text = (media, input_text)
|
||||
if not input_text:
|
||||
if not sys.stdin.isatty() and not input_text:
|
||||
input_text = sys.stdin.read().strip()
|
||||
if not input_text:
|
||||
print("No input provided. Use -h for help.", file=sys.stderr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue