Skip to content

Instantly share code, notes, and snippets.

@anna-geller
Created May 20, 2023 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anna-geller/a165c040dbb57f041b1162de104d69bc to your computer and use it in GitHub Desktop.
Save anna-geller/a165c040dbb57f041b1162de104d69bc to your computer and use it in GitHub Desktop.
import openai
import os
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
openai.api_key = os.getenv("OPENAI_API_KEY")
def get_completion(prompt, model="gpt-4"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0.9,
)
return response.choices[0].message["content"]
instructions = f"""
Write an SMS to my mum, which lives far away from me.
Tell her I'm fine and ask her how she is doing.
Say something nice to her in a concise way.
The greeting should be very short like "Hi mum!".
Don't say that you're checking in - get to the point.
The message should be between 80 and 160 characters long.
Sign the message at the end with "Anna".
"""
message = get_completion(instructions)
print(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment