Skip to content

Commit 7857790

Browse files
authored
Merge pull request #18 from code-yeongyu/feature/replace-yt-dlp
2 parents e9dce9f + 837ffd1 commit 7857790

File tree

10 files changed

+104
-325
lines changed

10 files changed

+104
-325
lines changed

poetry.lock

Lines changed: 76 additions & 239 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typer = { extras = ["all"], version = "^0.7.0" }
4949
rich = "<13.0.0"
5050
revchatgpt = "^4.2.2"
5151
pydantic = "^1.10.7"
52-
yt-dlp = "^2023.3.4"
52+
revchatgptauth = "^2023.4.16"
5353

5454
[tool.poetry.scripts]
5555
ygka = "ygka:main"

ygka/adapters/__init__.py

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

ygka/adapters/openai_cookie_adapter.py

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

ygka/adapters/test/test_openai_cookie_adapter.py

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

ygka/cli/config_ygka.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
import rich
44
import typer
5-
from yt_dlp.cookies import SUPPORTED_BROWSERS
5+
from revChatGPTAuth import SupportedBrowser
66

7-
from ygka.adapters.openai_cookie_adapter import OpenAICookieAdapter
8-
from ygka.models import RevChatGPTChatbotConfigModel
97
from ygka.models.ygka_config_model import YGKAConfigModel
108
from ygka.utils import YGKAConfigManager
119

1210

