Limit Character Limit in each JSON Field

Hi,

Currently, I have the model output JSON via function calling. I want the model to generate a list of posts, so I define a function to the model that takes in a list of posts, and I ask the model to create that parameter. For instance:

const function = {
      name: "write_about_dogs",
      description: `A function that takes in a list of posts about dogs and does something with it.`,
      parameters: {
        type: "object",
        properties: {
          posts: {
           "type": "array",
                "description": "A list of posts about dogs.",
                "items": {
                    "type": "string"
                }
          }
        },
        required: ["posts"],
      },
    },
};

However, I am looking to gate the amount of generated tokens per item in the array, as opposed to the entire GPT output. Is there a way to do this? Or is my only recourse to do multiple calls one at a time. I would like to limit that as it would require serially-awaiting each request, and would cost more input tokens.

You need to control the output via language. The most appropriate length might be “tweet”, but the stupid AI spouts unstoppable tween emojis and hashtags. So I had to try harder.

I re-engineered the function a bit:

function_list=[
{
    "name": "post_dog_quip",
    "description": "Single-sentence postings, 25 words. Absolutely no emoji nor unicode permitted.",
        "parameters": {
        "type": "object",
        "properties": {
            "post_list": {
                "type": "array",
                "description": "output to API to post",
                "items": {
                    "type": "string"
                }
            }
        },
        "required": ["post_list"],
        },
    }
]

And some prompting to fill the function.

response = openai.ChatCompletion.create(
    messages=[{"role": "system", "content":
               "You are a helpful AI content creator. Keep it short."},
            {"role": "user", "content":
             "Write 20 different posts about dogs, incl names and breeds,"
             "and daily antics. No emoji permitted."},
            ],
    model="gpt-3.5-turbo", max_tokens=200, temperature=0.2,
    functions=function_list, function_call={"name": "post_dog_quip"})
if response['choices'][0]['message']['function_call']:
    funct_name = str(response['choices'][0]['message']['function_call']['name'])
    print(f"--{str(response['choices'][0]['message']['function_call']['name'])}:--\n"
          + str(response['choices'][0]['message']['function_call']['arguments']))
else:
    print(response)

response (function_call)

–post_dog_quip:–
{
“post_list”: [
“Meet Max, the playful Labrador Retriever who loves chasing tennis balls all day long.”,
“Introducing Bella, the energetic Border Collie who can’t resist herding anything that moves.”,
“Say hello to Charlie, the mischievous Dachshund who loves digging up the backyard.”,
“Meet Luna, the adorable Golden Retriever who enjoys long walks and splashing in puddles.”,
“Introducing Cooper, the friendly Beagle who always greets everyone with a wagging tail.”,
“Say hello to Daisy, the curious French Bulldog who loves exploring new places.”,
“Meet Rocky, the brave German Shepherd who is always ready to protect his family.”,
“Introducing Lucy, the intelligent Poodle who can learn new tricks in no time.”,
“Say hello to Milo, the playful Shih Tzu who loves playing fetch with his favorite toy.”,
"Meet Bailey, the loyal Boxer who (max_tokens)

Hi,

You can use words like succinct, “with brevity”, concise, brief, etc. etc., these will all produce shorter responses.