From 379374d097a55c314c18ba0c4aad91e7cf7f878e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20M=C3=BCller=20=28ChaoticByte=29?= Date: Mon, 13 Mar 2023 11:00:27 +0100 Subject: [PATCH] Extended CLI to support Bing's Chatbot and updated README --- README.md | 12 ++++++++++++ cli.py | 25 +++++++++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6440bc0..0f6b78e 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,15 @@ You need an API key for the official ChatGPT API. ### Unofficial API for Bing Chatbot This requires your Cookies to be exported to a json file. See [EdgeGPT's README](https://github.com/acheong08/EdgeGPT) for more infos. + +## CLI + +Using the official API via ChatGPT: +``` +OPENAI_API_KEY="..." ./cli.py Hello +``` + +Using Bing's Chatbot: +``` +BING_COOKIES_FILE="~/cookies.json" ./cli.py bing Hello +``` diff --git a/cli.py b/cli.py index 2c452a1..ca71b98 100755 --- a/cli.py +++ b/cli.py @@ -5,13 +5,22 @@ from os import environ from sys import argv -from chatgpt_pyapi.openai import ChatGPT, Message, Models - -# Read the API key from a environment variable -API_KEY = environ["OPENAI_API_KEY"] - if __name__ == "__main__": - # Create ChatGPT API instance - cgpt = ChatGPT(API_KEY, model=Models.GPT_35_TURBO_0301) - user_input = " ".join(argv[1:]) + bing = False + if len(argv) > 2: + bing = argv[1] == "bing" + if bing: + from chatgpt_pyapi.bing import ChatGPT, Message, ConversationStyle + # Read the path to the cookies file from a environment variable + BING_COOKIES_FILE = environ["BING_COOKIES_FILE"] + # Create ChatGPT API instance + cgpt = ChatGPT(BING_COOKIES_FILE, ConversationStyle.balanced) + user_input = " ".join(argv[2:]) + else: + from chatgpt_pyapi.openai import ChatGPT, Message, Models + # Read the API key from a environment variable + API_KEY = environ["OPENAI_API_KEY"] + # Create ChatGPT API instance + cgpt = ChatGPT(API_KEY, model=Models.GPT_35_TURBO_0301) + user_input = " ".join(argv[1:]) print(cgpt.chat(Message(user_input)).text)