-
-
Save shanejones/030944c36328a9aee76c80fb35035e3c to your computer and use it in GitHub Desktop.
Script to connect to OpenAI and generate AI content for specific post title
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
###### | |
# | |
# Script to connect to OpenAI and generate AI content for specific post titles | |
# | |
# Created by https://twitter.com/shanejones | |
# Go and give him a follow being so he gave you this script for free | |
# | |
###### | |
import os | |
import openai | |
import csv | |
import time | |
openai.api_key = "YOUR_API_KEY_HERE" | |
infile = open("post-titles.txt", "r") | |
counter = 0 | |
for post in infile: | |
f = open("post-content.csv", "a") | |
writer = csv.writer(f) | |
counter = counter + 1 | |
prompt = "write as much content as you can for a blog post called \"" + post +"\"" | |
response = openai.Completion.create( | |
engine="text-ada-001", | |
prompt=prompt, | |
temperature=0.7, | |
max_tokens=1200, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
output = [post, response.choices[0].text] | |
writer.writerow(output) | |
print(str(counter) + " complete.") | |
# lets not spam the API too much | |
time.sleep(0.5) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment