My unnecessarily complicated CLI answer to my own question after a little further research:
import openai
import argparse
import json
openai.api_key = “API key here”
parser = argparse.ArgumentParser(description=‘CLI_GPT4’)
parser.add_argument(“-s”, type=str, help=“System role”, default=“You are a happy idea bot, you give people ideas that make them happy”, dest=“sys”)
parser.add_argument(“-a”, type=str, help=“Assistant role”, default=“”, dest=“assist”)
parser.add_argument(“-u”, type=str, help=“User role”, default=“”, dest=“user”)
args = parser.parse_args()
system=args.sys
assist=args.assist
user=args.user
class MessageBuilder:
def init(self):
self.msg = ][ #swap these to make a list
def add_line(self, role, content):
line = {"role": role, "content": content}
self.msg.append(line)
def get_message(self):
return self.msg
builder = MessageBuilder()
if system is not None: builder.add_line(“system”, system)
if user is not None: builder.add_line(“user”, user)
if assist is not None: builder.add_line(“assistant”, assist)
msg=builder.get_message()
print(msg)
response = openai.ChatCompletion.create(model=“gpt-4”, messages=msg, max_tokens=79)
response_dict = dict(response)
reply = response_dict[‘choices’][0][‘message’][‘content’]
reply=reply.replace(f"\n", " ")
print(reply)
and the resulting CLI use (CLI_GPT4.py) usage:
C:\Users\Z440\Desktop\GPT4\openai-quickstart-python> python CLI_GPT4.py -u “it’s raining” -a “Dogs like people.”
[{‘role’: ‘system’, ‘content’: ‘You are a happy idea bot, you give people ideas that make them happy’}, {‘role’: ‘user’, ‘content’: “it’s raining”}, {‘role’: ‘assistant’, ‘content’: ‘Dogs like people.’}]
How about having a cozy indoor picnic in your living room? Lay down a blanket, prepare some delicious snacks, light some candles, and set the mood by playing your favorite music or a rain-themed playlist in the background. You can even invite family members or friends to join through video chat, making it a fun virtual gathering that brings happiness and warmth during a rainy day.