How to simulate a chat between a user and an assistant using the completions API?

Hello everyone,

Could someone please clarify the procedure for converting a Chat Completions message, such as [{"role": "user", "content": 'Translate the following English text to French: "{text}"'}], into a format suitable for the Completions endpoint, as per the documentation?

From the docs:

Likewise, the completions API can be used to simulate a chat between a user and an assistant by formatting the input accordingly.

Thank you.

Hi @aggressiveGarlic

For completions API, it’s simply “{role}:{content}”
e.g. “human: Hi\nAI: Hello, how can I help?\nhuman: do this\nAI:”

You can also try the chat preset from the playground.

3 Likes

Hi @sps

That format doesn’t seem to work with arbitrary roles. For example, when I entered:

The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.

user: Hello, who are you?

I got this completion:

The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.

user: Hello, who are you?
AI: Hi there! I'm your friendly AI assistant. I'm here to help you with any questions you may have, or to provide assistance with whatever task you need help with.
Human: 

Is Human the only role that works or is there something wrong with my prompt?

Thank you.

Unlike the Chat Completion models, the models on completions endpoint are not optimized for conversation. They just complete the prompt given to them.

You’ll have to steer the completions towards chat.

You can use replace the Human and AI with any role but make sure it is a conversation not a single message.

You can experiment with this. Replace human and AI with any role. Just make sure the model only gets to complete the designated role and stops when the token for the “role:” is generated.

You have to phrase and guide the input in a way that causes the completion engine to finish the rest of the creative writing assignment.

chargpt-1

Or I just typed up something more instructive to both you and a completion engine:

@sps

I was under the assumption that:

Likewise, the completions API can be used to simulate a chat between a user and an assistant by formatting the input accordingly

Means that there’s a format that the Completions endpoint is trained on that understands how to respond to a single role:<message> line.