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

Class OpenAI

libs/partners/openai/langchain_openai/llms/base.py:599–646  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

597
598
599class 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

Callers 15

create_chainFunction · 0.90
validate_environmentMethod · 0.90
test_streamFunction · 0.90
test_astreamFunction · 0.90
test_abatchFunction · 0.90
test_abatch_tagsFunction · 0.90
test_batchFunction · 0.90
test_ainvokeFunction · 0.90
test_invokeFunction · 0.90
test_openai_callFunction · 0.90
test_openai_stop_validFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_streamFunction · 0.72
test_astreamFunction · 0.72
test_abatchFunction · 0.72
test_abatch_tagsFunction · 0.72
test_batchFunction · 0.72
test_ainvokeFunction · 0.72
test_invokeFunction · 0.72
test_openai_callFunction · 0.72
test_openai_stop_validFunction · 0.72
test_openai_streamingFunction · 0.72
test_openai_astreamFunction · 0.72