1. Overview of the OpenAI API

The OpenAI API is an artificial intelligence interface that provides services to the outside world through the HTTP protocol. It aims to equip developers with powerful natural language processing capabilities and AI models. Through the API, developers can achieve functions such as dialogue generation, language translation, text summarization, and code autocompletion.

Tip: This tutorial mainly explains the functionalities of the OpenAI API using the HTTP interface protocol.

2. Introduction to Officially Supported SDKs

2.1 Installation and Basic Usage of Python SDK

OpenAI provides an official Python SDK, which can be installed using the pip package management tool. The installation command is as follows:

pip install openai

After installation, you can use the following sample code for basic usage:

from openai import OpenAI
client = OpenAI(
    api_key = "your_api_key"
)

chat_completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Hello world"}]
)

The above sample code demonstrates how to create an OpenAI client and use it for dialogue generation. In actual usage, you need to replace your_api_key with your own API key and further understand the usage methods of various functionalities based on the API documentation.

2.2 TypeScript/JavaScript SDK

OpenAI also provides a TypeScript/JavaScript SDK, suitable for the Node.js environment, which can be installed using npm or yarn. Here is an example installation command:

npm install --save openai

After installation, you can use the following sample code for basic usage:

import OpenAI from 'openai';

const openai = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
});

const chatCompletion = await openai.chat.completions.create({
    messages: [{ role: 'user', content: 'Say this is a test' }],
    model: 'gpt-3.5-turbo',
});

Before using it, please make sure the OPENAI_API_KEY environment variable is set up, and further understand the usage methods of various functionalities based on the API documentation.

2.3 Azure OpenAI SDK

The Microsoft Azure team maintains SDKs that are compatible with the OpenAI API and Azure OpenAI services. You can refer to the related documentation through the following links:

Here are the community-supported SDKs and their respective links: