Created
July 23, 2023 10:16
-
-
Save scaery/ebbc3c82d86882d4f9d982690fc3aa10 to your computer and use it in GitHub Desktop.
ChatGPT Terminal v2 - Hacking with AI knowledge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import openai | |
import io | |
# Set your OpenAI API key here | |
openai.api_key = "YOUR-OPENAI-API-KEY" | |
def get_chatgpt_response(question): | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", | |
messages=[{"role": "user", "content": question}] | |
) | |
return response['choices'][0]['message']['content'] | |
def read_question_from_input(): | |
question_lines = [] | |
print("Enter your question (Press ESCAPE to send the question to ChatGPT):\n") | |
while True: | |
char = input() | |
if char == chr(27): # ASCII code for ESCAPE key | |
break | |
question_lines.append(char) | |
return "".join(question_lines) | |
def main(): | |
question = read_question_from_input() | |
if question.strip(): | |
answer = get_chatgpt_response(question) | |
with io.open("chatgpt.log", "a", encoding="UTF-8") as f: | |
print(f"\n\n# START #################################################\nYou:\n\n{question} ???\n", file=f) | |
print(f"ChatGPT:\n\n {answer}", file=f) | |
print("\n# END ###################################################\n", file=f) | |
print("ChatGPT:\n\n", answer) | |
else: | |
print("No question provided. Exiting.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment