3131from WebChatGPT .console import chat as webchatgpt
3232from colorama import Fore
3333from colorama import init as init_colorama
34+ from envist import Envist
3435
3536init_colorama (autoreset = True )
3637
38+ Envist () # loads .env variables
39+
3740logging .basicConfig (
3841 format = "%(asctime)s - %(levelname)s : %(message)s " , # [%(module)s,%(lineno)s]", # for debug purposes
3942 datefmt = "%H:%M:%S" ,
@@ -96,10 +99,18 @@ def run_system_command(
9699 return (False , e )
97100
98101 def g4f_providers_in_dict (
99- url = True , working = True , stream = False , context = False , gpt35 = False , gpt4 = False
102+ url = True ,
103+ working = True ,
104+ stream = False ,
105+ context = False ,
106+ gpt35 = False ,
107+ gpt4 = False ,
108+ selenium = False ,
100109 ):
101110 from pytgpt import g4f
111+ import g4f .Provider .selenium as selenium_based
102112
113+ selenium_based_providers : list = dir (selenium_based )
103114 hunted_providers = []
104115 required_attrs = (
105116 "url" ,
@@ -132,6 +143,13 @@ def sanitize_provider(provider: object):
132143 provider_meta ["gpt35_turbo" ] = provider .supports_gpt_35_turbo
133144 if gpt4 :
134145 provider_meta ["gpt4" ] = provider .supports_gpt_4
146+ if selenium :
147+ try :
148+ selenium_based_providers .index (provider_meta ["name" ])
149+ value = True
150+ except ValueError :
151+ value = False
152+ provider_meta ["non_selenium" ] = value
135153
136154 hunted_providers .append (provider_meta )
137155
@@ -1937,9 +1955,15 @@ def update(extra, log, sudo):
19371955 @click .option (
19381956 "-4" , "--gpt4" , is_flag = True , help = "Restrict to providers supporting gpt4 model"
19391957 )
1958+ @click .option (
1959+ "-se" ,
1960+ "--selenium" ,
1961+ is_flag = True ,
1962+ help = "Restrict to selenium dependent providers" ,
1963+ )
19401964 @click .option ("-j" , "--json" , is_flag = True , help = "Format output in json" )
19411965 @click .help_option ("-h" , "--help" )
1942- def show (target , working , url , stream , context , gpt35 , gpt4 , json ):
1966+ def show (target , working , url , stream , context , gpt35 , gpt4 , selenium , json ):
19431967 """List available models and providers"""
19441968 available_targets = ["models" , "providers" ]
19451969 assert (
@@ -1959,15 +1983,14 @@ def show(target, working, url, stream, context, gpt35, gpt4, json):
19591983 context = context ,
19601984 gpt35 = gpt35 ,
19611985 gpt4 = gpt4 ,
1986+ selenium = selenium ,
19621987 ),
19631988 )
19641989 )
19651990 )
1966- hunted_providers = (
1967- hunted_providers [1 :]
1968- if hunted_providers [0 ] is None
1969- else hunted_providers
1970- )
1991+ while None in hunted_providers :
1992+ hunted_providers .remove (None )
1993+
19711994 hunted_providers .sort ()
19721995 if json :
19731996 rich .print_json (data = dict (providers = hunted_providers ), indent = 4 )
@@ -2020,8 +2043,13 @@ def show(target, working, url, stream, context, gpt35, gpt4, json):
20202043 "llama7b-v2-chat" ,
20212044 ],
20222045 )
2046+ for provider in pytgpt .g4f .Provider .__providers__ :
2047+ if hasattr (provider , "models" ):
2048+ models [provider .__name__ ] = provider .models
20232049 if json :
20242050 for key , value in models .items ():
2051+ while None in value :
2052+ value .remove (None )
20252053 value .sort ()
20262054 models [key ] = value
20272055
@@ -2083,21 +2111,41 @@ def gui(port, address, debug, open):
20832111 help = "Test n amount of providers at once" ,
20842112 default = 5 ,
20852113 )
2086- @click .option ("-q" , "--quiet" , is_flag = True , help = "Suppress all stdout " )
2114+ @click .option ("-q" , "--quiet" , is_flag = True , help = "Suppress progress bar " )
20872115 @click .option (
20882116 "-j" , "--json" , is_flag = True , help = "Stdout test results in json format"
20892117 )
20902118 @click .option ("-d" , "--dry-test" , is_flag = True , help = "Return previous test results" )
20912119 @click .option (
20922120 "-b" , "--best" , is_flag = True , help = "Stdout the fastest provider <name only>"
20932121 )
2122+ @click .option (
2123+ "-se" ,
2124+ "--selenium" ,
2125+ help = "Test even selenium dependent providers" ,
2126+ is_flag = True ,
2127+ )
2128+ @click .option (
2129+ "-dl" ,
2130+ "--disable-logging" ,
2131+ is_flag = True ,
2132+ help = "Disable logging" ,
2133+ )
20942134 @click .option ("-y" , "--yes" , is_flag = True , help = "Okay to all confirmations" )
20952135 @click .help_option ("-h" , "--help" )
2096- def test (timeout , thread , quiet , json , dry_test , best , yes ):
2136+ def test (
2137+ timeout , thread , quiet , json , dry_test , best , selenium , disable_logging , yes
2138+ ):
20972139 """Test and save working providers"""
20982140 from pytgpt .gpt4free import utils
20992141
2100- test = utils .TestProviders (test_at_once = thread , quiet = quiet , timeout = timeout )
2142+ test = utils .TestProviders (
2143+ test_at_once = thread ,
2144+ quiet = quiet ,
2145+ timeout = timeout ,
2146+ selenium = selenium ,
2147+ do_log = disable_logging == False ,
2148+ )
21012149 if best :
21022150 click .secho (test .best )
21032151 return
0 commit comments