test_base.py — langchain Source File
Architecture documentation for test_base.py, a python file in the langchain codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8a6d5332_62df_10bf_dacc_92ebb46285a4["test_base.py"] 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c["os"] 8a6d5332_62df_10bf_dacc_92ebb46285a4 --> 9e98f0a7_ec6e_708f_4f1b_e9428b316e1c 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 8a6d5332_62df_10bf_dacc_92ebb46285a4 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"] 8a6d5332_62df_10bf_dacc_92ebb46285a4 --> 525a7d6f_f455_56e3_854a_c8a7da4a1417 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] 8a6d5332_62df_10bf_dacc_92ebb46285a4 --> 120e2591_3e15_b895_72b6_cb26195e40a6 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] 8a6d5332_62df_10bf_dacc_92ebb46285a4 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 0b28cff6_d823_1571_d2bb_ec61508cc89c["langchain_openai"] 8a6d5332_62df_10bf_dacc_92ebb46285a4 --> 0b28cff6_d823_1571_d2bb_ec61508cc89c style 8a6d5332_62df_10bf_dacc_92ebb46285a4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import os
from typing import Any
from unittest.mock import Mock, patch
import pytest
from pydantic import SecretStr
from langchain_openai import OpenAIEmbeddings
os.environ["OPENAI_API_KEY"] = "foo"
def test_openai_invalid_model_kwargs() -> None:
with pytest.raises(ValueError):
OpenAIEmbeddings(model_kwargs={"model": "foo"})
def test_openai_incorrect_field() -> None:
with pytest.warns(match="not default parameter"):
llm = OpenAIEmbeddings(foo="bar") # type: ignore[call-arg]
assert llm.model_kwargs == {"foo": "bar"}
def test_embed_documents_with_custom_chunk_size() -> None:
embeddings = OpenAIEmbeddings(chunk_size=2)
texts = ["text1", "text2", "text3", "text4"]
custom_chunk_size = 3
with patch.object(embeddings.client, "create") as mock_create:
mock_create.side_effect = [
{"data": [{"embedding": [0.1, 0.2]}, {"embedding": [0.3, 0.4]}]},
{"data": [{"embedding": [0.5, 0.6]}, {"embedding": [0.7, 0.8]}]},
]
result = embeddings.embed_documents(texts, chunk_size=custom_chunk_size)
_, tokens, __, ___ = embeddings._tokenize(texts, custom_chunk_size)
mock_create.call_args
mock_create.assert_any_call(input=tokens[0:3], **embeddings._invocation_params)
mock_create.assert_any_call(input=tokens[3:4], **embeddings._invocation_params)
assert result == [[0.1, 0.2], [0.3, 0.4], [0.5, 0.6], [0.7, 0.8]]
def test_embed_documents_with_custom_chunk_size_no_check_ctx_length() -> None:
embeddings = OpenAIEmbeddings(chunk_size=2, check_embedding_ctx_length=False)
texts = ["text1", "text2", "text3", "text4"]
custom_chunk_size = 3
with patch.object(embeddings.client, "create") as mock_create:
mock_create.side_effect = [
{"data": [{"embedding": [0.1, 0.2]}, {"embedding": [0.3, 0.4]}]},
{"data": [{"embedding": [0.5, 0.6]}, {"embedding": [0.7, 0.8]}]},
]
result = embeddings.embed_documents(texts, chunk_size=custom_chunk_size)
mock_create.call_args
mock_create.assert_any_call(input=texts[0:3], **embeddings._invocation_params)
mock_create.assert_any_call(input=texts[3:4], **embeddings._invocation_params)
// ... (91 more lines)
Domain
Subdomains
Functions
Dependencies
- langchain_openai
- os
- pydantic
- pytest
- typing
- unittest.mock
Source
Frequently Asked Questions
What does test_base.py do?
test_base.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in test_base.py?
test_base.py defines 7 function(s): test_embed_documents_with_custom_chunk_size, test_embed_documents_with_custom_chunk_size_no_check_ctx_length, test_embed_with_kwargs, test_embed_with_kwargs_async, test_embeddings_respects_token_limit, test_openai_incorrect_field, test_openai_invalid_model_kwargs.
What does test_base.py depend on?
test_base.py imports 6 module(s): langchain_openai, os, pydantic, pytest, typing, unittest.mock.
Where is test_base.py in the architecture?
test_base.py is located at libs/partners/openai/tests/unit_tests/embeddings/test_base.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/partners/openai/tests/unit_tests/embeddings).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free