For legacy compatibility. Use ChatOpenAI instead.

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

To use you should have the openai package installed, with the OPENAI_API_KEY environment variable set.

To use with Azure you should have the openai package installed, with the AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_INSTANCE_NAME, AZURE_OPENAI_API_DEPLOYMENT_NAME and AZURE_OPENAI_API_VERSION environment variable set.

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

const model = new OpenAIChat({
prefixMessages: [
{
role: "system",
content: "You are a helpful assistant that answers in pirate language",
},
],
maxTokens: 50,
});

const res = await model.invoke(
"What would be a good company name for a company that makes colorful socks?"
);
console.log({ res });

Hierarchy (view full)

Implements

Constructors

Constructors