langchain/libs/partners/openai
Marlene 4fa3ef0d55
Community/Partner: Adding Azure community and partner user agent to better track usage in Python (#29561)
- This pull request includes various changes to add a `user_agent`
parameter to Azure OpenAI, Azure Search and Whisper in the Community and
Partner packages. This helps in identifying the source of API requests
so we can better track usage and help support the community better. I
will also be adding the user_agent to the new `langchain-azure` repo as
well.

- No issue connected or  updated dependencies. 
- Utilises existing tests and docs

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2025-02-07 23:28:30 +00:00
..
langchain_openai Community/Partner: Adding Azure community and partner user agent to better track usage in Python (#29561) 2025-02-07 23:28:30 +00:00
scripts multiple: pydantic 2 compatibility, v0.3 (#26443) 2024-09-13 14:38:45 -07:00
tests openai: Removed tool_calls from completion chunk after other chunks have already been sent. (#29649) 2025-02-07 10:15:52 -05:00
.gitignore openai: audio modality, remove sockets from unit tests (#27436) 2024-10-18 08:02:09 -07:00
LICENSE openai[minor]: implement langchain-openai package (#15503) 2024-01-05 15:03:28 -08:00
Makefile infra: add UV_FROZEN to makefiles (#29642) 2025-02-06 14:36:54 -05:00
pyproject.toml openai: release 0.3.4 (#29652) 2025-02-06 17:02:21 -05:00
README.md docs: Update openai README.md (#29146) 2025-01-10 17:24:16 -08:00
uv.lock openai: release 0.3.4 (#29652) 2025-02-06 17:02:21 -05:00

langchain-openai

This package contains the LangChain integrations for OpenAI through their openai SDK.

Installation and Setup

  • Install the LangChain partner package
pip install langchain-openai
  • Get an OpenAI api key and set it as an environment variable (OPENAI_API_KEY)

Chat model

See a usage example.

from langchain_openai import ChatOpenAI

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureChatOpenAI

For a more detailed walkthrough of the Azure wrapper, see here

Text Embedding Model

See a usage example

from langchain_openai import OpenAIEmbeddings

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureOpenAIEmbeddings

For a more detailed walkthrough of the Azure wrapper, see here

LLM (Legacy)

LLM refers to the legacy text-completion models that preceded chat models. See a usage example.

from langchain_openai import OpenAI

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureOpenAI

For a more detailed walkthrough of the Azure wrapper, see here