Skip to main content
You are currently on a page documenting the use of OpenAI text completion models. The latest and most popular OpenAI models are chat completion models.Unless you are specifically using gpt-3.5-turbo-instruct, you are probably looking for this page instead.
OpenAI 是一个人工智能 (AI) 研究实验室。 This will help you get started with OpenAI completion models (LLMs) using LangChain. For detailed documentation on OpenAI features and configuration options, please refer to the API reference.

概述

集成详情

设置

要访问 OpenAI models,你需要create an OpenAI account, get an API key, and install the @langchain/openai integration package.

凭证

前往 platform.openai.com 注册 OpenAI 并生成 API 密钥。完成后设置 OPENAI_API_KEY 环境变量:
如果你想要自动追踪模型调用,还可以设置你的 LangSmith API 密钥,取消注释以下内容:

安装

LangChain 的 OpenAI 集成位于 @langchain/openai 包中:

实例化

现在我们可以实例化模型对象并生成聊天补全:

调用

自定义 URL

You can customize the base URL the SDK sends requests to by passing a configuration parameter like this:
You can also pass other ClientOptions parameters accepted by the official SDK. If you are hosting on Azure OpenAI, see the dedicated page instead.

API 参考

有关所有 OpenAI 功能和配置的详细文档,请前往 API 参考