Skip to main content
`Ctrl`+`K`

# Chat Models

pydantic model langchain.chat_models.AzureChatOpenAI

  Wrapper around Azure OpenAI Chat Completion API. To use this class you must have a deployed model on Azure OpenAI. Use deployment_name in the constructor to refer to the “Model deployment name” in the Azure portal.

  In addition, you should have the `openai` python package installed, and the following environment variables set or passed in constructor in lower case: - `OPENAI_API_TYPE` (default: `azure`) - `OPENAI_API_KEY` - `OPENAI_API_BASE` - `OPENAI_API_VERSION`

  For exmaple, if you have gpt-35-turbo deployed, with the deployment name 35-turbo-dev, the constructor should look like:

  Be aware the API version may change.

  Any parameters that are valid to be passed to the openai.create call can be passed in, even if not explicitly saved on this class.

  Validators

    - `build_extra` » `all fields`

    - `set_callback_manager` » `callback_manager`

    - `validate_environment` » `all fields`

  field deployment_name: str = ''
  field openai_api_base: str = ''
  field openai_api_key: str = ''
  field openai_api_type: str = 'azure'
  field openai_api_version: str = ''
  field openai_organization: str = ''

pydantic model langchain.chat_models.ChatAnthropic

  Wrapper around Anthropic’s large language model.

  To use, you should have the `anthropic` python package installed, and the environment variable `ANTHROPIC_API_KEY` set with your API key, or pass it as a named parameter to the constructor.

  Example

  Validators

    - `set_callback_manager` » `callback_manager`

    - `validate_environment` » `all fields`

  field callback_manager: langchain.callbacks.base.BaseCallbackManager [Optional]
  field verbose: bool [Optional]

    Whether to print out response text.

pydantic model langchain.chat_models.ChatOpenAI

  Wrapper around OpenAI Chat large language models.

  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 explicitly saved on this class.

  Example

      from langchain.chat_models import ChatOpenAI
      openai = ChatOpenAI(model_name="gpt-3.5-turbo")

  Validators

    - `build_extra` » `all fields`

    - `set_callback_manager` » `callback_manager`

    - `validate_environment` » `all fields`

  field max_retries: int = 6

    Maximum number of retries to make when generating.

  field max_tokens: Optional[int] = None

    Maximum number of tokens to generate.

  field model_kwargs: Dict[str, Any] [Optional]

    Holds any model parameters valid for create call not explicitly specified.

  field model_name: str = 'gpt-3.5-turbo'

    Model name to use.

  field n: int = 1

    Number of chat completions to generate for each prompt.

  field openai_api_key: Optional[str] = None
  field openai_organization: Optional[str] = None
  field request_timeout: int = 60

    Timeout in seconds for the OpenAPI request.

  field streaming: bool = False

    Whether to stream the results or not.

  field temperature: float = 0.7

    What sampling temperature to use.

  completion_with_retry(**kwargs: Any) → Any

    Use tenacity to retry the completion call.

  get_num_tokens(text: str) → int

    Calculate num tokens with tiktoken package.

  get_num_tokens_from_messages(messages: List[langchain.schema.BaseMessage]) → int

    Calculate num tokens for gpt-3.5-turbo and gpt-4 with tiktoken package.

    Official documentation: openai/openai-cookbook main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb

pydantic model langchain.chat_models.PromptLayerChatOpenAI

  Wrapper around OpenAI Chat large language models and PromptLayer.

  To use, you should have the `openai` and `promptlayer` python package installed, and the environment variable `OPENAI_API_KEY` and `PROMPTLAYER_API_KEY` set with your openAI API key and promptlayer key respectively.

  All parameters that can be passed to the OpenAI LLM can also be passed here. The PromptLayerChatOpenAI adds to optional :param `pl_tags`: List of strings to tag the request with. :param `return_pl_id`: If True, the PromptLayer request ID will be

  > returned in the `generation_info` field of the `Generation` object.

  Example

      from langchain.chat_models import PromptLayerChatOpenAI
      openai = PromptLayerChatOpenAI(model_name="gpt-3.5-turbo")

  Validators

    - `build_extra` » `all fields`

    - `set_callback_manager` » `callback_manager`

    - `validate_environment` » `all fields`

  field pl_tags: Optional[List[str]] = None
  field return_pl_id: Optional[bool] = False