diff --git a/pxutil/cli.py b/pxutil/cli.py index 5f4ee37..b6e9138 100755 --- a/pxutil/cli.py +++ b/pxutil/cli.py @@ -57,16 +57,15 @@ def chat_main(): description="ChatGPT cli, type q to exit. Set env variable OPENAI_API_KEY first." ) parser.add_argument( - "--v4", action="store_true", help="use GPT-4-turbo, default is GPT-3.5-turbo" + "-m", + "--model", + default="gpt-3.5-turbo", + help="OpenAI chatGPT model, gpt-3.5-turbo (default), gpt-4o etc.", ) args = parser.parse_args() register_signal_ctrl_c() - if args.v4: - model = "gpt-4-turbo" - else: - model = "gpt-3.5-turbo" - chat = ChatAPI(model=model) + chat = ChatAPI(model=args.model.strip()) while True: question = input("> ") if question in ("q", "quit"): @@ -128,4 +127,4 @@ def listmod_main(): # sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) # loop_main() - listmod_main() + chat_main() diff --git a/pxutil/pxutil.py b/pxutil/pxutil.py index 7738d95..1465a51 100755 --- a/pxutil/pxutil.py +++ b/pxutil/pxutil.py @@ -490,7 +490,7 @@ def grep(pattern, string=None, filename=None): return result -def replace_in_file(files, old, new, backup=None): +def replace_in_file(files, old, new, backup=""): """ Replace in place directly on a file. @@ -830,15 +830,15 @@ def chat(self, question: str): if isinstance(resp, Exception): return Exception("Chat API request failed with error: %s." % resp) - if len(resp["choices"]) >= 1: - for choice in resp["choices"]: - if choice["index"] == 0 and choice["finish_reason"] in ("stop", None): - answer = choice["message"]["content"] + if len(resp["choices"]) >= 1: # type: ignore + for choice in resp["choices"]: # type: ignore + if choice["index"] == 0 and choice["finish_reason"] in ("stop", None): # type: ignore + answer = choice["message"]["content"] # type: ignore answer = answer.strip("\n").strip() # record chat history if self.remember_chat_history: self.chat_history.append({"role": "user", "content": question}) - self.chat_history.append(choice["message"]) + self.chat_history.append(choice["message"]) # type: ignore return answer return Exception(