OpenAI
features and configuration options, please refer to the API reference.
Overview
Integration details
Class | Package | Local | Serializable | PY support | Downloads | Version |
---|---|---|---|---|---|---|
OpenAI | @langchain/openai | ❌ | ✅ | ✅ |
Setup
To access OpenAI models you’ll need to create an OpenAI account, get an API key, and install the@langchain/openai
integration package.
Credentials
Head to platform.openai.com to sign up to OpenAI and generate an API key. Once you’ve done this set theOPENAI_API_KEY
environment variable:
Installation
The LangChain OpenAI integration lives in the@langchain/openai
package:
Instantiation
Now we can instantiate our model object and generate chat completions:Invocation
Chaining
We can chain our completion model with a prompt template like so:process.env.OPENAI_ORGANIZATION
to your OpenAI organization id, or pass it in as organization
when
initializing the model.
Custom URLs
You can customize the base URL the SDK sends requests to by passing aconfiguration
parameter like this:
ClientOptions
parameters accepted by the official SDK.
If you are hosting on Azure OpenAI, see the dedicated page instead.