Skip to content

Commit 93bc179

Browse files
authored
Merge pull request #56 from code-yeongyu/feature/big-fucking-changes
AiShell 2.0
2 parents 1111fdf + dcf1c49 commit 93bc179

32 files changed

+318
-988
lines changed

aishell/adapters/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

aishell/adapters/openai_cookie_adapter.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

aishell/adapters/test/__init__.py

Whitespace-only changes.

aishell/adapters/test/test_openai_chatgpt_adapter.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

aishell/cli/aishell.py

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
import time
33
from typing import Optional
44

5-
import rich
65
import typer
76
from rich.console import Console
7+
from ygka.models import LanguageModel
8+
from ygka.query_clients import QueryClientFactory
9+
from ygka.utils import YGKAConfigManager
810

9-
from aishell.models import AiShellConfigModel
10-
from aishell.models.language_model import LanguageModel
11-
from aishell.query_clients import GPT3Client, OfficialChatGPTClient, ReverseEngineeredChatGPTClient
12-
from aishell.utils import AiShellConfigManager
11+
from aishell.utils import construct_prompt
1312

1413
from .cli_app import cli_app
1514
from .config_aishell import config_aishell
@@ -20,53 +19,29 @@ def aishell_command(question: str, language_model: Optional[LanguageModel] = Non
2019
config_manager = _get_config_manager()
2120
config_manager.config_model.language_model = language_model or config_manager.config_model.language_model
2221

23-
query_client = _get_query_client(
24-
language_model=config_manager.config_model.language_model,
25-
config_model=config_manager.config_model,
26-
)
22+
query_client = QueryClientFactory(config_model=config_manager.config_model).create()
2723

2824
console = Console()
2925

30-
try:
31-
with console.status(f'''
26+
with console.status(f'''
3227
[green] AiShell is thinking of `{question}` ...[/green]
3328
3429
[dim]AiShell is not responsible for any damage caused by the command executed by the user.[/dim]'''[1:]):
35-
start_time = time.time()
36-
response = query_client.query(question)
37-
end_time = time.time()
30+
start_time = time.time()
31+
response = query_client.query(construct_prompt(question))
32+
end_time = time.time()
3833

39-
execution_time = end_time - start_time
40-
console.print(f'AiShell: {response}\n\n[dim]Took {execution_time:.2f} seconds to think the command.[/dim]')
34+
execution_time = end_time - start_time
35+
console.print(f'AiShell: {response}\n\n[dim]Took {execution_time:.2f} seconds to think the command.[/dim]')
4136

42-
will_execute = typer.confirm('Execute this command?')
43-
if will_execute:
44-
os.system(response)
45-
except KeyError:
46-
rich.print('It looks like the `session_token` is expired. Please reconfigure AiShell.')
47-
typer.confirm('Reconfigure AiShell?', abort=True)
48-
config_aishell()
49-
aishell_command(question=question, language_model=language_model)
50-
typer.Exit()
37+
will_execute = typer.confirm('Execute this command?')
38+
if will_execute:
39+
os.system(response)
5140

5241

5342
def _get_config_manager():
54-
is_config_file_available = AiShellConfigManager.is_config_file_available(AiShellConfigManager.DEFAULT_CONFIG_PATH)
43+
is_config_file_available = YGKAConfigManager.is_config_file_available(YGKAConfigManager.DEFAULT_CONFIG_PATH)
5544
if is_config_file_available:
56-
return AiShellConfigManager(load_config=True)
45+
return YGKAConfigManager(load_config=True)
5746
else:
5847
return config_aishell()
59-
60-
61-
def _get_query_client(language_model: LanguageModel, config_model: AiShellConfigModel):
62-
if language_model == LanguageModel.REVERSE_ENGINEERED_CHATGPT:
63-
return ReverseEngineeredChatGPTClient(config=config_model.chatgpt_config)
64-
65-
if not config_model.openai_api_key:
66-
raise RuntimeError('OpenAI API key is not provided. Please provide it in the config file.')
67-
68-
if language_model == LanguageModel.GPT3:
69-
return GPT3Client(openai_api_key=config_model.openai_api_key)
70-
if language_model == LanguageModel.OFFICIAL_CHATGPT:
71-
return OfficialChatGPTClient(openai_api_key=config_model.openai_api_key)
72-
raise NotImplementedError(f'Language model {language_model} is not implemented yet.')

aishell/cli/config_aishell.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import rich
44
import typer
5-
from yt_dlp.cookies import SUPPORTED_BROWSERS
6-
7-
from aishell.adapters.openai_cookie_adapter import OpenAICookieAdapter
8-
from aishell.models import RevChatGPTChatbotConfigModel
9-
from aishell.models.aishell_config_model import AiShellConfigModel
10-
from aishell.utils import AiShellConfigManager
5+
from revChatGPTAuth import SupportedBrowser
6+
from ygka.cli.config_ygka import save_config
117

128

139
def config_aishell():
10+
SUPPORTED_BROWSERS = [browser.value for browser in SupportedBrowser]
1411
rich.print('''
1512
Hi! 🙌 I am [bold blue]AiShell[/bold blue], [yellow]your powerful terminal assistant[/yellow] 🔥
1613
I am here to assist you with configuring AiShell. 💪
@@ -29,13 +26,7 @@ def config_aishell():
2926
rich.print(f'Browser {browser_name} is not supported. Supported browsers are: {SUPPORTED_BROWSERS}')
3027
sys.exit(1)
3128

32-
adapter = OpenAICookieAdapter(browser_name)
33-
session_token = adapter.get_openai_session_token()
34-
if not session_token:
35-
rich.print('Failed to get session token. 😓 Can you check if you are logged in to https://chat.openai.com?')
36-
sys.exit(1)
37-
38-
config_manager = save_config(session_token)
29+
config_manager = save_config(browser_name=browser_name)
3930

4031
rich.print(f'''
4132
[green bold]Excellent![/green bold] You are now ready to use [bold blue]AiShell[/bold blue] 🚀
@@ -46,22 +37,3 @@ def config_aishell():
4637
4738
'''[1:])
4839
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()
67-
return config_manager

aishell/cli/test/__init__.py

Whitespace-only changes.

aishell/cli/test/test_config_aishell.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

aishell/exceptions/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

aishell/exceptions/unauthorized_access_error.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

aishell/models/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

aishell/models/aishell_config_model.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

aishell/models/language_model.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

aishell/models/open_ai_response_model.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

aishell/models/revchatgpt_chatbot_config_model.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

aishell/models/str_enum.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

aishell/query_clients/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)