diff --git a/chatgpt_bot/chatgpt_bot.py b/chatgpt_bot/chatgpt_bot.py new file mode 100644 index 0000000..7644f0d --- /dev/null +++ b/chatgpt_bot/chatgpt_bot.py @@ -0,0 +1,36 @@ +import requests + +API_KEY = "YOUR API KEY" + +PROXIES = { + "http": "http://127.0.0.1:4780", + "https": "http://127.0.0.1:4780" +} + +MODEL = "gpt-3.5-turbo" + +history = [{"role": "system", "content": "你好"}] + +def chat(): + data = { + "messages": history, + "model": MODEL + } + + response = requests.post( + "https://api.openai.com/v1/chat/completions", + headers={"Authorization": f"Bearer {API_KEY}"}, + json=data, + proxies=PROXIES + ) + + message = response.json()["choices"][0]["message"]["content"].strip() + history.append(response.json()["choices"][0]["message"]) + + return message + +while True: + message = chat() + print("Bot:", message) + msg = input("You: ") + history.append({"role": "user", "content": msg}) diff --git a/chatgpt_bot/requirements.txt b/chatgpt_bot/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/chatgpt_bot/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file