I am using the GPT-4-1106-preview API. I asked it to generate some social media posts in a specific format, explicitly mentioning that I want 12 posts, for example. However, I received only 8 or 9 in response. Although, I insisted that I strictly want 12 posts in the prompt.
Hi! Welcome to the forum!
Unfortunately, the models are not always amazing at counting, and some have certain idiosyncrasies that you need to work around.
Is there a specific reason why you want 12 posts in one, instead of calling the API 3, 4, 6 or 12 times?
Yeah thanks for the welcome,
I want 12 because I need some generated and scheduled posts over a month. 3 posts per week . I tried to do it implicitly by saying 3 posts/week for a month and it didnt work . so I had to explicitly mention it “12 posts for next month”, and still , same issue.
in my case . each post is an object looking like
{ post title , publish date , post caption … }.
if there is no way to force it from prompt it’s ok I can figure out how to force it from my backend.
LLMs can’t count, you’re asking the model to do something it cannot.
There are ways to make it easier for the model to do what you want it to, but there is no way to ensure it will never generate 11 or 10.
@Diet has already given you the only correct answer, ask for the number you want (or maybe more) count the number you get, then ask for more until you get the correct total (or more) and keep what you need.
Try adding an index explicitly by numbering your desired posts 1 to 12 in your instructions, so the model knows when to stop. And add the instruction “Use numbers to label the posts, starting with #1, #2, #3 and so on, until you reach post #12 which should be your final post.” Basically, you need some instructions to explain the number of posts you need in terms of text, rather than math. The model understands text patterns, like a list of 12 items, even though it doesn’t understand math or counting.
thanks all for the assistance, I tried specifying the length of the array in the schema and it worked fine:
const schema = {
type: "object",
properties: {
posts: {
type: "array",
description:
"an array of posts with length = number of posts per week * 4 ",
items: {
type: "object",