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.
Remarks
Any parameters that are valid to be passed to openai.createCompletion can be passed through modelKwargs, even
if not explicitly available on this class.
Example
constmodel = newOpenAIChat({ prefixMessages: [ { role:"system", content:"You are a helpful assistant that answers in pirate language", }, ], maxTokens:50, });
constres = awaitmodel.invoke( "What would be a good company name for a company that makes colorful socks?" ); console.log({ res });
Deprecated
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 theOPENAI_API_KEY
environment variable set.To use with Azure you should have the
openai
package installed, with theAZURE_OPENAI_API_KEY
,AZURE_OPENAI_API_INSTANCE_NAME
,AZURE_OPENAI_API_DEPLOYMENT_NAME
andAZURE_OPENAI_API_VERSION
environment variable set.Remarks
Any parameters that are valid to be passed to
openai.createCompletion
can be passed through modelKwargs, even if not explicitly available on this class.Example