Home / Function/ test_callable_api_key_async() — langchain Function Reference

test_callable_api_key_async() — langchain Function Reference

Architecture documentation for the test_callable_api_key_async() function in test_base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  bfbf8a9f_bf5a_d5ec_9eb3_4c127198ba51["test_callable_api_key_async()"]
  9bf2a9b0_094e_e5e3_a0fa_faa0fc8514e5["test_base.py"]
  bfbf8a9f_bf5a_d5ec_9eb3_4c127198ba51 -->|defined in| 9bf2a9b0_094e_e5e3_a0fa_faa0fc8514e5
  style bfbf8a9f_bf5a_d5ec_9eb3_4c127198ba51 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/tests/integration_tests/embeddings/test_base.py lines 93–125

async def test_callable_api_key_async(monkeypatch: pytest.MonkeyPatch) -> None:
    original_key = os.environ["OPENAI_API_KEY"]

    calls = {"sync": 0, "async": 0}

    def get_openai_api_key() -> str:
        calls["sync"] += 1
        return original_key

    async def get_openai_api_key_async() -> str:
        calls["async"] += 1
        return original_key

    monkeypatch.delenv("OPENAI_API_KEY")

    model = OpenAIEmbeddings(
        model="text-embedding-3-small", dimensions=128, api_key=get_openai_api_key
    )
    _ = model.embed_query("hello")
    assert calls["sync"] == 1

    _ = await model.aembed_query("hello")
    assert calls["sync"] == 2

    model = OpenAIEmbeddings(
        model="text-embedding-3-small", dimensions=128, api_key=get_openai_api_key_async
    )
    _ = await model.aembed_query("hello")
    assert calls["async"] == 1

    with pytest.raises(ValueError):
        # We do not create a sync callable from an async one
        _ = model.embed_query("hello")

Domain

Subdomains

Frequently Asked Questions

What does test_callable_api_key_async() do?
test_callable_api_key_async() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/embeddings/test_base.py.
Where is test_callable_api_key_async() defined?
test_callable_api_key_async() is defined in libs/partners/openai/tests/integration_tests/embeddings/test_base.py at line 93.

Analyze Your Own Codebase

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

Try Supermodel Free