fix(providers): remove type: ignore suppressions from registry.py and resolve underlying type errors #3459
@@ -472,14 +472,14 @@ class ProviderRegistry:
|
||||
if provider_type == ProviderType.OPENAI:
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
return ChatOpenAI(model=model_id or "gpt-4o", **kwargs) # type: ignore[arg-type]
|
||||
return ChatOpenAI(model=model_id or "gpt-4o", **kwargs)
|
||||
|
||||
if provider_type == ProviderType.ANTHROPIC:
|
||||
from langchain_anthropic import ChatAnthropic
|
||||
|
||||
return ChatAnthropic(
|
||||
model=model_id or "claude-sonnet-4-20250514",
|
||||
**kwargs, # type: ignore[arg-type]
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
if provider_type in (ProviderType.GOOGLE, ProviderType.GEMINI):
|
||||
@@ -487,7 +487,7 @@ class ProviderRegistry:
|
||||
|
||||
return ChatGoogleGenerativeAI(
|
||||
model=model_id or "gemini-2.0-flash",
|
||||
**kwargs, # type: ignore[arg-type]
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
if provider_type == ProviderType.AZURE:
|
||||
@@ -522,31 +522,31 @@ class ProviderRegistry:
|
||||
deployment_name=deployment_name,
|
||||
azure_endpoint=azure_endpoint,
|
||||
api_version=api_version,
|
||||
**kwargs, # type: ignore[arg-type]
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
if provider_type == ProviderType.GROQ:
|
||||
from langchain_groq import ChatGroq # type: ignore[import-untyped]
|
||||
from langchain_groq import ChatGroq
|
||||
|
||||
return ChatGroq(
|
||||
model=model_id or "llama-3.1-70b-versatile",
|
||||
**kwargs, # type: ignore[arg-type]
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
if provider_type == ProviderType.TOGETHER:
|
||||
from langchain_together import ChatTogether # type: ignore[import-untyped]
|
||||
from langchain_together import ChatTogether
|
||||
|
||||
return ChatTogether(
|
||||
model=model_id or "meta-llama/Llama-3.1-70B-Instruct-Turbo",
|
||||
**kwargs, # type: ignore[arg-type]
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
if provider_type == ProviderType.COHERE:
|
||||
from langchain_cohere import ChatCohere # type: ignore[import-untyped]
|
||||
from langchain_cohere import ChatCohere
|
||||
|
||||
return ChatCohere(
|
||||
model=model_id or "command-r-plus",
|
||||
**kwargs, # type: ignore[arg-type]
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
raise ValueError(f"Unsupported provider type: {provider_type}")
|
||||
@@ -647,14 +647,18 @@ class ProviderRegistry:
|
||||
max_retries=max_retries,
|
||||
)
|
||||
|
||||
# Create factory function for the LLM
|
||||
# Create factory function for the LLM.
|
||||
# Capture the narrowed ProviderType in a local variable so the closure
|
||||
# holds a ProviderType rather than the wider ProviderType | str | None.
|
||||
resolved_provider_type: ProviderType = provider_type
|
||||
|
||||
def llm_factory(mid: str) -> BaseLanguageModel:
|
||||
factory_kwargs: dict[str, Any] = {"max_retries": max_retries}
|
||||
return self._create_provider_llm(
|
||||
provider_type,
|
||||
resolved_provider_type,
|
||||
mid,
|
||||
**factory_kwargs,
|
||||
) # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
return LangChainChatProvider(
|
||||
name=provider_type.value,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
"""Type stubs for langchain_cohere package."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.messages import AIMessage
|
||||
|
||||
class ChatCohere(BaseLanguageModel[AIMessage]):
|
||||
"""Cohere chat model wrapper."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
model: str = ...,
|
||||
temperature: float = ...,
|
||||
max_tokens: int | None = None,
|
||||
timeout: float | None = None,
|
||||
max_retries: int = ...,
|
||||
cohere_api_key: Any = None,
|
||||
base_url: str | None = None,
|
||||
streaming: bool = ...,
|
||||
**kwargs: Any,
|
||||
) -> None: ...
|
||||
|
||||
__all__ = ["ChatCohere"]
|
||||
@@ -0,0 +1,25 @@
|
||||
"""Type stubs for langchain_groq package."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.messages import AIMessage
|
||||
|
||||
class ChatGroq(BaseLanguageModel[AIMessage]):
|
||||
"""Groq chat model wrapper."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
model: str = ...,
|
||||
temperature: float = ...,
|
||||
max_tokens: int | None = None,
|
||||
timeout: float | None = None,
|
||||
max_retries: int = ...,
|
||||
api_key: Any = None,
|
||||
base_url: str | None = None,
|
||||
streaming: bool = ...,
|
||||
**kwargs: Any,
|
||||
) -> None: ...
|
||||
|
||||
__all__ = ["ChatGroq"]
|
||||
@@ -0,0 +1,25 @@
|
||||
"""Type stubs for langchain_together package."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from langchain_core.language_models import BaseLanguageModel
|
||||
from langchain_core.messages import AIMessage
|
||||
|
||||
class ChatTogether(BaseLanguageModel[AIMessage]):
|
||||
"""Together AI chat model wrapper."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
model: str = ...,
|
||||
temperature: float = ...,
|
||||
max_tokens: int | None = None,
|
||||
timeout: float | None = None,
|
||||
max_retries: int = ...,
|
||||
api_key: Any = None,
|
||||
base_url: str | None = None,
|
||||
streaming: bool = ...,
|
||||
**kwargs: Any,
|
||||
) -> None: ...
|
||||
|
||||
__all__ = ["ChatTogether"]
|
||||
Reference in New Issue
Block a user