1311
def config_ygka():
12+
SUPPORTED_BROWSERS = [browser.value for browser in SupportedBrowser]
1413
rich.print('''
1514
Hi! 🙌 I am [bold blue]YGKA[/bold blue]!
1615
[yellow][blue bold underline]Y[/blue bold underline]our
@@ -33,13 +32,7 @@ def config_ygka():
3332
rich.print(f'Browser {browser_name} is not supported. Supported browsers are: {SUPPORTED_BROWSERS}')
3433
sys.exit(1)
3534

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

4437
rich.print(f'''
4538
[green bold]Excellent![/green bold] You are now ready to use [bold blue]YGKA[/bold blue] 🚀
@@ -52,19 +45,15 @@ def config_ygka():
5245
return config_manager
5346

5447

55-
def save_config(session_token: str):
48+
def save_config(browser_name: str):
49+
config_manager: YGKAConfigManager = YGKAConfigManager()
50+
5651
is_config_file_available = YGKAConfigManager.is_config_file_available(YGKAConfigManager.DEFAULT_CONFIG_PATH)
5752
if is_config_file_available:
5853
config_manager = YGKAConfigManager(load_config=True)
59-
is_chatgpt_config_available = config_manager.config_model.chatgpt_config is not None
60-
if is_chatgpt_config_available:
61-
assert config_manager.config_model.chatgpt_config # for type hinting
62-
config_manager.config_model.chatgpt_config.session_token = session_token
63-
else:
64-
config_manager.config_model.chatgpt_config = RevChatGPTChatbotConfigModel(session_token=session_token)
54+
config_manager.config_model.browser_name = browser_name
6555
else:
66-
chatgpt_config = RevChatGPTChatbotConfigModel(session_token=session_token)
67-
YGKA_config = YGKAConfigModel(chatgpt_config=chatgpt_config)
56+
YGKA_config = YGKAConfigModel(browser_name=browser_name)
6857
config_manager = YGKAConfigManager(config_model=YGKA_config)
6958

7059
config_manager.save_config()

ygka/cli/ygka.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import Optional
22

3-
import rich
4-
import typer
53
from rich.console import Console
64

75
from ygka.models import LanguageModel
@@ -23,17 +21,10 @@ def ygka_command(query: str, language_model: Optional[LanguageModel] = None):
2321
query_client = QueryClientFactory(config_model=config_manager.config_model).create()
2422

2523
console = Console()
26-
try:
27-
with console.status('''[green] YGKA is waiting for ChatGPT's answer ...[/green]'''):
28-
prompt = _generate_prompt(stdin, query)
29-
response = query_client.query(prompt)
30-
console.print(response)
31-
except KeyError:
32-
rich.print('It looks like the `session_token` is expired. Please reconfigure YGKA.')
33-
typer.confirm('Reconfigure YGKA?', abort=True)
34-
config_ygka()
35-
ygka_command(query=query, language_model=language_model)
36-
typer.Exit()
24+
with console.status('''[green] YGKA is waiting for ChatGPT's answer ...[/green]'''):
25+
prompt = _generate_prompt(stdin, query)
26+
response = query_client.query(prompt)
27+
console.print(response)
3728

3829

3930
def _get_config_manager():

ygka/models/ygka_config_model.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
from pydantic import BaseModel, root_validator
44

55
from .language_model import LanguageModel
6-
from .revchatgpt_chatbot_config_model import RevChatGPTChatbotConfigModel
76

87

98
class YGKAConfigModel(BaseModel):
109
language_model: LanguageModel = LanguageModel.REVERSE_ENGINEERED_CHATGPT
11-
chatgpt_config: Optional[RevChatGPTChatbotConfigModel] = None
10+
browser_name: Optional[str] = None
1211
openai_api_key: Optional[str] = None
1312

1413
@root_validator
1514
def check_required_info_provided(cls, values: dict[str, Optional[str]]):
1615
language_model = values.get('language_model')
1716
if language_model == LanguageModel.REVERSE_ENGINEERED_CHATGPT:
18-
if not values.get('chatgpt_config'):
19-
raise ValueError(f'chatgpt_config should not be none if language_model is {language_model}')
17+
if not values.get('browser_name'):
18+
raise ValueError(f'browser_name should not be none if language_model is {language_model}')
2019
elif language_model == LanguageModel.OFFICIAL_CHATGPT:
2120
if not values.get('openai_api_key'):
2221
raise ValueError(f'openai_api_key should not be none if language_model is {language_model}')

ygka/query_clients/query_client_factory.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from ygka.models import LanguageModel, YGKAConfigModel
1+
from typing import cast
2+
3+
from revChatGPTAuth import get_access_token
4+
5+
from ygka.models import LanguageModel, RevChatGPTChatbotConfigModel, YGKAConfigModel
26

37

48
class QueryClientFactory:
@@ -11,7 +15,11 @@ def create(self):
1115
'''Create a query client.'''
1216
if self.config_model.language_model == LanguageModel.REVERSE_ENGINEERED_CHATGPT:
1317
from .reverse_engineered_chatgpt_client import ReverseEngineeredChatGPTClient
14-
return ReverseEngineeredChatGPTClient(config=self.config_model.chatgpt_config)
18+
browser_name: str = \
19+
cast(str, self.config_model.browser_name) # REVERSE_ENGINEERED_CHATGPT means browser_name is not None
20+
access_token = get_access_token(browser_name)
21+
rev_chatgpt_config_model = RevChatGPTChatbotConfigModel(access_token=access_token)
22+
return ReverseEngineeredChatGPTClient(config=rev_chatgpt_config_model)
1523
elif self.config_model.language_model == LanguageModel.OFFICIAL_CHATGPT:
1624
from .official_chatgpt_client import OfficialChatGPTClient
1725
return OfficialChatGPTClient(openai_api_key=self.config_model.openai_api_key)

ygka/utils/ygka_config_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class YGKAConfigManager:
9-
DEFAULT_CONFIG_PATH = os.path.expanduser('~/.ygka_config.json')
9+
DEFAULT_CONFIG_PATH = os.path.expanduser('~/.ygka_openai_config.json')
1010

1111
def __init__(
1212
self,
@@ -22,7 +22,7 @@ def __init__(
2222
An instance of YGKAConfigManager to use as the configuration.\
2323
If None and load_config is True, loads the configuration from the configuration file.
2424
config_path: Path to the configuration file. \
25-
If None, uses the default path "~/.ygka_config.json".
25+
If None, uses the default path "~/.ygka_openai_config.json".
2626
load_config: If True and config_model is None, loads the configuration from the configuration file.
2727
'''
2828
self.config_path = config_path or YGKAConfigManager.DEFAULT_CONFIG_PATH

0 commit comments

Comments
 (0)