Stop Sequences Best Practices

Hey OpenAI Community,

I’m currently working on a prompt which takes some existing files & updates aspects about them based on some natural language input. Specifically, I’m using the following header at the top of every prompt that gets fired off to /codex:

# Listed below are:
# 1. An issue describing how referenced YAML files need to be changed, this may include adding elements, removing elements, or changing elements. For example: "@examplefile needs to specify the 'example' namespace" translates into adding a '.metadata.namespace="example"' entry to the @examplefile.
# 2. The original files, separated by a '---' string
# 3. An updated version of the files with the described changes, with each file separated by a '---' string
# 4. A '####' string, indicating the end of this document

Sections 1 & 2 are used as user-input from my end, section 3 is the bulk of the response from OpenAI, and section 4 is used so that I can tell OpenAI to use '####' as a stop sequence.

The current setup works well when there are multiple files, but ends with ## End of document instead when there’s only a single file at play. I’ve managed to solve this by including this case in the stop sequences, but is there a better / more elegant way to work around this?

Would love to hear everyone else’s thoughts on this.

1 Like