MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / main

Function main

stream/main.py:37–85  ·  view source on GitHub ↗

Main entry point

()

Source from the content-addressed store, hash-verified

35
36
37async def main() -> None:
38 """Main entry point"""
39 args = parse_args()
40
41 # Set up logging with GridFormatter for consistent output
42 set_source("PROXY")
43
44 console_handler = logging.StreamHandler(sys.stderr)
45 console_handler.setFormatter(GridFormatter(show_tree=True, colorize=True))
46 console_handler.setLevel(logging.INFO)
47
48 # Configure proxy_server logger specifically (not root)
49 logger = logging.getLogger("proxy_server")
50 logger.handlers.clear() # Remove any existing handlers
51 logger.addHandler(console_handler)
52 logger.setLevel(logging.INFO)
53 logger.propagate = False # Prevent double logging
54
55 logging.getLogger("asyncio").setLevel(logging.ERROR)
56 logging.getLogger("websockets").setLevel(logging.ERROR)
57
58 # Create certs directory
59 cert_dir = Path("certs")
60 cert_dir.mkdir(exist_ok=True)
61
62 # Print startup information
63 logger.info(f"Starting proxy server on {args.host}:{args.port}")
64 logger.info(f"Intercepting domains: {args.domains}")
65 if args.proxy:
66 logger.info(f"Using upstream proxy: {args.proxy}")
67
68 # Create and start the proxy server
69 proxy_server = ProxyServer(
70 host=args.host,
71 port=args.port,
72 intercept_domains=args.domains,
73 upstream_proxy=args.proxy,
74 queue=None,
75 )
76
77 try:
78 await proxy_server.start()
79 except KeyboardInterrupt:
80 logger.info("Shutting down proxy server")
81 except asyncio.CancelledError:
82 raise
83 except Exception as e:
84 logger.error(f"Error starting proxy server: {e}", exc_info=True)
85 sys.exit(1)
86
87
88async def builtin(

Calls 8

startMethod · 0.95
set_sourceFunction · 0.90
GridFormatterClass · 0.90
ProxyServerClass · 0.90
infoMethod · 0.80
errorMethod · 0.80
parse_argsFunction · 0.70
clearMethod · 0.45