From the course: Building a Project with the ChatGPT API
Generate text using text completion - ChatGPT Tutorial
From the course: Building a Project with the ChatGPT API
Generate text using text completion
- The possibilities of what you can create with the Completions API are limitless. You can generate and edit content, and code to complete task in a matter of minutes, not hours. The Completions API uses the text in, text out format for a wide variety of tasks. The input is a simple text prompt with a model generating output that matches the context or pattern you provide. The Completions API is backed by a traditional GPT model that consumes unstructured text, which you already know is represented to the model as a sequence of tokens. A simple example input would be, "Write a title for a course on the OpenAI API." With the output being, "Getting Started with the OpenAI API: A Comprehensive Guide." Have you considered what would happen if you provided the exact same prompt to the model again? You may actually see a different result. Let's test this out. Using the same prompt, write a title for a course on the OpenAI API. Let's execute this code to see what happens. The response is "Getting Started with the OpenAI API: Unlocking the Power of AI." This happens because the model is considered stochastic! The responses are generated randomly based on the input and the model's probability distribution. Imagine reaching into a jar filled with different colored balls. Each ball represents a possible outcome, and the color of each ball represents the probability of that outcome occurring. The outcome is stochastic because you cannot predict which color ball you will pick, but each specific color has a known probability of being chosen. You can control the randomness of the model by using the temperature attribute. Lower values result in more consistent outputs, while higher values generate more random results. You'll notice the Completions API is similar to the Chat Completions API, but there are differences. Instead of the input being a list of messages, it's freeform text. Another difference is the underlying GPT models available to each. The Chat Completions API interfaces to GPT-4 and GPT-3 0.5 Turbo, and the Completions API interfaces with GPT-3.0, and anything before. Developers often opt to use the Chat Completions API over the Completions API, because it's more cost-effective, and handles complex tasks better. From my experience, the newer models are more creative as well. Here's the link to the endpoint to carry out the interaction with the Completions API. This course will use open AI's Python library to access the API endpoints. However, you can test them directly from tools like Curl or Postman. Now that you understand how to generate text using text completions, let's explore the use cases for the Embeddings API.
Contents
-
-
-
-
Create chatbots using chat completion4m 34s
-
Generate text using text completion3m 34s
-
Measure relatedness using embeddings4m 26s
-
Turn audio into text using Whisper3m 46s
-
Generate images using DALL-E5m 25s
-
Customize a model using fine-tuning6m 52s
-
Examine key concepts3m 43s
-
Understand pricing models2m 52s
-
-
-
-
-
-
-
-
-