cli.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import argparse
  2. from enum import Enum
  3. import g4f
  4. from g4f import Provider
  5. from g4f.api import Api
  6. from g4f.gui.run import gui_parser, run_gui_args
  7. def run_gui(args):
  8. print("Running GUI...")
  9. def main():
  10. IgnoredProviders = Enum("ignore_providers", {key: key for key in Provider.__all__})
  11. parser = argparse.ArgumentParser(description="Run gpt4free")
  12. subparsers = parser.add_subparsers(dest="mode", help="Mode to run the g4f in.")
  13. api_parser=subparsers.add_parser("api")
  14. api_parser.add_argument("--bind", default="0.0.0.0:1337", help="The bind string.")
  15. api_parser.add_argument("--debug", type=bool, default=False, help="Enable verbose logging")
  16. api_parser.add_argument("--ignored-providers", nargs="+", choices=[provider.name for provider in IgnoredProviders],
  17. default=[], help="List of providers to ignore when processing request.")
  18. subparsers.add_parser("gui", parents=[gui_parser()], add_help=False)
  19. args = parser.parse_args()
  20. if args.mode == "api":
  21. controller=Api(engine=g4f, debug=args.debug, list_ignored_providers=args.ignored_providers)
  22. controller.run(args.bind)
  23. elif args.mode == "gui":
  24. run_gui_args(args)
  25. else:
  26. parser.print_help()
  27. exit(1)
  28. if __name__ == "__main__":
  29. main()