Last active
November 7, 2023 09:01
-
-
Save iTrooz/f5a2f9b5e79fb54d8439cedba49bdfa3 to your computer and use it in GitHub Desktop.
basic ChatGPT terminal client
This file contains 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
#!/bin/python3 | |
import sys | |
from openai import OpenAI | |
myPrompt = ' '.join(sys.argv[1:]).strip() | |
if not myPrompt: | |
print("Syntax : ", sys.argv[0], "prompt") | |
exit(1) | |
print("Me:", myPrompt, file=sys.stderr) | |
client = OpenAI(api_key = "YOUR KEY HERE") | |
stream = client.chat.completions.create( | |
model="gpt-4-1106-preview", | |
messages=[{"role": "user", "content": myPrompt}], | |
stream=True, | |
) | |
print("ChatGPT: ", end="", flush=True, file=sys.stderr) | |
for part in stream: | |
print(part.choices[0].delta.content or "", end="", flush=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment