1111
1212
1313def config_aishell ():
14- rich .print ('''Hi! 🙌 I am [bold blue]AiShell[/bold blue], [yellow]your powerful terminal assistant[/yellow] 🔥
14+ rich .print ('''
15+ Hi! 🙌 I am [bold blue]AiShell[/bold blue], [yellow]your powerful terminal assistant[/yellow] 🔥
1516I am here to assist you with configuring AiShell. 💪
1617
1718Please make sure that you have logged into chat.openai.com on your browser before we continue. 🗝️
1819
19- ''' )
20+ ''' [ 1 :] )
2021 typer .confirm ('Are you ready to proceed? 🚀' , abort = True )
2122
22- rich .print (f'''Which browser did you use to log in to chat.openai.com?
23+ rich .print (f'''
24+ Which browser did you use to log in to chat.openai.com?
2325
24- We support the following browsers: [{ SUPPORTED_BROWSERS } ]''' )
26+ We support the following browsers: [{ SUPPORTED_BROWSERS } ]''' [ 1 :] )
2527 browser_name = typer .prompt ('Please enter your choice here: ' )
2628 if browser_name not in SUPPORTED_BROWSERS :
2729 rich .print (f'Browser { browser_name } is not supported. Supported browsers are: { SUPPORTED_BROWSERS } ' )
@@ -33,18 +35,33 @@ def config_aishell():
3335 rich .print ('Failed to get session token. 😓 Can you check if you are logged in to https://chat.openai.com?' )
3436 sys .exit (1 )
3537
36- is_paid = typer . confirm ( "It's my last question! 🤩 Are you a PLUS user?" )
38+ config_manager = save_config ( session_token )
3739
38- chatgpt_config = RevChatGPTChatbotConfigModel (session_token = session_token , paid = is_paid )
39- aishell_config = AiShellConfigModel (chatgpt_config = chatgpt_config )
40- config_manager = AiShellConfigManager (config_model = aishell_config )
41- config_manager .save_config ()
42-
43- rich .print (f'''[green bold]Excellent![/green bold] You are now ready to use [bold blue]AiShell[/bold blue] 🚀
40+ rich .print (f'''
41+ [green bold]Excellent![/green bold] You are now ready to use [bold blue]AiShell[/bold blue] 🚀
4442
4543Enjoy your AI powered terminal assistant! 🎉
4644
4745[dim]To check your settings file, it's at: { config_manager .config_path } [/dim]
4846
49- ''' )
47+ ''' [1 :])
48+ return config_manager
49+
50+
51+ def save_config (session_token : str ):
52+ is_config_file_available = AiShellConfigManager .is_config_file_available (AiShellConfigManager .DEFAULT_CONFIG_PATH )
53+ if is_config_file_available :
54+ config_manager = AiShellConfigManager (load_config = True )
55+ is_chatgpt_config_available = config_manager .config_model .chatgpt_config is not None
56+ if is_chatgpt_config_available :
57+ assert config_manager .config_model .chatgpt_config # for type hinting
58+ config_manager .config_model .chatgpt_config .session_token = session_token
59+ else :
60+ config_manager .config_model .chatgpt_config = RevChatGPTChatbotConfigModel (session_token = session_token )
61+ else :
62+ chatgpt_config = RevChatGPTChatbotConfigModel (session_token = session_token )
63+ aishell_config = AiShellConfigModel (chatgpt_config = chatgpt_config )
64+ config_manager = AiShellConfigManager (config_model = aishell_config )
65+
66+ config_manager .save_config ()
5067 return config_manager
0 commit comments