Using GPT Chat Completions

OpenAI models are trained as completion-style models, which means they are designed to predict the next word in a sequence of text. This is a common task in natural language processing, and it’s also the basis for many other tasks such as translation, question answering, text analysis, and more.

To use the chat completions, you need to have an OpenAI API key. You can generate this in your OpenAI dashboard. Then, you need to use the API endpoint to send a request to the API and get a response back.

OpenAI provides multiple models. However, if you’re starting out, choose between GPT-3.5-Turbo or GPT-4.

An Introductory Example

Let’s initiate a chat with GPT-3.5:

cat > src/app.py << EOF
from api import client

model

Get OpenAI GPT For Python Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.