mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-16 23:13:31 +00:00
infra: update mypy 1.10, ruff 0.5 (#23721)
```python """python scripts/update_mypy_ruff.py""" import glob import tomllib from pathlib import Path import toml import subprocess import re ROOT_DIR = Path(__file__).parents[1] def main(): for path in glob.glob(str(ROOT_DIR / "libs/**/pyproject.toml"), recursive=True): print(path) with open(path, "rb") as f: pyproject = tomllib.load(f) try: pyproject["tool"]["poetry"]["group"]["typing"]["dependencies"]["mypy"] = ( "^1.10" ) pyproject["tool"]["poetry"]["group"]["lint"]["dependencies"]["ruff"] = ( "^0.5" ) except KeyError: continue with open(path, "w") as f: toml.dump(pyproject, f) cwd = "/".join(path.split("/")[:-1]) completed = subprocess.run( "poetry lock --no-update; poetry install --with typing; poetry run mypy . --no-color", cwd=cwd, shell=True, capture_output=True, text=True, ) logs = completed.stdout.split("\n") to_ignore = {} for l in logs: if re.match("^(.*)\:(\d+)\: error:.*\[(.*)\]", l): path, line_no, error_type = re.match( "^(.*)\:(\d+)\: error:.*\[(.*)\]", l ).groups() if (path, line_no) in to_ignore: to_ignore[(path, line_no)].append(error_type) else: to_ignore[(path, line_no)] = [error_type] print(len(to_ignore)) for (error_path, line_no), error_types in to_ignore.items(): all_errors = ", ".join(error_types) full_path = f"{cwd}/{error_path}" try: with open(full_path, "r") as f: file_lines = f.readlines() except FileNotFoundError: continue file_lines[int(line_no) - 1] = ( file_lines[int(line_no) - 1][:-1] + f" # type: ignore[{all_errors}]\n" ) with open(full_path, "w") as f: f.write("".join(file_lines)) subprocess.run( "poetry run ruff format .; poetry run ruff --select I --fix .", cwd=cwd, shell=True, capture_output=True, text=True, ) if __name__ == "__main__": main() ```
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Wrapper around Anyscale Endpoint"""
|
||||
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
|
@@ -44,8 +44,7 @@ class _DatabricksClientBase(BaseModel, ABC):
|
||||
@abstractmethod
|
||||
def post(
|
||||
self, request: Any, transform_output_fn: Optional[Callable[..., str]] = None
|
||||
) -> Any:
|
||||
...
|
||||
) -> Any: ...
|
||||
|
||||
@property
|
||||
def llm(self) -> bool:
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Wrapper around EdenAI's Generation API."""
|
||||
|
||||
import logging
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Wrapper around Konko AI's Completion API."""
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
@@ -39,12 +39,12 @@ class LayerupSecurity(LLM):
|
||||
response_guardrails: Optional[List[str]] = []
|
||||
mask: bool = False
|
||||
metadata: Optional[Dict[str, Any]] = {}
|
||||
handle_prompt_guardrail_violation: Callable[
|
||||
[dict], str
|
||||
] = default_guardrail_violation_handler
|
||||
handle_response_guardrail_violation: Callable[
|
||||
[dict], str
|
||||
] = default_guardrail_violation_handler
|
||||
handle_prompt_guardrail_violation: Callable[[dict], str] = (
|
||||
default_guardrail_violation_handler
|
||||
)
|
||||
handle_response_guardrail_violation: Callable[[dict], str] = (
|
||||
default_guardrail_violation_handler
|
||||
)
|
||||
client: Any #: :meta private:
|
||||
|
||||
@root_validator(pre=True)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Base interface for loading large language model APIs."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Wrapper around Minimax APIs."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
@@ -18,12 +18,10 @@ CUSTOM_ENDPOINT_PREFIX = "ocid1.generativeaiendpoint"
|
||||
class Provider(ABC):
|
||||
@property
|
||||
@abstractmethod
|
||||
def stop_sequence_key(self) -> str:
|
||||
...
|
||||
def stop_sequence_key(self) -> str: ...
|
||||
|
||||
@abstractmethod
|
||||
def completion_response_to_text(self, response: Any) -> str:
|
||||
...
|
||||
def completion_response_to_text(self, response: Any) -> str: ...
|
||||
|
||||
|
||||
class CohereProvider(Provider):
|
||||
@@ -144,13 +142,13 @@ class OCIGenAIBase(BaseModel, ABC):
|
||||
oci_config=client_kwargs["config"]
|
||||
)
|
||||
elif values["auth_type"] == OCIAuthType(3).name:
|
||||
client_kwargs[
|
||||
"signer"
|
||||
] = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
|
||||
client_kwargs["signer"] = (
|
||||
oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
|
||||
)
|
||||
elif values["auth_type"] == OCIAuthType(4).name:
|
||||
client_kwargs[
|
||||
"signer"
|
||||
] = oci.auth.signers.get_resource_principals_signer()
|
||||
client_kwargs["signer"] = (
|
||||
oci.auth.signers.get_resource_principals_signer()
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
"Please provide valid value to auth_type, "
|
||||
|
@@ -93,9 +93,9 @@ class OpenLLM(LLM):
|
||||
"""Keyword arguments to be passed to openllm.LLM"""
|
||||
|
||||
_runner: Optional[openllm.LLMRunner] = PrivateAttr(default=None)
|
||||
_client: Union[
|
||||
openllm.client.HTTPClient, openllm.client.GrpcClient, None
|
||||
] = PrivateAttr(default=None)
|
||||
_client: Union[openllm.client.HTTPClient, openllm.client.GrpcClient, None] = (
|
||||
PrivateAttr(default=None)
|
||||
)
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
@@ -108,8 +108,7 @@ class OpenLLM(LLM):
|
||||
model_id: Optional[str] = ...,
|
||||
embedded: Literal[True, False] = ...,
|
||||
**llm_kwargs: Any,
|
||||
) -> None:
|
||||
...
|
||||
) -> None: ...
|
||||
|
||||
@overload
|
||||
def __init__(
|
||||
@@ -118,8 +117,7 @@ class OpenLLM(LLM):
|
||||
server_url: str = ...,
|
||||
server_type: Literal["grpc", "http"] = ...,
|
||||
**llm_kwargs: Any,
|
||||
) -> None:
|
||||
...
|
||||
) -> None: ...
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@@ -3,6 +3,7 @@
|
||||
Based on https://github.com/saharNooby/rwkv.cpp/blob/master/rwkv/chat_with_bot.py
|
||||
https://github.com/BlinkDL/ChatRWKV/blob/main/v2/chat.py
|
||||
"""
|
||||
|
||||
from typing import Any, Dict, List, Mapping, Optional, Set
|
||||
|
||||
from langchain_core.callbacks import CallbackManagerForLLMRun
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Sagemaker InvokeEndpoint API."""
|
||||
|
||||
import io
|
||||
import json
|
||||
from abc import abstractmethod
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Wrapper around Together AI's Completion API."""
|
||||
|
||||
import logging
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
"""Common utility functions for LLM APIs."""
|
||||
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
|
@@ -35,7 +35,6 @@ if TYPE_CHECKING:
|
||||
# This is for backwards compatibility
|
||||
# We can remove after `langchain` stops importing it
|
||||
_response_to_generation = None
|
||||
completion_with_retry = None
|
||||
stream_completion_with_retry = None
|
||||
|
||||
|
||||
|
@@ -104,9 +104,9 @@ class _BaseYandexGPT(Serializable):
|
||||
if values["model_uri"] == "" and values["folder_id"] == "":
|
||||
raise ValueError("Either 'model_uri' or 'folder_id' must be provided.")
|
||||
if not values["model_uri"]:
|
||||
values[
|
||||
"model_uri"
|
||||
] = f"gpt://{values['folder_id']}/{values['model_name']}/{values['model_version']}"
|
||||
values["model_uri"] = (
|
||||
f"gpt://{values['folder_id']}/{values['model_name']}/{values['model_version']}"
|
||||
)
|
||||
if values["disable_request_logging"]:
|
||||
values["_grpc_metadata"].append(
|
||||
(
|
||||
|
Reference in New Issue
Block a user