Copy
---
title: OpenAI Adapter
---
**OpenAI 라이브러리 버전이 1.0.0 이상인지 확인하세요. 그렇지 않은 경우 이전 문서 [OpenAI Adapter(Old)](/oss/python/integrations/adapters/openai-old/)를 참조하세요.**
많은 사람들이 OpenAI로 시작하지만 다른 모델을 탐색하고 싶어합니다. LangChain은 여러 모델 제공자와의 통합을 통해 이를 쉽게 할 수 있도록 합니다. LangChain은 자체 message 및 model API를 가지고 있지만, LangChain 모델을 OpenAI API에 적응시키는 adapter를 제공하여 다른 모델을 최대한 쉽게 탐색할 수 있도록 했습니다.
현재 이것은 출력만 처리하며 다른 정보(token 수, 중지 이유 등)는 반환하지 않습니다.
```python
import openai
from langchain_community.adapters import openai as lc_openai
chat.completions.create
Copy
messages = [{"role": "user", "content": "hi"}]
Copy
result = openai.chat.completions.create(
messages=messages, model="gpt-3.5-turbo", temperature=0
)
result.choices[0].message.model_dump()
Copy
{'content': 'Hello! How can I assist you today?',
'role': 'assistant',
'function_call': None,
'tool_calls': None}
Copy
lc_result = lc_openai.chat.completions.create(
messages=messages, model="gpt-3.5-turbo", temperature=0
)
lc_result.choices[0].message # Attribute access
Copy
{'role': 'assistant', 'content': 'Hello! How can I help you today?'}
Copy
lc_result["choices"][0]["message"] # Also compatible with index access
Copy
{'role': 'assistant', 'content': 'Hello! How can I help you today?'}
Copy
lc_result = lc_openai.chat.completions.create(
messages=messages, model="claude-2", temperature=0, provider="ChatAnthropic"
)
lc_result.choices[0].message
Copy
{'role': 'assistant', 'content': 'Hello! How can I assist you today?'}
chat.completions.stream
원본 OpenAI 호출Copy
for c in openai.chat.completions.create(
messages=messages, model="gpt-3.5-turbo", temperature=0, stream=True
):
print(c.choices[0].delta.model_dump())
Copy
{'content': '', 'function_call': None, 'role': 'assistant', 'tool_calls': None}
{'content': 'Hello', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': '!', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': ' How', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': ' can', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': ' I', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': ' assist', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': ' you', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': ' today', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': '?', 'function_call': None, 'role': None, 'tool_calls': None}
{'content': None, 'function_call': None, 'role': None, 'tool_calls': None}
Copy
for c in lc_openai.chat.completions.create(
messages=messages, model="gpt-3.5-turbo", temperature=0, stream=True
):
print(c.choices[0].delta)
Copy
{'role': 'assistant', 'content': ''}
{'content': 'Hello'}
{'content': '!'}
{'content': ' How'}
{'content': ' can'}
{'content': ' I'}
{'content': ' assist'}
{'content': ' you'}
{'content': ' today'}
{'content': '?'}
{}
Copy
for c in lc_openai.chat.completions.create(
messages=messages,
model="claude-2",
temperature=0,
stream=True,
provider="ChatAnthropic",
):
print(c["choices"][0]["delta"])
Copy
{'role': 'assistant', 'content': ''}
{'content': 'Hello'}
{'content': '!'}
{'content': ' How'}
{'content': ' can'}
{'content': ' I'}
{'content': ' assist'}
{'content': ' you'}
{'content': ' today'}
{'content': '?'}
{}
Copy
---
<Callout icon="pen-to-square" iconType="regular">
[Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/adapters/openai.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
[Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>