OpenAI GPT Chat Completions Accounts For 97% Of Usage

Since the introduction of the Chat Completion API, it accounts for 97% of all GPT API usage as opposed to text completions.

Cobus Greyling
6 min readJul 7, 2023

--

I’m currently the Chief Evangelist @ HumanFirst. I explore & write about all things at the intersection of AI and language; ranging from LLMs, Chatbots, Voicebots, Development Frameworks, Data-Centric latent spaces & more.

Users are moving from text completion to chat completion.

The initial Completions API, introduced in June 2020, provided a freeform text prompt for interacting with OpenAI’s language models.

However, OpenAI soon realised that a more structured prompt interface could produce far better results.

Chat-based paradigms have proven to be particularly powerful, handling the vast majority of use cases, while offering higher flexibility and specificity.

Considering the image below, there has been a change to the Mode section of the OpenAI playground.

The insert mode has been removed while the Complete and Edit modes are marked as legacy.

The Chat Completions API’s structured interface and multi-turn conversation capabilities (e.g., system messages, function calling) enable developers to build varied conversational experiences and completions tasks.

Furthermore, this structure helps protect against prompt injection attacks, as user-provided content can be kept separated from instructions.

OpenAI has expressed their intention to focus the majority of platform development efforts to chat completions.

Here are a few complete working code examples for Text Summarisation, Code Completion & Few-Shot Learning.

Text Summarisation Code

pip install openai

import os
import openai
openai.api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

completion = openai.ChatCompletion.create(
model="gpt-4-0613",
messages = [{"role": "system", "content" : "Summarize this message in max 10 words."},
{"role": "user", "content" : "Jupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter. When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows, and is on average the third-brightest natural object in the night sky after the Moon and Venus."},
{"role": "assistant", "content" : "I am doing well"}]
)

print(completion)

Text Summarisation Result:

{
"id": "chatcmpl-7Zjb73qmWIRhTZ1EdoVoF3htTx6wy",
"object": "chat.completion",
"created": 1688751113,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Jupiter is the largest planet and very bright in the sky."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 160,
"completion_tokens": 13,
"total_tokens": 173
}
}

Code Completion Code

completion = openai.ChatCompletion.create(
model="gpt-4-0613",
messages = [{"role": "system", "content" : "Complete the following code."},
{"role": "user", "content" : "def fibonacci(num):"}]
)

print(completion)

Code Completion Result:

{
"id": "chatcmpl-7ZjeMfmfC7SntvD4EuKZtTmotf6z4",
"object": "chat.completion",
"created": 1688751314,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "if num <= 0:\n return []\nelif num == 1:\n return [0]\nelif num == 2:\n return [0, 1]\nelse:\n fib_list = [0, 1]\n for i in range(2, num):\n fib_list.append(fib_list[i - 1] + fib_list[i - 2])\n return fib_list"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 80,
"total_tokens": 100
}
}

Few-Shot Learning Code

completion = openai.ChatCompletion.create(
model="gpt-4-0613",
messages = [{"role": "system", "content" : "You translate corporate jargon into plain English."},
{"role": "user", "content" : "New synergies will help drive top-line growth."},
{"role": "assistant", "content" : "Working well together will make more money."},
{"role": "user", "content" : "Let’s circle back when we have more bandwidth to touch base on opportunities for increased leverage."},
{"role": "assistant", "content" : "When we’re less busy, let’s talk about how to do better."},
{"role": "user", "content" : "LThis late pivot means we don’t have time to boil the ocean for the client deliverable."}
]
)
print(completion)

Few-Shot Learning Result:

{
"id": "chatcmpl-7ZjixqMS7XUlKLGPQbvX0RgIlNayU",
"object": "chat.completion",
"created": 1688751599,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "This sudden change in direction means we don't have enough time to do everything for the client's request."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 107,
"completion_tokens": 21,
"total_tokens": 128
}
}

The last update to Chat Markup Language (ChatML) was four months ago, and I would expect an enhancement soon.

It is clear that OpenAI wants to introduce structure to the format of input data. With the ChatML conversational format extending to generative AI tasks which have been very open in the past, like summarisation, code completion and few-shot contextual prompts.

This structure being imposed from a model level, will have to be absorbed by downstream implementations like autonomous agents, prompt chaining, etc.

As LLM-based generative AI apps can make use of multiple LLMs, the propagation of Chat Completion will surely have benefits, but will surely introduce complexity.

⭐️ Please follow me on LinkedIn for updates on Conversational AI ⭐️

I’m currently the Chief Evangelist @ HumanFirst. I explore & write about all things at the intersection of AI and language; ranging from LLMs, Chatbots, Voicebots, Development Frameworks, Data-Centric latent spaces & more.

LinkedIn

--

--

Cobus Greyling

I explore and write about all things at the intersection of AI & language; LLMs/NLP/NLU, Chat/Voicebots, CCAI. www.cobusgreyling.com