MCPcopy
hub / github.com/langchain-ai/langchain / ChatOpenAI

Class ChatOpenAI

libs/partners/openai/langchain_openai/chat_models/base.py:1181–1694  ·  view source on GitHub ↗

OpenAI chat model integration. Setup: Install ``langchain-openai`` and set environment variable ``OPENAI_API_KEY``. .. code-block:: bash pip install -U langchain-openai export OPENAI_API_KEY="your-api-key" Key init args — completion params:

Source from the content-addressed store, hash-verified

1179
1180
1181class ChatOpenAI(BaseChatOpenAI):
1182 """OpenAI chat model integration.
1183
1184 Setup:
1185 Install ``langchain-openai`` and set environment variable ``OPENAI_API_KEY``.
1186
1187 .. code-block:: bash
1188
1189 pip install -U langchain-openai
1190 export OPENAI_API_KEY="your-api-key"
1191
1192 Key init args — completion params:
1193 model: str
1194 Name of OpenAI model to use.
1195 temperature: float
1196 Sampling temperature.
1197 max_tokens: Optional[int]
1198 Max number of tokens to generate.
1199 logprobs: Optional[bool]
1200 Whether to return logprobs.
1201 stream_options: Dict
1202 Configure streaming outputs, like whether to return token usage when
1203 streaming (``{"include_usage": True}``).
1204
1205 Key init args — client params:
1206 timeout: Union[float, Tuple[float, float], Any, None]
1207 Timeout for requests.
1208 max_retries: int
1209 Max number of retries.
1210 api_key: Optional[str]
1211 OpenAI API key. If not passed in will be read from env var OPENAI_API_KEY.
1212 base_url: Optional[str]
1213 Base URL for API requests. Only specify if using a proxy or service
1214 emulator.
1215 organization: Optional[str]
1216 OpenAI organization ID. If not passed in will be read from env
1217 var OPENAI_ORG_ID.
1218
1219 See full list of supported init args and their descriptions in the params section.
1220
1221 Instantiate:
1222 .. code-block:: python
1223
1224 from langchain_openai import ChatOpenAI
1225
1226 llm = ChatOpenAI(
1227 model="gpt-4o",
1228 temperature=0,
1229 max_tokens=None,
1230 timeout=None,
1231 max_retries=2,
1232 # api_key="...",
1233 # base_url="...",
1234 # organization="...",
1235 # other params...
1236 )
1237
1238 **NOTE**: Any param which is not explicitly supported will be passed directly to the

Callers 15

multi_modal_rag_chainFunction · 0.90
agent.pyFile · 0.90
chain.pyFile · 0.90
agent.pyFile · 0.90
ingest.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90

Calls

no outgoing calls