Home / Function/ test_audio_inputs() — langchain Function Reference

test_audio_inputs() — langchain Function Reference

Architecture documentation for the test_audio_inputs() function in chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c7be2f2e_b4e7_5993_9336_e4040cb24467["test_audio_inputs()"]
  971e928f_9c9b_ce7a_b93d_e762f2f5aa54["ChatModelIntegrationTests"]
  c7be2f2e_b4e7_5993_9336_e4040cb24467 -->|defined in| 971e928f_9c9b_ce7a_b93d_e762f2f5aa54
  a116da61_b432_7c0f_6f42_237547519f1f["_get_base64_from_url()"]
  c7be2f2e_b4e7_5993_9336_e4040cb24467 -->|calls| a116da61_b432_7c0f_6f42_237547519f1f
  style c7be2f2e_b4e7_5993_9336_e4040cb24467 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/standard-tests/langchain_tests/integration_tests/chat_models.py lines 2621–2714

    def test_audio_inputs(self, model: BaseChatModel) -> None:
        """Test that the model can process audio inputs.

        This test should be skipped (see configuration below) if the model does not
        support audio inputs. These will take the shape of the LangChain
        `AudioContentBlock`:

        ```python
        {
            "type": "audio",
            "base64": "<base64 audio data>",
            "mime_type": "audio/wav",  # or appropriate MIME type
        }
        ```

        Furthermore, for backward-compatibility, we must also support OpenAI chat
        completions audio content blocks:

        ```python
        {
            "type": "input_audio",
            "input_audio": {
                "data": "<base64 audio data>",
                "format": "wav",  # or appropriate format
            },
        }
        ```

        Note: this test downloads audio data from wikimedia.org. You may need to set
        the `LANGCHAIN_TESTS_USER_AGENT` environment variable to identify these
        requests, e.g.,

        ```bash
        export LANGCHAIN_TESTS_USER_AGENT="CoolBot/0.0 (https://example.org/coolbot/; coolbot@example.org) generic-library/0.0"
        ```

        Refer to the [Wikimedia Foundation User-Agent Policy](https://foundation.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy).

        ??? note "Configuration"

            To disable this test, set `supports_audio_inputs` to `False` in your
            test class:

            ```python
            class TestMyChatModelIntegration(ChatModelIntegrationTests):
                @property
                def supports_audio_inputs(self) -> bool:
                    return False
            ```

        ??? question "Troubleshooting"

            If this test fails, check that the model can correctly handle messages
            with audio content blocks, specifically base64-encoded files. Otherwise,
            set the `supports_audio_inputs` property to `False`.

        """  # noqa: E501
        if not self.supports_audio_inputs:
            pytest.skip("Model does not support audio inputs.")

        # https://commons.wikimedia.org/wiki/File:Northern_Flicker_202280456.wav
        # License: CC0 1.0 Universal
        url = "https://upload.wikimedia.org/wikipedia/commons/6/6a/Northern_Flicker_202280456.wav"
        audio_data = _get_base64_from_url(url)

        message = HumanMessage(
            [
                {
                    "type": "text",
                    "text": "Describe this audio:",
                },
                {
                    "type": "audio",
                    "mime_type": "audio/wav",
                    "base64": audio_data,
                },
            ]
        )
        _ = model.invoke([message])

        # Test OpenAI Chat Completions format

Domain

Subdomains

Frequently Asked Questions

What does test_audio_inputs() do?
test_audio_inputs() is a function in the langchain codebase, defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py.
Where is test_audio_inputs() defined?
test_audio_inputs() is defined in libs/standard-tests/langchain_tests/integration_tests/chat_models.py at line 2621.
What does test_audio_inputs() call?
test_audio_inputs() calls 1 function(s): _get_base64_from_url.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free