XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Update __init__.py

ba898176
H Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +67 -0
Modified g4f/cli/__init__.py +67 -0
@@ -0,0 +1,67 @@
1 from __future__ import annotations
2
3 import argparse
4 from argparse import ArgumentParser
5 from .client import get_parser, run_client_args
6
7 from g4f import Provider
8 from g4f.gui.run import gui_parser, run_gui_args
9 import g4f.cookies
10
11 def get_api_parser():
12 api_parser = ArgumentParser(description="Run the API and GUI")
13 api_parser.add_argument("--bind", default=None, help="The bind string. (Default: 0.0.0.0:1337)")
14 api_parser.add_argument("--port", "-p", default=None, help="Change the port of the server.")
15 api_parser.add_argument("--debug", "-d", action="store_true", help="Enable verbose logging.")
16 api_parser.add_argument("--gui", "-g", default=None, action="store_true", help="Start also the gui.")
17 api_parser.add_argument("--model", default=None, help="Default model for chat completion. (incompatible with --reload and --workers)")
18 api_parser.add_argument("--provider", choices=[provider.__name__ for provider in Provider.__providers__ if provider.working],
19 default=None, help="Default provider for chat completion. (incompatible with --reload and --workers)")
20 api_parser.add_argument("--media-provider", choices=[provider.__name__ for provider in Provider.__providers__ if provider.working and bool(getattr(provider, "image_models", False))],
21 default=None, help="Default provider for image generation. (incompatible with --reload and --workers)"),
22 api_parser.add_argument("--proxy", default=None, help="Default used proxy. (incompatible with --reload and --workers)")
23 api_parser.add_argument("--workers", type=int, default=None, help="Number of workers.")
24 api_parser.add_argument("--disable-colors", action="store_true", help="Don't use colors.")
25 api_parser.add_argument("--ignore-cookie-files", action="store_true", help="Don't read .har and cookie files. (incompatible with --reload and --workers)")
26 api_parser.add_argument("--g4f-api-key", type=str, default=None, help="Sets an authentication key for your API. (incompatible with --reload and --workers)")
27 api_parser.add_argument("--ignored-providers", nargs="+", choices=[provider.__name__ for provider in Provider.__providers__ if provider.working],
28 default=[], help="List of providers to ignore when processing request. (incompatible with --reload and --workers)")
29 api_parser.add_argument("--cookie-browsers", nargs="+", choices=[browser.__name__ for browser in g4f.cookies.browsers],
30 default=[], help="List of browsers to access or retrieve cookies from. (incompatible with --reload and --workers)")
31 api_parser.add_argument("--reload", action="store_true", help="Enable reloading.")
32 api_parser.add_argument("--demo", action="store_true", help="Enable demo mode.")
33 api_parser.add_argument("--timeout", type=int, default=600, help="Default timeout for requests in seconds. (incompatible with --reload and --workers)")
34 api_parser.add_argument("--ssl-keyfile", type=str, default=None, help="Path to SSL key file for HTTPS.")
35 api_parser.add_argument("--ssl-certfile", type=str, default=None, help="Path to SSL certificate file for HTTPS.")
36 api_parser.add_argument("--log-config", type=str, default=None, help="Custom log config.")
37
38 return api_parser
39
40 def run_api_args(args):
41 from g4f.api import AppConfig, run_api
42
43 AppConfig.set_config(
44 ignore_cookie_files=args.ignore_cookie_files,
45 ignored_providers=args.ignored_providers,
46 g4f_api_key=args.g4f_api_key,
47 provider=args.provider,
48 media_provider=args.media_provider,
49 proxy=args.proxy,
50 model=args.model,
51 gui=args.gui,
52 demo=args.demo,
53 timeout=args.timeout,
54 )
55 if args.cookie_browsers:
56 g4f.cookies.browsers = [g4f.cookies[browser] for browser in args.cookie_browsers]
57 run_api(
58 bind=args.bind,
59 port=args.port,
60 debug=args.debug,
61 workers=args.workers,
62 use_colors=not args.disable_colors,
63 reload=args.reload,
64 ssl_keyfile=args.ssl_keyfile,
65 ssl_certfile=args.ssl_certfile,
66 log_config=args.log_config,
67 )