OpenAI 통합

OpenAI 통합

LangChain JavaScript로 OpenAI LLM과 통합하는 방법을 알아봅니다.

OpenAI는 인공지능(AI) 연구 기관이에요. LangChain으로 OpenAI 완성 모델(LLM)을 시작하는 데 도움을 주는 가이드입니다. OpenAI 기능과 구성 옵션에 대한 자세한 문서는 API reference를 참조하세요.

출처: 문서

본문

현재 이 페이지는 OpenAI 텍스트 완성 모델 사용법을 다루는 문서예요. 최신이자 가장 인기 있는 OpenAI 모델은 챗 완성 모델입니다.

특별히 gpt-3.5-turbo-instruct를 사용하지 않는다면, 아마 이 페이지를 찾고 계실 거예요.

개요

통합 세부 정보

클래스(Class) 패키지(Package) 로컬(Local) 직렬화(Serializable) PY 지원 다운로드(Downloads) 버전(Version)
OpenAI @langchain/openai NPM - Downloads NPM - Version

설정

OpenAI 모델에 접근하려면 OpenAI 계정을 만들고 API 키를 발급받은 뒤 @langchain/openai 통합 패키지를 설치해야 합니다.

자격 증명(Credentials)

platform.openai.com에 방문해 OpenAI에 가입하고 API 키를 생성하세요. 완료되면 OPENAI_API_KEY 환경 변수를 설정하세요:

export OPENAI_API_KEY="your-api-key"

모델 호출에 대한 자동 추적을 받으려면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있습니다:

# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

설치

LangChain OpenAI 통합은 @langchain/openai 패키지에 있습니다:

npm install @langchain/openai @langchain/core
yarn add @langchain/openai @langchain/core
pnpm add @langchain/openai @langchain/core

인스턴스화(Instantiation)

이제 모델을 인스턴스화하고 텍스트 완성을 생성할 수 있습니다:

import { OpenAI } from "@langchain/openai"

const llm = new OpenAI({
  model: "gpt-3.5-turbo-instruct",
  temperature: 0,
  maxTokens: undefined,
  timeout: undefined,
  maxRetries: 2,
  apiKey: proces...KEY,
  // other params...
})

호출(Invocation)

const inputText = "OpenAI is an AI company that "

const completion = await llm.invoke(inputText)
completion
develops and promotes friendly AI for the benefit of humanity. It was founded in 2015 by Elon Musk, Sam Altman, Greg Brockman, Ilya Sutskever, Wojciech Zaremba, John Schulman, and Chris Olah. The company's mission is to create and promote artificial general intelligence (AGI) that is safe and beneficial to humanity.

OpenAI conducts research in various areas of AI, including deep learning, reinforcement learning, robotics, and natural language processing. The company also develops and releases open-source tools and platforms for AI research, such as the GPT-3 language model and the Gym toolkit for reinforcement learning.

One of the main goals of OpenAI is to ensure that the development of AI is aligned with human values and does not pose a threat to humanity. To this end, the company has established a set of principles for safe and ethical AI development, and it actively collaborates with other organizations and researchers in the field.

OpenAI has received funding from various sources, including tech giants like Microsoft and Amazon, as well as individual investors. It has also partnered with companies and organizations such as Google, IBM, and the United Nations to advance its research and promote responsible AI development.

In addition to its research and development

커스텀 URL

configuration 파라미터를 전달해 SDK가 요청을 보내는 base URL을 커스터마이즈할 수 있습니다:

const llmCustomURL = new OpenAI({
  temperature: 0.9,
  configuration: {
    baseURL: "https://your_custom_url.com",
  },
});

공식 SDK가 허용하는 다른 ClientOptions 파라미터도 전달할 수 있습니다.

Azure OpenAI에서 호스팅한다면 전용 페이지를 대신 참조하세요.


API reference

모든 OpenAI 기능과 구성에 대한 자세한 문서는 API reference를 참조하세요.

더 알아보기 (Learn more)