Skip to main content

OpenAI

All functionality related to OpenAI

OpenAI is American artificial intelligence (AI) research laboratory consisting of the non-profit OpenAI Incorporated and its for-profit subsidiary corporation OpenAI Limited Partnership. OpenAI conducts AI research with the declared intention of promoting and developing a friendly AI. OpenAI systems run on an Azure-based supercomputing platform from Microsoft.

The OpenAI API is powered by a diverse set of models with different capabilities and price points.

ChatGPT is the Artificial Intelligence (AI) chatbot developed by OpenAI.

Installation and Setupโ€‹

Install the integration package with

pip install langchain-openai

Get an OpenAI api key and set it as an environment variable (OPENAI_API_KEY)

Chat modelโ€‹

See a usage example.

from langchain_openai import ChatOpenAI
API Reference:ChatOpenAI

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureChatOpenAI
API Reference:AzureChatOpenAI

For a more detailed walkthrough of the Azure wrapper, see here.

LLMโ€‹

See a usage example.

from langchain_openai import OpenAI
API Reference:OpenAI

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureOpenAI
API Reference:AzureOpenAI

For a more detailed walkthrough of the Azure wrapper, see here.

Embedding Modelโ€‹

See a usage example

from langchain_openai import OpenAIEmbeddings
API Reference:OpenAIEmbeddings

Document Loaderโ€‹

See a usage example.

from langchain_community.document_loaders.chatgpt import ChatGPTLoader
API Reference:ChatGPTLoader

Retrieverโ€‹

See a usage example.

from langchain.retrievers import ChatGPTPluginRetriever

Toolsโ€‹

Dall-E Image Generatorโ€‹

OpenAI Dall-E are text-to-image models developed by OpenAI using deep learning methodologies to generate digital images from natural language descriptions, called "prompts".

See a usage example.

from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
API Reference:DallEAPIWrapper

Adapterโ€‹

See a usage example.

from langchain.adapters import openai as lc_openai

Tokenizerโ€‹

There are several places you can use the tiktoken tokenizer. By default, it is used to count tokens for OpenAI LLMs.

You can also use it to count tokens when splitting documents with

from langchain.text_splitter import CharacterTextSplitter
CharacterTextSplitter.from_tiktoken_encoder(...)
API Reference:CharacterTextSplitter

For a more detailed walkthrough of this, see this notebook

Chainโ€‹

See a usage example.

from langchain.chains import OpenAIModerationChain
API Reference:OpenAIModerationChain

Was this page helpful?


You can also leave detailed feedback on GitHub.