OpenAI large language models. To use, you should have the environment variable ``OPENAI_API_KEY`` set with your API key, or pass it as a named parameter to the constructor. Any parameters that are valid to be passed to the openai.create call can be passed in, even if not explicitly
| 597 | |
| 598 | |
| 599 | class OpenAI(BaseOpenAI): |
| 600 | """OpenAI large language models. |
| 601 | |
| 602 | To use, you should have the environment variable ``OPENAI_API_KEY`` |
| 603 | set with your API key, or pass it as a named parameter to the constructor. |
| 604 | |
| 605 | Any parameters that are valid to be passed to the openai.create call can be passed |
| 606 | in, even if not explicitly saved on this class. |
| 607 | |
| 608 | Example: |
| 609 | .. code-block:: python |
| 610 | |
| 611 | from langchain_openai import OpenAI |
| 612 | |
| 613 | model = OpenAI(model_name="gpt-3.5-turbo-instruct") |
| 614 | """ |
| 615 | |
| 616 | @classmethod |
| 617 | def get_lc_namespace(cls) -> List[str]: |
| 618 | """Get the namespace of the langchain object.""" |
| 619 | return ["langchain", "llms", "openai"] |
| 620 | |
| 621 | @classmethod |
| 622 | def is_lc_serializable(cls) -> bool: |
| 623 | """Return whether this model can be serialized by Langchain.""" |
| 624 | return True |
| 625 | |
| 626 | @property |
| 627 | def _invocation_params(self) -> Dict[str, Any]: |
| 628 | return {**{"model": self.model_name}, **super()._invocation_params} |
| 629 | |
| 630 | @property |
| 631 | def lc_secrets(self) -> Dict[str, str]: |
| 632 | return {"openai_api_key": "OPENAI_API_KEY"} |
| 633 | |
| 634 | @property |
| 635 | def lc_attributes(self) -> Dict[str, Any]: |
| 636 | attributes: Dict[str, Any] = {} |
| 637 | if self.openai_api_base: |
| 638 | attributes["openai_api_base"] = self.openai_api_base |
| 639 | |
| 640 | if self.openai_organization: |
| 641 | attributes["openai_organization"] = self.openai_organization |
| 642 | |
| 643 | if self.openai_proxy: |
| 644 | attributes["openai_proxy"] = self.openai_proxy |
| 645 | |
| 646 | return attributes |
no outgoing calls