Sure, let me post a little more for clarity. I can’t post the complete code or specifics of what it’s generating, but here’s what I’m doing.
Here is the web app side where I input the article’s contents in a form.
main.py
import chat_functions
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def generate_article():
if request.method == 'GET':
return render_template('index.html')
title = request.form.get('title').title()
materials = request.form.get('materials')
instructions = request.form.get('instructions')
keywords = request.form.get('keywords')
content = chat_functions.ArticleGenerator(title, materials, instructions, keywords)
article = content.generate_article()
return render_template('index.html', article=article)
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8080, debug=False)
The chat_functions being imported in main.py above are my GPT instructions, which look like the following (please excuse the text formatting). Small side note, I changed the 13 pairs to just 13 user instructions, I’ll edit my comment above.
chat_functions.py
import openai
import os
from dotenv import load_dotenv
class ArticleGenerator():
def __init__(self, title, materials, instructions, keywords):
self.title = title
self.materials = materials
self.instructions = instructions
self.keywords = keywords
load_dotenv()
openai.api_key = os.getenv('OPENAI_API_KEY', 'xxxxxxx')
self.messages = [
{"role": "system", "content": f'''Generate articles that follow the users instructions exactly.'''},
{"role": "user", "content": f'''I want you to write an article for a {title} project according to my instructions and formatting rules.'''},
{"role": "user", "content": f'''First, write {title} as a first level heading. Under that heading, write an introduction to the project.'''},
{"role": "user", "content": f'''Next, write 'What is {title}?' as a second level heading. Under that heading, write about what {title} is.'''},
{"role": "user", "content": f'''Next, write 'What You Need to Make {title} At Home' as a second level heading. Under that heading, take this list of materials
and write about why each material is needed for the project: {materials}. Bold the name of the material, then write
no more than 40 words about why it is needed. Seperate each material and its description with a line break.
Do not include the material's quantity.'''},
{"role": "user", "content": f'''Next, write 'Tips for Making the Best {title}' as a second level heading. Under that heading, include 5-7 points about how to build the best {title}.'''}
]
def generate_article(self):
completion = openai.ChatCompletion.create(
model="gpt-4",
temperature=1.2,
presence_penalty=0.0,
frequency_penalty=0.0,
logit_bias={48126: -100},
messages=self.messages
)
return completion.choices[0].message.content
These aren’t the complete instructions, but this is basically how I’ve got it working now. Each instruction creates an H1, H2, or H3, then writes and formats the content for each heading. This part is working great; it writes relevant content that is formatted how I specify. The issue is, while it’s writing these sections of content, I need it to use specific keywords, which I can’t get it to do.
These keywords are always relevant to the topic of the article, I just need the API to actually use them. For example, say the article title is ‘Painted DIY Bookshelves’ and a keyword is ‘coats’ (as in coats of paint). The API could either write a new sentence using the word (i.e., ‘Apply two coats of paint, letting it dry in between’), or it could replace an existing word with the keyword when it can be used interchangeably (i.e., using ‘coats’ instead of ‘layers’). It’s doing neither currently.
@chrstfer I’m going to completely redo the chat instructions following your recommendations today, so I’ll update or send a PM to take you up on your brainstorming offer. Thanks!
@_j No offense, but you are not understanding the point of this thread and it’s convoluting the conversation. What you’re talking about is keyword stuffing, which Google has been penalizing for years. What I’m talking about is keyword optimizing, which is still very much a ranking factor. Having this program write ‘fridge’ instead of ‘refrigerator’, or create new sentences using keywords that are relevant to the topic, is neither spam nor too much to ask from ChatGPT. Every website anywhere near the top 5 pages of Google SERP’s use some variation of keyword optimization to help get there, which is why I’m not here to debate SEO strategy.
@ethan.peck I appreciate the example! If I can’t get this to work with @chrstfer suggestions, I’ll try this out with the logit_bias.