Wrapper around OpenAI large language models that use the Chat endpoint.

To use you should have the OPENAI_API_KEY environment variable set.

To use with Azure you should have the: AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_INSTANCE_NAME, AZURE_OPENAI_API_DEPLOYMENT_NAME and AZURE_OPENAI_API_VERSION environment variables set. AZURE_OPENAI_BASE_PATH is optional and will override AZURE_OPENAI_API_INSTANCE_NAME if you need to use a custom endpoint.

Any parameters that are valid to be passed to openai.createChatCompletion can be passed through modelKwargs, even if not explicitly available on this class.

// Create a new instance of ChatOpenAI with specific temperature and model name settings
const model = new ChatOpenAI({
temperature: 0.9,
model: "ft:gpt-3.5-turbo-0613:{ORG_NAME}::{MODEL_ID}",
});

// Invoke the model with a message and await the response
const message = await model.invoke("Hi there!");

// Log the response to the console
console.log(message);

Hierarchy (view full)

Constructors

Methods