11import os
2- from typing import Optional , cast
2+ from typing import Optional , Union , cast
33
44from revChatGPT .V1 import Chatbot
55
66from aishell .exceptions import UnauthorizedAccessError
7+ from aishell .models import RevChatGPTChatbotConfigModel
78from aishell .utils import make_executable_command
89
910from .query_client import QueryClient
1011
1112
1213class ReverseEngineeredChatGPTClient (QueryClient ):
13- config : dict [str , str ] = {}
14+ _config : RevChatGPTChatbotConfigModel
15+
16+ @property
17+ def revchatgpt_config (self ) -> dict [str , Union [str , bool ]]:
18+ return self ._config .dict (exclude_none = True )
1419
1520 def __init__ (
1621 self ,
@@ -19,21 +24,17 @@ def __init__(
1924 ):
2025 CHATGPT_ACCESS_TOKEN = os .environ .get ('CHATGPT_ACCESS_TOKEN' , access_token )
2126 CHATGPT_SESSION_TOKEN = os .environ .get ('CHATGPT_SESSION_TOKEN' , session_token )
22- if CHATGPT_ACCESS_TOKEN is not None :
23- self .config [ 'access_token' ] = CHATGPT_ACCESS_TOKEN
24- elif CHATGPT_SESSION_TOKEN is not None :
25- self .config [ 'session_token' ] = CHATGPT_SESSION_TOKEN
27+ if CHATGPT_ACCESS_TOKEN :
28+ self ._config = RevChatGPTChatbotConfigModel ( access_token = CHATGPT_ACCESS_TOKEN )
29+ elif CHATGPT_SESSION_TOKEN :
30+ self ._config = RevChatGPTChatbotConfigModel ( session_token = CHATGPT_SESSION_TOKEN )
2631 else :
2732 raise UnauthorizedAccessError ('No access token or session token provided.' )
2833
29- def _construct_prompt (self , text : str ) -> str :
30- return f'''You are now a translater from human language to { os .uname ()[0 ]} shell command.
31- No explanation required, respond with only the raw shell command.
32- What should I type to shell for: { text } , in one line.'''
33-
3434 def query (self , prompt : str ) -> str :
3535 prompt = self ._construct_prompt (prompt )
36- chatbot = Chatbot (config = self .config )
36+ chatbot = Chatbot (config = self .revchatgpt_config ) # pyright: ignore [reportGeneralTypeIssues]
37+ # ignore for wrong type hint of revchatgpt
3738
3839 response_text = ''
3940 for data in chatbot .ask (prompt ):
@@ -42,3 +43,8 @@ def query(self, prompt: str) -> str:
4243 response_text = make_executable_command (cast (str , response_text ))
4344
4445 return response_text
46+
47+ def _construct_prompt (self , text : str ) -> str :
48+ return f'''You are now a translater from human language to { os .uname ()[0 ]} shell command.
49+ No explanation required, respond with only the raw shell command.
50+ What should I type to shell for: { text } , in one line.'''
0 commit comments