Hi,
I’m having a super difficult time getting the 3.5-turbo API to return the correct number of output lines consistently. (it can do it about 40% of the time)
I’ll attach my python below. The input “MTD.txt” is a sampling of 6 song lyrics separated by newlines, and it currently writes the output to the file “cherry_coke8.txt” in the same directory.
I’m trying to do this with one system prompt, and multiple user prompts (I’d rather not use the giant block of instructions during each request because of the input token cost).
It can sometimes output descriptions, but it’s extremely flaky.
Any advice is very appreciated!
from openai import OpenAI
# Reads the clean txt file
def readCleanTXT(cleanTXT):
with open(cleanTXT, 'r') as file:
lines = file.readlines()
return lines
# Runs the OpenAI API on the clean txt file
def generatePrompts(cleanTXT, wordPhrase1, wordPhrase2, wordPhrase3):
client = OpenAI()
systemMessageWhole = {"role": "system", "content":
"You are a creative prompt creator." + "\n" + \
"The user will pass you lines of a song, one at a time, and you will generate creative prompts for each line (FOR EACH USER REQUEST)." + "\n" + \
"Then, the images produced from your prompts will be shown concurrently with the song’s audio, creating a slideshow-like music video." + "\n" + \
"Note that the image generation model takes in each prompt separately, so that you cannot reference past prompts or scenes from past prompts, and instead must describe them again." + "\n" + \
"Yet, your prompts must still show an overarching theme / arc / story, and relate to each other in content." + "\n" + \
"The user will pass in three words or phrases along with the lines to their song, which will guide your prompts in terms of “mood” or “theme”." + "\n" + \
"""Criterion:
Respond to each line individually with a single sentence. Prompts are not necessarily in full sentences, and may contain many adjectives and dependent clauses separated by commas. Maximimze Detail.
Do not combine responses or directly refer to past lines.
Use clear language that focuses on visual imagery.
***The user will input lyrics 1 by 1. Make sure that you are returning ALL your prompts in your completion, and not just one.***
DO NOT USE INTERPRATIVE OR ABSTRACT VERBS: Do not analyze. Do not use any words "representing" “showcasing” or “emphasizing” or “highlighting” or "portraying" or similar. Simply state what is literally in the image. Don't infer meaning. Just describe clear, vivid pictures.
Adhere strictly to the mood words provided. These should influence your prompts.
Keep your response to a single sentence, as descriptive as possible while under 20 words.
A sample of a good prompt: A powerful mysterious sorceress, casting lightning magic, detailed clothing, digital painting, hyperrealistic, fantasy, Surrealist, full body, highly detailed, dystopian, iridescent gold""" + "\n" "\n" + \
"These are the user's three words/phrases: " + "\n" + \
wordPhrase1 + ", " + wordPhrase2 + ", " + wordPhrase3}
lineTotal = 6
userMessages = [
{ "role": "user",
"content": f"Line {index + 1} of {lineTotal}: {line}"
} for index, line in enumerate(readLyrics)
]
print([systemMessageWhole]+userMessages)
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=
[systemMessageWhole] + userMessages
)
# Writes the finished file to local directory as .txt
with open("cherry_coke8.txt", 'w') as file:
#print(completion.choices[0].message.content)
file.write(completion.choices[0].message.content)
if __name__ == "__main__":
readLyrics = readCleanTXT("MTD.txt")
wordPhrase1 = input("Enter word/phrase 1: ")
wordPhrase2 = input("Enter word/phrase 2: ")
wordPhrase3 = input("Enter word/phrase 3: ")
# The actual call
generatePrompts(readLyrics, wordPhrase1, wordPhrase2, wordPhrase3)