File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 11from .gpt3_client import GPT3Client as GPT3Client
2+ from .official_chatgpt_client import OfficialChatGPTClient as OfficialChatGPTClient
23from .query_client import QueryClient as QueryClient
34from .reverse_engineered_chatgpt_client import ReverseEngineeredChatGPTClient as ReverseEngineeredChatGPTClient
Original file line number Diff line number Diff line change 1+ import os
2+ from typing import Final , Optional
3+
4+ from revChatGPT .V3 import Chatbot
5+
6+ from aishell .utils import make_executable_command
7+
8+ from .query_client import QueryClient
9+
10+
11+ class OfficialChatGPTClient (QueryClient ):
12+ openai_api_key : str
13+
14+ def __init__ (
15+ self ,
16+ openai_api_key : Optional [str ] = None ,
17+ ):
18+ super ().__init__ ()
19+ OPENAI_API_KEY : Final [Optional [str ]] = os .environ .get ('OPENAI_API_KEY' , openai_api_key )
20+ if OPENAI_API_KEY is None :
21+ raise Exception ('OPENAI_API_KEY should not be none' )
22+
23+ self .openai_api_key = OPENAI_API_KEY
24+
25+ def _construct_prompt (self , text : str ) -> str :
26+ return f'''You are now a translater from human language to { os .uname ()[0 ]} shell command.
27+ No explanation required, respond with only the raw shell command.
28+ What should I type to shell for: { text } , in one line.'''
29+
30+ def query (self , prompt : str ) -> str :
31+ prompt = self ._construct_prompt (prompt )
32+
33+ chatbot = Chatbot (api_key = self .openai_api_key )
34+ response_text = chatbot .ask (prompt )
35+
36+ return make_executable_command (response_text )
You can’t perform that action at this time.
0 commit comments