community[patch]: upgrade to recent version of mypy (#21616)

This PR upgrades community to a recent version of mypy. It inserts type:
ignore on all existing failures.
This commit is contained in:
Eugene Yurtsev
2024-05-13 14:55:07 -04:00
committed by GitHub
parent b923951062
commit 25fbe356b4
243 changed files with 718 additions and 710 deletions

View File

@@ -5,7 +5,7 @@ from langchain_community.embeddings.awa import AwaEmbeddings
def test_awa_embedding_documents() -> None:
"""Test Awa embeddings for documents."""
documents = ["foo bar", "test document"]
embedding = AwaEmbeddings()
embedding = AwaEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2
assert len(output[0]) == 768
@@ -14,6 +14,6 @@ def test_awa_embedding_documents() -> None:
def test_awa_embedding_query() -> None:
"""Test Awa embeddings for query."""
document = "foo bar"
embedding = AwaEmbeddings()
embedding = AwaEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 768

View File

@@ -17,7 +17,7 @@ DEPLOYMENT_NAME = os.environ.get(
def _get_embeddings(**kwargs: Any) -> AzureOpenAIEmbeddings:
return AzureOpenAIEmbeddings(
return AzureOpenAIEmbeddings( # type: ignore[call-arg]
azure_deployment=DEPLOYMENT_NAME,
api_version=OPENAI_API_VERSION,
openai_api_base=OPENAI_API_BASE,

View File

@@ -5,7 +5,7 @@ from langchain_community.embeddings.baichuan import BaichuanTextEmbeddings
def test_baichuan_embedding_documents() -> None:
"""Test Baichuan Text Embedding for documents."""
documents = ["今天天气不错", "今天阳光灿烂"]
embedding = BaichuanTextEmbeddings()
embedding = BaichuanTextEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2 # type: ignore[arg-type]
assert len(output[0]) == 1024 # type: ignore[index]
@@ -14,6 +14,6 @@ def test_baichuan_embedding_documents() -> None:
def test_baichuan_embedding_query() -> None:
"""Test Baichuan Text Embedding for query."""
document = "所有的小学生都会学过只因兔同笼问题。"
embedding = BaichuanTextEmbeddings()
embedding = BaichuanTextEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 1024 # type: ignore[arg-type]

View File

@@ -5,7 +5,7 @@ from langchain_community.embeddings.cohere import CohereEmbeddings
def test_cohere_embedding_documents() -> None:
"""Test cohere embeddings."""
documents = ["foo bar"]
embedding = CohereEmbeddings()
embedding = CohereEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 2048
@@ -14,6 +14,6 @@ def test_cohere_embedding_documents() -> None:
def test_cohere_embedding_query() -> None:
"""Test cohere embeddings."""
document = "foo bar"
embedding = CohereEmbeddings()
embedding = CohereEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 2048

View File

@@ -7,7 +7,7 @@ from langchain_community.embeddings.dashscope import DashScopeEmbeddings
def test_dashscope_embedding_documents() -> None:
"""Test dashscope embeddings."""
documents = ["foo bar"]
embedding = DashScopeEmbeddings(model="text-embedding-v1")
embedding = DashScopeEmbeddings(model="text-embedding-v1") # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 1536
@@ -45,7 +45,7 @@ def test_dashscope_embedding_documents_multiple() -> None:
"foo23",
"foo24",
]
embedding = DashScopeEmbeddings(model="text-embedding-v1")
embedding = DashScopeEmbeddings(model="text-embedding-v1") # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 28
assert len(output[0]) == 1536
@@ -56,7 +56,7 @@ def test_dashscope_embedding_documents_multiple() -> None:
def test_dashscope_embedding_query() -> None:
"""Test dashscope embeddings."""
document = "foo bar"
embedding = DashScopeEmbeddings(model="text-embedding-v1")
embedding = DashScopeEmbeddings(model="text-embedding-v1") # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 1536
@@ -66,7 +66,7 @@ def test_dashscope_embedding_with_empty_string() -> None:
import dashscope
document = ["", "abc"]
embedding = DashScopeEmbeddings(model="text-embedding-v1")
embedding = DashScopeEmbeddings(model="text-embedding-v1") # type: ignore[call-arg]
output = embedding.embed_documents(document)
assert len(output) == 2
assert len(output[0]) == 1536

View File

@@ -6,7 +6,7 @@ from langchain_community.embeddings.edenai import EdenAiEmbeddings
def test_edenai_embedding_documents() -> None:
"""Test edenai embeddings with openai."""
documents = ["foo bar", "test text"]
embedding = EdenAiEmbeddings(provider="openai")
embedding = EdenAiEmbeddings(provider="openai") # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2
assert len(output[0]) == 1536
@@ -16,6 +16,6 @@ def test_edenai_embedding_documents() -> None:
def test_edenai_embedding_query() -> None:
"""Test eden ai embeddings with google."""
document = "foo bar"
embedding = EdenAiEmbeddings(provider="google")
embedding = EdenAiEmbeddings(provider="google") # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 768

View File

@@ -15,10 +15,10 @@ def test_fastembed_embedding_documents(
) -> None:
"""Test fastembed embeddings for documents."""
documents = ["foo bar", "bar foo"]
embedding = FastEmbedEmbeddings(
embedding = FastEmbedEmbeddings( # type: ignore[call-arg]
model_name=model_name,
max_length=max_length,
doc_embed_type=doc_embed_type,
doc_embed_type=doc_embed_type, # type: ignore[arg-type]
threads=threads,
)
output = embedding.embed_documents(documents)
@@ -33,7 +33,7 @@ def test_fastembed_embedding_documents(
def test_fastembed_embedding_query(model_name: str, max_length: int) -> None:
"""Test fastembed embeddings for query."""
document = "foo bar"
embedding = FastEmbedEmbeddings(model_name=model_name, max_length=max_length)
embedding = FastEmbedEmbeddings(model_name=model_name, max_length=max_length) # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 384
@@ -49,10 +49,10 @@ async def test_fastembed_async_embedding_documents(
) -> None:
"""Test fastembed embeddings for documents."""
documents = ["foo bar", "bar foo"]
embedding = FastEmbedEmbeddings(
embedding = FastEmbedEmbeddings( # type: ignore[call-arg]
model_name=model_name,
max_length=max_length,
doc_embed_type=doc_embed_type,
doc_embed_type=doc_embed_type, # type: ignore[arg-type]
threads=threads,
)
output = await embedding.aembed_documents(documents)
@@ -69,6 +69,6 @@ async def test_fastembed_async_embedding_query(
) -> None:
"""Test fastembed embeddings for query."""
document = "foo bar"
embedding = FastEmbedEmbeddings(model_name=model_name, max_length=max_length)
embedding = FastEmbedEmbeddings(model_name=model_name, max_length=max_length) # type: ignore[call-arg]
output = await embedding.aembed_query(document)
assert len(output) == 384

View File

@@ -9,7 +9,7 @@ from langchain_community.embeddings.google_palm import GooglePalmEmbeddings
def test_google_palm_embedding_documents() -> None:
"""Test Google PaLM embeddings."""
documents = ["foo bar"]
embedding = GooglePalmEmbeddings()
embedding = GooglePalmEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 768
@@ -18,7 +18,7 @@ def test_google_palm_embedding_documents() -> None:
def test_google_palm_embedding_documents_multiple() -> None:
"""Test Google PaLM embeddings."""
documents = ["foo bar", "bar foo", "foo"]
embedding = GooglePalmEmbeddings()
embedding = GooglePalmEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 3
assert len(output[0]) == 768
@@ -29,6 +29,6 @@ def test_google_palm_embedding_documents_multiple() -> None:
def test_google_palm_embedding_query() -> None:
"""Test Google PaLM embeddings."""
document = "foo bar"
embedding = GooglePalmEmbeddings()
embedding = GooglePalmEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 768

View File

@@ -7,7 +7,7 @@ from langchain_community.embeddings import HuggingFaceHubEmbeddings
def test_huggingfacehub_embedding_documents() -> None:
"""Test huggingfacehub embeddings."""
documents = ["foo bar"]
embedding = HuggingFaceHubEmbeddings()
embedding = HuggingFaceHubEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 768
@@ -16,7 +16,7 @@ def test_huggingfacehub_embedding_documents() -> None:
async def test_huggingfacehub_embedding_async_documents() -> None:
"""Test huggingfacehub embeddings."""
documents = ["foo bar"]
embedding = HuggingFaceHubEmbeddings()
embedding = HuggingFaceHubEmbeddings() # type: ignore[call-arg]
output = await embedding.aembed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 768
@@ -25,7 +25,7 @@ async def test_huggingfacehub_embedding_async_documents() -> None:
def test_huggingfacehub_embedding_query() -> None:
"""Test huggingfacehub embeddings."""
document = "foo bar"
embedding = HuggingFaceHubEmbeddings()
embedding = HuggingFaceHubEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 768
@@ -33,7 +33,7 @@ def test_huggingfacehub_embedding_query() -> None:
async def test_huggingfacehub_embedding_async_query() -> None:
"""Test huggingfacehub embeddings."""
document = "foo bar"
embedding = HuggingFaceHubEmbeddings()
embedding = HuggingFaceHubEmbeddings() # type: ignore[call-arg]
output = await embedding.aembed_query(document)
assert len(output) == 768
@@ -42,4 +42,4 @@ def test_huggingfacehub_embedding_invalid_repo() -> None:
"""Test huggingfacehub embedding repo id validation."""
# Only sentence-transformers models are currently supported.
with pytest.raises(ValueError):
HuggingFaceHubEmbeddings(repo_id="allenai/specter")
HuggingFaceHubEmbeddings(repo_id="allenai/specter") # type: ignore[call-arg]

View File

@@ -5,7 +5,7 @@ from langchain_community.embeddings.jina import JinaEmbeddings
def test_jina_embedding_documents() -> None:
"""Test jina embeddings for documents."""
documents = ["foo bar", "bar foo"]
embedding = JinaEmbeddings()
embedding = JinaEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2
assert len(output[0]) == 512
@@ -14,6 +14,6 @@ def test_jina_embedding_documents() -> None:
def test_jina_embedding_query() -> None:
"""Test jina embeddings for query."""
document = "foo bar"
embedding = JinaEmbeddings()
embedding = JinaEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 512

View File

@@ -11,7 +11,7 @@ def test_laser_embedding_documents(lang: str) -> None:
User warning is returned by LASER library implementation
so will ignore in testing."""
documents = ["hello", "world"]
embedding = LaserEmbeddings(lang=lang)
embedding = LaserEmbeddings(lang=lang) # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2 # type: ignore[arg-type]
assert len(output[0]) == 1024 # type: ignore[index]
@@ -24,6 +24,6 @@ def test_laser_embedding_query(lang: str) -> None:
User warning is returned by LASER library implementation
so will ignore in testing."""
query = "hello world"
embedding = LaserEmbeddings(lang=lang)
embedding = LaserEmbeddings(lang=lang) # type: ignore[call-arg]
output = embedding.embed_query(query)
assert len(output) == 1024

View File

@@ -31,7 +31,7 @@ def test_llamacpp_embedding_documents() -> None:
"""Test llamacpp embeddings."""
documents = ["foo bar"]
model_path = get_model()
embedding = LlamaCppEmbeddings(model_path=model_path)
embedding = LlamaCppEmbeddings(model_path=model_path) # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 512
@@ -41,6 +41,6 @@ def test_llamacpp_embedding_query() -> None:
"""Test llamacpp embeddings."""
document = "foo bar"
model_path = get_model()
embedding = LlamaCppEmbeddings(model_path=model_path)
embedding = LlamaCppEmbeddings(model_path=model_path) # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 512

View File

@@ -12,7 +12,7 @@ from langchain_community.embeddings.premai import PremAIEmbeddings
@pytest.fixture
def embedder() -> PremAIEmbeddings:
return PremAIEmbeddings(project_id=8, model="text-embedding-3-small")
return PremAIEmbeddings(project_id=8, model="text-embedding-3-small") # type: ignore[call-arg]
def test_prem_embedding_documents(embedder: PremAIEmbeddings) -> None:

View File

@@ -6,7 +6,7 @@ from langchain_community.embeddings.baidu_qianfan_endpoint import (
def test_embedding_multiple_documents() -> None:
documents = ["foo", "bar"]
embedding = QianfanEmbeddingsEndpoint()
embedding = QianfanEmbeddingsEndpoint() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2
assert len(output[0]) == 384
@@ -15,20 +15,20 @@ def test_embedding_multiple_documents() -> None:
def test_embedding_query() -> None:
query = "foo"
embedding = QianfanEmbeddingsEndpoint()
embedding = QianfanEmbeddingsEndpoint() # type: ignore[call-arg]
output = embedding.embed_query(query)
assert len(output) == 384
def test_model() -> None:
documents = ["hi", "qianfan"]
embedding = QianfanEmbeddingsEndpoint(model="Embedding-V1")
embedding = QianfanEmbeddingsEndpoint(model="Embedding-V1") # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2
def test_rate_limit() -> None:
llm = QianfanEmbeddingsEndpoint(
llm = QianfanEmbeddingsEndpoint( # type: ignore[call-arg]
model="Embedding-V1", init_kwargs={"query_per_second": 2}
)
assert llm.client._client._rate_limiter._sync_limiter._query_per_second == 2

View File

@@ -77,7 +77,7 @@ def test_self_hosted_embedding_documents() -> None:
"""Test self-hosted huggingface instruct embeddings."""
documents = ["foo bar"] * 2
gpu = get_remote_instance()
embedding = SelfHostedEmbeddings(
embedding = SelfHostedEmbeddings( # type: ignore[call-arg]
model_load_fn=get_pipeline, hardware=gpu, inference_fn=inference_fn
)
output = embedding.embed_documents(documents)
@@ -89,7 +89,7 @@ def test_self_hosted_embedding_query() -> None:
"""Test self-hosted custom embeddings."""
query = "foo bar"
gpu = get_remote_instance()
embedding = SelfHostedEmbeddings(
embedding = SelfHostedEmbeddings( # type: ignore[call-arg]
model_load_fn=get_pipeline, hardware=gpu, inference_fn=inference_fn
)
output = embedding.embed_query(query)

View File

@@ -17,7 +17,7 @@ def test_baichuan_embedding_documents() -> None:
"understand and think, "
"creating a better world with artificial intelligence."
]
embedding = SparkLLMTextEmbeddings()
embedding = SparkLLMTextEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 1 # type: ignore[arg-type]
assert len(output[0]) == 2560 # type: ignore[index]
@@ -30,6 +30,6 @@ def test_baichuan_embedding_query() -> None:
"first Artificial Intelligence open platform for Mobile Internet "
"and intelligent hardware developers"
)
embedding = SparkLLMTextEmbeddings()
embedding = SparkLLMTextEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 2560 # type: ignore[arg-type]

View File

@@ -5,7 +5,7 @@ from langchain_community.embeddings import VolcanoEmbeddings
def test_embedding_documents() -> None:
"""Test embeddings for documents."""
documents = ["foo", "bar"]
embedding = VolcanoEmbeddings()
embedding = VolcanoEmbeddings() # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 2
assert len(output[0]) == 1024
@@ -14,6 +14,6 @@ def test_embedding_documents() -> None:
def test_embedding_query() -> None:
"""Test embeddings for query."""
document = "foo bar"
embedding = VolcanoEmbeddings()
embedding = VolcanoEmbeddings() # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 1024

View File

@@ -8,7 +8,7 @@ MODEL = "voyage-2"
def test_voyagi_embedding_documents() -> None:
"""Test voyage embeddings."""
documents = ["foo bar"]
embedding = VoyageEmbeddings(model=MODEL)
embedding = VoyageEmbeddings(model=MODEL) # type: ignore[call-arg]
output = embedding.embed_documents(documents)
assert len(output) == 1
assert len(output[0]) == 1024
@@ -16,7 +16,7 @@ def test_voyagi_embedding_documents() -> None:
def test_voyagi_with_default_model() -> None:
"""Test voyage embeddings."""
embedding = VoyageEmbeddings()
embedding = VoyageEmbeddings() # type: ignore[call-arg]
assert embedding.model == "voyage-01"
assert embedding.batch_size == 7
documents = [f"foo bar {i}" for i in range(72)]
@@ -40,6 +40,6 @@ def test_voyage_embedding_documents_multiple() -> None:
def test_voyage_embedding_query() -> None:
"""Test voyage embeddings."""
document = "foo bar"
embedding = VoyageEmbeddings(model=MODEL)
embedding = VoyageEmbeddings(model=MODEL) # type: ignore[call-arg]
output = embedding.embed_query(document)
assert len(output) == 1024