1414import subprocess
1515from threading import Thread as thr
1616from functools import wraps
17-
18- # rich
19-
2017from rich .panel import Panel
2118from rich .style import Style
2219from rich .markdown import Markdown
2522from rich .table import Table
2623from rich .prompt import Prompt
2724from rich .progress import Progress
28-
2925from typing import Iterable
30-
31- #pytgpt
32-
3326from pytgpt .utils import Optimizers
3427from pytgpt .utils import default_path
3528from pytgpt .utils import AwesomePrompts
3629from pytgpt .utils import RawDog
3730from pytgpt .imager import Imager
3831from pytgpt .imager import Prodia
3932from pytgpt .utils import Audio
40- from pytgpt .utils import suggest_query
41-
4233from WebChatGPT .console import chat as webchatgpt
43-
44- # colorama
4534from colorama import Fore
4635from colorama import init as init_colorama
47-
4836from dotenv import load_dotenv
4937
50- # prompt-toolkit
51- from prompt_toolkit import PromptSession
52- from prompt_toolkit .completion import ThreadedCompleter , Completer , Completion
53- from prompt_toolkit .document import Document
54-
5538init_colorama (autoreset = True )
5639
5740load_dotenv () # loads .env variables
@@ -346,40 +329,6 @@ def main(*args, **kwargs):
346329
347330 return decorator
348331
349- class CustomCompleter (Completer ):
350- """Suggests query based on user prompts"""
351-
352- def __init__ (
353- self ,
354- caller : object ,
355- suggestions_limit : int = 15 ,
356- special_commands : list [str ] = [],
357- ):
358- self .suggestions_limit = suggestions_limit
359- self .caller = caller
360- self .special_commands = special_commands
361-
362- def get_completions (self , document : Document , complete_event ):
363- word = document .text
364- if word and self .suggestions_limit > 0 and not word .startswith ("./" ):
365- completions = []
366- first_word = word .strip ().split (" " )[0 ]
367- if first_word in self .special_commands :
368- completions .append (
369- Completion (
370- f"{ first_word } [RESERVED] "
371- + getattr (self .caller , f"do_{ first_word } " ).__doc__
372- )
373- )
374- return completions
375- for count , suggestion in enumerate (
376- suggest_query (word , timeout = 10 , die_silently = True ),
377- start = 1 ):
378- completions .append (Completion (suggestion , start_position = - len (word )))
379- if count >= self .suggestions_limit :
380- break
381- return completions
382- return []
383332
384333class Main (cmd .Cmd ):
385334 intro = (
@@ -412,8 +361,6 @@ def __init__(
412361 internal_exec = False ,
413362 confirm_script = False ,
414363 interpreter = "python" ,
415- suggestions_limit = 15 ,
416- non_interactive = False ,
417364 * args ,
418365 ** kwargs ,
419366 ):
@@ -825,22 +772,6 @@ def __init__(
825772 self .read_aloud = False
826773 self .read_aloud_voice = "Brian"
827774 self .path_to_last_response_audio = None
828- if not non_interactive :
829- self .completer_session = PromptSession (
830- "" ,
831- completer = ThreadedCompleter (
832- CustomCompleter (
833- self ,
834- suggestions_limit ,
835- [
836- "cd" , "copy_this" , "h" , "last_response" , "rawdog" ,
837- "settings" , "with_copied" ,
838- "clear" , "exec" , "help" , "load" , "reread" , "shell" ,
839- "code" , "exit" , "history" , "new_intro" , "reset" , "sys" ,
840- ],
841- )
842- ),
843- )
844775 self .__init_time = time .time ()
845776 self .__start_time = time .time ()
846777 self .__end_time = time .time ()
@@ -871,7 +802,7 @@ def find_range(start, end, hms: bool = False):
871802 f"~[`{ Fore .LIGHTWHITE_EX } 🕒{ Fore .BLUE } { current_time } -`"
872803 f"{ Fore .LIGHTWHITE_EX } 💻{ Fore .RED } { find_range (self .__init_time , time .time (), True )} -`"
873804 f"{ Fore .LIGHTWHITE_EX } ⚡{ Fore .YELLOW } { find_range (self .__start_time , self .__end_time )} s]`"
874- # f"\n╰─>"
805+ f"\n ╰─>"
875806 )
876807 whitelist = ["[" , "]" , "~" , "-" , "(" , ")" ]
877808 for character in whitelist :
@@ -884,70 +815,8 @@ def find_range(start, end, hms: bool = False):
884815 f"~[🕒{ current_time } "
885816 f"-💻{ find_range (self .__init_time , time .time (), True )} "
886817 f"-⚡{ find_range (self .__start_time , self .__end_time )} s]"
887- # "\n╰─>"
818+ "\n ╰─>"
888819 )
889- def cmdloop (self , intro = None ):
890- """Repeatedly issue a prompt, accept input, parse an initial prefix
891- off the received input, and dispatch to action methods, passing them
892- the remainder of the line as argument.
893-
894- """
895-
896- self .preloop ()
897- if self .use_rawinput and self .completekey :
898- try :
899- import readline
900-
901- self .old_completer = readline .get_completer ()
902- readline .set_completer (self .complete )
903- if hasattr (readline , "backend" ) and readline .backend == "editline" :
904- if self .completekey == "tab" :
905- # libedit uses "^I" instead of "tab"
906- command_string = "bind ^I rl_complete"
907- else :
908- command_string = f"bind { self .completekey } rl_complete"
909- else :
910- command_string = f"{ self .completekey } : complete"
911- readline .parse_and_bind (command_string )
912- except ImportError :
913- pass
914- try :
915- if intro is not None :
916- self .intro = intro
917- if self .intro :
918- self .stdout .write (str (self .intro ) + "\n " )
919- stop = None
920- while not stop :
921- if self .cmdqueue :
922- line = self .cmdqueue .pop (0 )
923- else :
924- if self .use_rawinput :
925- try :
926- print (self .prompt , end = "" )
927- line = self .completer_session .prompt ("\n ╰─>" )
928- except EOFError :
929- line = "EOF"
930- else :
931- self .stdout .write (self .prompt )
932- self .stdout .flush ()
933- line = self .stdin .readline ()
934- if not len (line ):
935- line = "EOF"
936- else :
937- line = line .rstrip ("\r \n " )
938- line = self .precmd (line )
939- stop = self .onecmd (line )
940- stop = self .postcmd (stop , line )
941- self .postloop ()
942- finally :
943- if self .use_rawinput and self .completekey :
944- try :
945- import readline
946-
947- readline .set_completer (self .old_completer )
948- except ImportError :
949- pass
950-
951820
952821 def output_bond (
953822 self ,
@@ -1375,7 +1244,7 @@ def do_sys(self, line):
13751244 def do_exit (self , line ):
13761245 """Quit this program"""
13771246 if click .confirm ("Are you sure to exit" ):
1378- click .secho ("^-^ Okay Goodbye!" , fg = "yellow" )
1247+ click .secho ("Okay Goodbye!" , fg = "yellow" )
13791248 return True
13801249
13811250
@@ -1553,13 +1422,6 @@ class ChatInteractive:
15531422 "for advanced g4f providers test"
15541423 ),
15551424 )
1556- @click .option (
1557- '-sl' ,
1558- "--suggestions-limit" ,
1559- type = click .INT ,
1560- help = "Prompt suggestions limit - 0 to disable suggestion" ,
1561- default = 15 ,
1562- )
15631425 @click .option (
15641426 "-vo" ,
15651427 "--vertical-overflow" ,
@@ -1668,7 +1530,6 @@ def interactive(
16681530 awesome_prompt ,
16691531 proxy_path ,
16701532 provider ,
1671- suggestions_limit ,
16721533 vertical_overflow ,
16731534 whole ,
16741535 quiet ,
@@ -1709,7 +1570,6 @@ def interactive(
17091570 internal_exec = internal_exec ,
17101571 confirm_script = confirm_script ,
17111572 interpreter = interpreter ,
1712- suggestions_limit = suggestions_limit
17131573 )
17141574 busy_bar .spin_index = busy_bar_index
17151575 bot .code_theme = code_theme
@@ -2009,7 +1869,6 @@ def generate(
20091869 internal_exec = internal_exec ,
20101870 confirm_script = confirm_script ,
20111871 interpreter = interpreter ,
2012- non_interactive = True
20131872 )
20141873 prompt = prompt if prompt else ""
20151874 copied_placeholder = "{{copied}}"
0 commit comments