In the vast landscape of technology, where applications and systems seamlessly team up, a silent hero exists: the Application Programming Interface (API). An API is like a waiter in a restaurant. Customers (developers) communicate their preferences (requests) to the waiter (API), specifying the dishes (data or services) they desire. The waiter efficiently conveys these requests to the kitchen (server or database) and brings back the requested information, ensuring a smooth and seamless interaction for a delightful dining experience (application usage).
Now, in the LLM game, Azure and OpenAI have joined forces to bring us two impactful APIs: the OpenAI Completion API and the OpenAI Chat Completion API. They’re like the superheroes of text generation, from finishing sentences to acing dynamic conversations. Both these APIs have been exceptionally useful to us, and we’re thrilled to take you on a ride-along to unravel their capabilities.
So, the OpenAI Completion API is your portal to legacy models like GPT-3, Davinci, and crew, plus the updated gang like GPT-3.5-Turbo-Instruct. Just toss in a string, and voila! You get a text completion – Let’s imagine that the OpenAI Completion API is a nice, elaborate toolbox filled with an array of specialized tools. Each tool represents the duties of a model, both legacy and new. When you toss in a string – think of it as the material you want to work on – and give it a whirl, out comes a finely crafted piece, ready for various tasks.
It’s like having a set of versatile tools at your disposal. Need a summary? Grab the summarization tool. Want a translation? Reach for the translation tool. Just seeking a better understanding of words? Well, there’s a tool for that too. The OpenAI Completion API is essentially your go-to toolkit for text manipulation, making it a breeze to shape, understand, and transform your textual material.
In the code below, we made use of the OpenAI API to generate a completion using the GPT-3.5-Turbo engine. We use the openai.Completion.create as a method call to the OpenAI API’s Completion endpoint. It initiates a request to generate text completion based on the specified parameters.
On the other hand, the newer OpenAI Chat Completion API brings the big guns like GPT-4 and friends. It’s not a solo act; it rolls with a list of messages as its sidekick. These messages play different roles – user, assistant, or system – telling the model where the talk is coming from and why. It’s like a chat where everyone knows their part.
The messages parameter accepts an array of message objects, organized by role, when using the Python API, represented as a list of dictionaries. To make it easier, imagine the messages parameter as the cast of characters in a play, and each message is a character in the script. When you’re working with the Python API, consider it as managing a list of characters, each represented by a dictionary.
Now, in this theatrical production, each character plays a role – there’s the user, the assistant, and the system. The system, or the director in this analogy, is the one who kicks off the play by providing the initial instructions. It’s like the director giving cues, setting the scene, and establishing the tone for the entire performance. This is where you can weave in a character’s backstory, share some guiding instructions, or establish the rules of the stage!
Now in this code snippet, we are using the Chat Completion API to perform chat-based language completion using the GPT-3.5-Turbo engine. We are instructing the model to act as an AI assistant to detect sentiment in the text:
Let’s shift gears and compare their features:
Completion API: Hooks you up with text completions from a single prompt.
Chat Completion API: Nails it in the chat game, keeping the conversational flow intact.
Completion API: Knows what’s up with the prompt but might forget it after.
Chat Completion API: Holds onto the chat history, making sure each reply is on point.
Completion API: Lets you tweak the model’s vibe.
Chat Completion API: Goes a step further, giving you room to train it for specific tasks.
Deciding between these two? It’s akin to selecting the perfect cast for your play. The Completion API takes center stage for solo acts, much like crafting a compelling monologue or setting the stage for code generation. On the other hand, the Chat Completion API becomes your backstage crew, orchestrating the dynamic conversations like a well-coordinated theatrical ensemble – perfect for lively interactions in the world of chatbots and interactive interfaces.
Both these APIs bring something for everyone – the Completion API crafts those finishing touches, while the Chat Completion API spices up the chat scene. It’s all about finding the right fit for your project and diving into the endless possibilities of language play!
That’s all for now! Don’t miss out on our compelling tour of Langchain’s SQL Agents next Friday. See you!
Enjoy more Azure AI Blogs as part of Azure AI Week.
About the Author:
Xencia, headquartered in Bangalore with offices and delivery centres in Chennai, Singapore and USA, is a Born in the Cloud Company and helps organizations embrace public cloud seamlessly. We UNLEASH THE POWER OF CLOUD with our XEN (Transformational Experience) Framework.
Azure OpenAI Completion API vs Chat Completion API – Demystifying the Differences! Available at: https://www.linkedin.com/pulse/azure-openai-completion-api-vs-chat-demystifying-qirpc/ [Accessed: 18th January 2024].