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

Class ChatOpenAI

libs/community/langchain_community/chat_models/openai.py:151–688  ·  view source on GitHub ↗

`OpenAI` Chat large language models API. To use, you should have the ``openai`` python package installed, and the environment variable ``OPENAI_API_KEY`` set with your API key. Any parameters that are valid to be passed to the openai.create call can be passed in, even if not explic

Source from the content-addressed store, hash-verified

149 since="0.0.10", removal="0.3.0", alternative_import="langchain_openai.ChatOpenAI"
150)
151class ChatOpenAI(BaseChatModel):
152 """`OpenAI` Chat large language models API.
153
154 To use, you should have the ``openai`` python package installed, and the
155 environment variable ``OPENAI_API_KEY`` set with your API key.
156
157 Any parameters that are valid to be passed to the openai.create call can be passed
158 in, even if not explicitly saved on this class.
159
160 Example:
161 .. code-block:: python
162
163 from langchain_community.chat_models import ChatOpenAI
164 openai = ChatOpenAI(model="gpt-3.5-turbo")
165 """
166
167 @property
168 def lc_secrets(self) -> Dict[str, str]:
169 return {"openai_api_key": "OPENAI_API_KEY"}
170
171 @classmethod
172 def get_lc_namespace(cls) -> List[str]:
173 """Get the namespace of the langchain object."""
174 return ["langchain", "chat_models", "openai"]
175
176 @property
177 def lc_attributes(self) -> Dict[str, Any]:
178 attributes: Dict[str, Any] = {}
179
180 if self.openai_organization:
181 attributes["openai_organization"] = self.openai_organization
182
183 if self.openai_api_base:
184 attributes["openai_api_base"] = self.openai_api_base
185
186 if self.openai_proxy:
187 attributes["openai_proxy"] = self.openai_proxy
188
189 return attributes
190
191 @classmethod
192 def is_lc_serializable(cls) -> bool:
193 """Return whether this model can be serialized by Langchain."""
194 return True
195
196 client: Any = Field(default=None, exclude=True) #: :meta private:
197 async_client: Any = Field(default=None, exclude=True) #: :meta private:
198 model_name: str = Field(default="gpt-3.5-turbo", alias="model")
199 """Model name to use."""
200 temperature: float = 0.7
201 """What sampling temperature to use."""
202 model_kwargs: Dict[str, Any] = Field(default_factory=dict)
203 """Holds any model parameters valid for `create` call not explicitly specified."""
204 # When updating this to use a SecretStr
205 # Check for classes that derive from this class (as some of them
206 # may assume openai_api_key is a str)
207 openai_api_key: Optional[str] = Field(default=None, alias="api_key")
208 """Automatically inferred from env var `OPENAI_API_KEY` if not provided."""

Callers 15

llm_with_toolsFunction · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
image_summarizeFunction · 0.90
chain.pyFile · 0.90
agent.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
chain.pyFile · 0.90
image_summarizeFunction · 0.90
multi_modal_rag_chainFunction · 0.90
chain.pyFile · 0.90

Calls

no outgoing calls