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:
Bagatur 2024-07-03 13:33:27 -04:00 committed by GitHub
parent 6cd56821dc
commit a0c2281540
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
915 changed files with 4759 additions and 4047 deletions

View File

@ -350,11 +350,7 @@ def get_graphql_pr_edges(*, settings: Settings, after: Union[str, None] = None):
print("Querying PRs...") print("Querying PRs...")
else: else:
print(f"Querying PRs with cursor {after}...") print(f"Querying PRs with cursor {after}...")
data = get_graphql_response( data = get_graphql_response(settings=settings, query=prs_query, after=after)
settings=settings,
query=prs_query,
after=after
)
graphql_response = PRsResponse.model_validate(data) graphql_response = PRsResponse.model_validate(data)
return graphql_response.data.repository.pullRequests.edges return graphql_response.data.repository.pullRequests.edges
@ -484,10 +480,16 @@ def get_contributors(settings: Settings):
lines_changed = pr.additions + pr.deletions lines_changed = pr.additions + pr.deletions
score = _logistic(files_changed, 20) + _logistic(lines_changed, 100) score = _logistic(files_changed, 20) + _logistic(lines_changed, 100)
contributor_scores[pr.author.login] += score contributor_scores[pr.author.login] += score
three_months_ago = (datetime.now(timezone.utc) - timedelta(days=3*30)) three_months_ago = datetime.now(timezone.utc) - timedelta(days=3 * 30)
if pr.createdAt > three_months_ago: if pr.createdAt > three_months_ago:
recent_contributor_scores[pr.author.login] += score recent_contributor_scores[pr.author.login] += score
return contributors, contributor_scores, recent_contributor_scores, reviewers, authors return (
contributors,
contributor_scores,
recent_contributor_scores,
reviewers,
authors,
)
def get_top_users( def get_top_users(
@ -524,9 +526,13 @@ if __name__ == "__main__":
# question_commentors, question_last_month_commentors, question_authors = get_experts( # question_commentors, question_last_month_commentors, question_authors = get_experts(
# settings=settings # settings=settings
# ) # )
contributors, contributor_scores, recent_contributor_scores, reviewers, pr_authors = get_contributors( (
settings=settings contributors,
) contributor_scores,
recent_contributor_scores,
reviewers,
pr_authors,
) = get_contributors(settings=settings)
# authors = {**question_authors, **pr_authors} # authors = {**question_authors, **pr_authors}
authors = {**pr_authors} authors = {**pr_authors}
maintainers_logins = { maintainers_logins = {
@ -559,7 +565,7 @@ if __name__ == "__main__":
maintainers.append( maintainers.append(
{ {
"login": login, "login": login,
"count": contributors[login], #+ question_commentors[login], "count": contributors[login], # + question_commentors[login],
"avatarUrl": user.avatarUrl, "avatarUrl": user.avatarUrl,
"twitterUsername": user.twitterUsername, "twitterUsername": user.twitterUsername,
"url": user.url, "url": user.url,
@ -615,9 +621,7 @@ if __name__ == "__main__":
new_people_content = yaml.dump( new_people_content = yaml.dump(
people, sort_keys=False, width=200, allow_unicode=True people, sort_keys=False, width=200, allow_unicode=True
) )
if ( if people_old_content == new_people_content:
people_old_content == new_people_content
):
logging.info("The LangChain People data hasn't changed, finishing.") logging.info("The LangChain People data hasn't changed, finishing.")
sys.exit(0) sys.exit(0)
people_path.write_text(new_people_content, encoding="utf-8") people_path.write_text(new_people_content, encoding="utf-8")
@ -630,9 +634,7 @@ if __name__ == "__main__":
logging.info(f"Creating a new branch {branch_name}") logging.info(f"Creating a new branch {branch_name}")
subprocess.run(["git", "checkout", "-B", branch_name], check=True) subprocess.run(["git", "checkout", "-B", branch_name], check=True)
logging.info("Adding updated file") logging.info("Adding updated file")
subprocess.run( subprocess.run(["git", "add", str(people_path)], check=True)
["git", "add", str(people_path)], check=True
)
logging.info("Committing updated file") logging.info("Committing updated file")
message = "👥 Update LangChain people data" message = "👥 Update LangChain people data"
result = subprocess.run(["git", "commit", "-m", message], check=True) result = subprocess.run(["git", "commit", "-m", message], check=True)

View File

@ -1,11 +1,12 @@
import glob
import json import json
import sys
import os import os
from typing import Dict, List, Set import re
import sys
import tomllib import tomllib
from collections import defaultdict from collections import defaultdict
import glob from typing import Dict, List, Set
LANGCHAIN_DIRS = [ LANGCHAIN_DIRS = [
"libs/core", "libs/core",
@ -15,8 +16,13 @@ LANGCHAIN_DIRS = [
"libs/experimental", "libs/experimental",
] ]
def all_package_dirs() -> Set[str]: def all_package_dirs() -> Set[str]:
return {"/".join(path.split("/")[:-1]) for path in glob.glob("./libs/**/pyproject.toml", recursive=True)} return {
"/".join(path.split("/")[:-1]).lstrip("./")
for path in glob.glob("./libs/**/pyproject.toml", recursive=True)
if "libs/cli" not in path and "libs/standard-tests" not in path
}
def dependents_graph() -> dict: def dependents_graph() -> dict:
@ -26,9 +32,9 @@ def dependents_graph() -> dict:
if "template" in path: if "template" in path:
continue continue
with open(path, "rb") as f: with open(path, "rb") as f:
pyproject = tomllib.load(f)['tool']['poetry'] pyproject = tomllib.load(f)["tool"]["poetry"]
pkg_dir = "libs" + "/".join(path.split("libs")[1].split("/")[:-1]) pkg_dir = "libs" + "/".join(path.split("libs")[1].split("/")[:-1])
for dep in pyproject['dependencies']: for dep in pyproject["dependencies"]:
if "langchain" in dep: if "langchain" in dep:
dependents[dep].add(pkg_dir) dependents[dep].add(pkg_dir)
return dependents return dependents
@ -122,9 +128,12 @@ if __name__ == "__main__":
outputs = { outputs = {
"dirs-to-lint": add_dependents( "dirs-to-lint": add_dependents(
dirs_to_run["lint"] | dirs_to_run["test"] | dirs_to_run["extended-test"], dependents dirs_to_run["lint"] | dirs_to_run["test"] | dirs_to_run["extended-test"],
dependents,
),
"dirs-to-test": add_dependents(
dirs_to_run["test"] | dirs_to_run["extended-test"], dependents
), ),
"dirs-to-test": add_dependents(dirs_to_run["test"] | dirs_to_run["extended-test"], dependents),
"dirs-to-extended-test": list(dirs_to_run["extended-test"]), "dirs-to-extended-test": list(dirs_to_run["extended-test"]),
"docs-edited": "true" if docs_edited else "", "docs-edited": "true" if docs_edited else "",
} }

View File

@ -74,6 +74,4 @@ if __name__ == "__main__":
# Call the function to get the minimum versions # Call the function to get the minimum versions
min_versions = get_min_version_from_toml(toml_file) min_versions = get_min_version_from_toml(toml_file)
print( print(" ".join([f"{lib}=={version}" for lib, version in min_versions.items()]))
" ".join([f"{lib}=={version}" for lib, version in min_versions.items()])
)

View File

@ -48,14 +48,14 @@ lint lint_diff lint_package lint_tests:
./scripts/check_pydantic.sh . ./scripts/check_pydantic.sh .
./scripts/lint_imports.sh ./scripts/lint_imports.sh
./scripts/check_pickle.sh . ./scripts/check_pickle.sh .
poetry run ruff . poetry run ruff check .
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff [ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff --select I $(PYTHON_FILES) [ "$(PYTHON_FILES)" = "" ] || poetry run ruff check --select I $(PYTHON_FILES)
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE) [ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
format format_diff: format format_diff:
poetry run ruff format $(PYTHON_FILES) poetry run ruff format $(PYTHON_FILES)
poetry run ruff --select I --fix $(PYTHON_FILES) poetry run ruff check --select I --fix $(PYTHON_FILES)
spell_check: spell_check:
poetry run codespell --toml pyproject.toml poetry run codespell --toml pyproject.toml

View File

@ -1,4 +1,5 @@
"""Main entrypoint into package.""" """Main entrypoint into package."""
from importlib import metadata from importlib import metadata
try: try:

View File

@ -206,8 +206,7 @@ class ChatCompletion:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[False] = False, stream: Literal[False] = False,
**kwargs: Any, **kwargs: Any,
) -> dict: ) -> dict: ...
...
@overload @overload
@staticmethod @staticmethod
@ -217,8 +216,7 @@ class ChatCompletion:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[True], stream: Literal[True],
**kwargs: Any, **kwargs: Any,
) -> Iterable: ) -> Iterable: ...
...
@staticmethod @staticmethod
def create( def create(
@ -249,8 +247,7 @@ class ChatCompletion:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[False] = False, stream: Literal[False] = False,
**kwargs: Any, **kwargs: Any,
) -> dict: ) -> dict: ...
...
@overload @overload
@staticmethod @staticmethod
@ -260,8 +257,7 @@ class ChatCompletion:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[True], stream: Literal[True],
**kwargs: Any, **kwargs: Any,
) -> AsyncIterator: ) -> AsyncIterator: ...
...
@staticmethod @staticmethod
async def acreate( async def acreate(
@ -319,8 +315,7 @@ class Completions:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[False] = False, stream: Literal[False] = False,
**kwargs: Any, **kwargs: Any,
) -> ChatCompletions: ) -> ChatCompletions: ...
...
@overload @overload
@staticmethod @staticmethod
@ -330,8 +325,7 @@ class Completions:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[True], stream: Literal[True],
**kwargs: Any, **kwargs: Any,
) -> Iterable: ) -> Iterable: ...
...
@staticmethod @staticmethod
def create( def create(
@ -366,8 +360,7 @@ class Completions:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[False] = False, stream: Literal[False] = False,
**kwargs: Any, **kwargs: Any,
) -> ChatCompletions: ) -> ChatCompletions: ...
...
@overload @overload
@staticmethod @staticmethod
@ -377,8 +370,7 @@ class Completions:
provider: str = "ChatOpenAI", provider: str = "ChatOpenAI",
stream: Literal[True], stream: Literal[True],
**kwargs: Any, **kwargs: Any,
) -> AsyncIterator: ) -> AsyncIterator: ...
...
@staticmethod @staticmethod
async def acreate( async def acreate(

View File

@ -2189,14 +2189,14 @@ class AzureCosmosDBSemanticCache(BaseCache):
index_name=index_name, index_name=index_name,
) )
else: else:
self._cache_dict[ self._cache_dict[index_name] = (
index_name AzureCosmosDBVectorSearch.from_connection_string(
] = AzureCosmosDBVectorSearch.from_connection_string( connection_string=self.cosmosdb_connection_string,
connection_string=self.cosmosdb_connection_string, namespace=namespace,
namespace=namespace, embedding=self.embedding,
embedding=self.embedding, index_name=index_name,
index_name=index_name, application_name=self.application_name,
application_name=self.application_name, )
) )
# create index for the vectorstore # create index for the vectorstore

View File

@ -6,6 +6,7 @@
BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler
""" """
import importlib import importlib
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any

View File

@ -82,9 +82,9 @@ class ArizeCallbackHandler(BaseCallbackHandler):
"completion_tokens", 0 "completion_tokens", 0
) )
else: else:
self.prompt_tokens = ( self.prompt_tokens = self.total_tokens = self.completion_tokens = (
self.total_tokens 0 # assign default value
) = self.completion_tokens = 0 # assign default value )
for generations in response.generations: for generations in response.generations:
for generation in generations: for generation in generations:

View File

@ -1,4 +1,5 @@
"""ArthurAI's Callback Handler.""" """ArthurAI's Callback Handler."""
from __future__ import annotations from __future__ import annotations
import os import os

View File

@ -1,4 +1,5 @@
"""Callback handler for promptlayer.""" """Callback handler for promptlayer."""
from __future__ import annotations from __future__ import annotations
import datetime import datetime

View File

@ -1,4 +1,5 @@
"""A Tracer Implementation that records activity to Weights & Biases.""" """A Tracer Implementation that records activity to Weights & Biases."""
from __future__ import annotations from __future__ import annotations
import json import json
@ -234,9 +235,9 @@ def build_tree(runs: List[Dict[str, Any]]) -> Dict[str, Any]:
for child_id, parent_id in child_to_parent.items(): for child_id, parent_id in child_to_parent.items():
parent_dict = id_to_data[parent_id] parent_dict = id_to_data[parent_id]
parent_dict[next(iter(parent_dict))][ parent_dict[next(iter(parent_dict))][next(iter(id_to_data[child_id]))] = (
next(iter(id_to_data[child_id])) id_to_data[child_id][next(iter(id_to_data[child_id]))]
] = id_to_data[child_id][next(iter(id_to_data[child_id]))] )
root_dict = next( root_dict = next(
data for id_val, data in id_to_data.items() if id_val not in child_to_parent data for id_val, data in id_to_data.items() if id_val not in child_to_parent

View File

@ -1,4 +1,5 @@
"""Methods for creating chains that use Ernie function-calling APIs.""" """Methods for creating chains that use Ernie function-calling APIs."""
import inspect import inspect
from typing import ( from typing import (
Any, Any,
@ -191,9 +192,9 @@ def get_ernie_output_parser(
} }
else: else:
pydantic_schema = functions[0] pydantic_schema = functions[0]
output_parser: Union[ output_parser: Union[BaseOutputParser, BaseGenerationOutputParser] = (
BaseOutputParser, BaseGenerationOutputParser PydanticOutputFunctionsParser(pydantic_schema=pydantic_schema)
] = PydanticOutputFunctionsParser(pydantic_schema=pydantic_schema) )
else: else:
output_parser = JsonOutputFunctionsParser(args_only=len(functions) <= 1) output_parser = JsonOutputFunctionsParser(args_only=len(functions) <= 1)
return output_parser return output_parser

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
import re import re

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
import re import re

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
import re import re

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
import re import re

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,6 +1,7 @@
""" """
Question answering over an RDF or OWL graph using SPARQL. Question answering over an RDF or OWL graph using SPARQL.
""" """
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,4 +1,5 @@
"""Question answering over a graph.""" """Question answering over a graph."""
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Any, Dict, List, Optional from typing import TYPE_CHECKING, Any, Dict, List, Optional

View File

@ -1,6 +1,7 @@
""" """
Question answering over an RDF or OWL graph using SPARQL. Question answering over an RDF or OWL graph using SPARQL.
""" """
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,4 +1,5 @@
"""Chain that hits a URL and then uses an LLM to parse results.""" """Chain that hits a URL and then uses an LLM to parse results."""
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,4 +1,5 @@
"""Chain that makes API calls and summarizes the responses to answer a question.""" """Chain that makes API calls and summarizes the responses to answer a question."""
from __future__ import annotations from __future__ import annotations
import json import json

View File

@ -1,4 +1,5 @@
"""Utilities for chat loaders.""" """Utilities for chat loaders."""
from copy import deepcopy from copy import deepcopy
from typing import Iterable, Iterator, List from typing import Iterable, Iterator, List

View File

@ -1,4 +1,5 @@
"""Astra DB - based chat message history, based on astrapy.""" """Astra DB - based chat message history, based on astrapy."""
from __future__ import annotations from __future__ import annotations
import json import json

View File

@ -1,4 +1,5 @@
"""Cassandra-based chat message history, based on cassIO.""" """Cassandra-based chat message history, based on cassIO."""
from __future__ import annotations from __future__ import annotations
import json import json

View File

@ -1,4 +1,5 @@
"""Azure CosmosDB Memory History.""" """Azure CosmosDB Memory History."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""Firestore Chat Message History.""" """Firestore Chat Message History."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,7 +1,8 @@
""" Kafka-based chat message history by using confluent-kafka-python. """Kafka-based chat message history by using confluent-kafka-python.
confluent-kafka-python is under Apache 2.0 license. confluent-kafka-python is under Apache 2.0 license.
https://github.com/confluentinc/confluent-kafka-python https://github.com/confluentinc/confluent-kafka-python
""" """
from __future__ import annotations from __future__ import annotations
import json import json

View File

@ -1,4 +1,5 @@
"""Anyscale Endpoints chat wrapper. Relies heavily on ChatOpenAI.""" """Anyscale Endpoints chat wrapper. Relies heavily on ChatOpenAI."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""Azure OpenAI chat wrapper.""" """Azure OpenAI chat wrapper."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""EverlyAI Endpoints chat wrapper. Relies heavily on ChatOpenAI.""" """EverlyAI Endpoints chat wrapper. Relies heavily on ChatOpenAI."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""Fake ChatModel for testing purposes.""" """Fake ChatModel for testing purposes."""
import asyncio import asyncio
import time import time
from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, Union from typing import Any, AsyncIterator, Dict, Iterator, List, Optional, Union

View File

@ -1,4 +1,5 @@
"""Wrapper around Google's PaLM Chat API.""" """Wrapper around Google's PaLM Chat API."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""JinaChat wrapper.""" """JinaChat wrapper."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""KonkoAI chat wrapper.""" """KonkoAI chat wrapper."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""Wrapper around LiteLLM's model I/O library.""" """Wrapper around LiteLLM's model I/O library."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""LiteLLM Router as LangChain Model.""" """LiteLLM Router as LangChain Model."""
from typing import ( from typing import (
Any, Any,
AsyncIterator, AsyncIterator,

View File

@ -1,4 +1,5 @@
"""Wrapper around Moonshot chat models.""" """Wrapper around Moonshot chat models."""
from typing import Dict from typing import Dict
from langchain_core.pydantic_v1 import root_validator from langchain_core.pydantic_v1 import root_validator

View File

@ -27,28 +27,22 @@ CUSTOM_ENDPOINT_PREFIX = "ocid1.generativeaiendpoint"
class Provider(ABC): class Provider(ABC):
@property @property
@abstractmethod @abstractmethod
def stop_sequence_key(self) -> str: def stop_sequence_key(self) -> str: ...
...
@abstractmethod @abstractmethod
def chat_response_to_text(self, response: Any) -> str: def chat_response_to_text(self, response: Any) -> str: ...
...
@abstractmethod @abstractmethod
def chat_stream_to_text(self, event_data: Dict) -> str: def chat_stream_to_text(self, event_data: Dict) -> str: ...
...
@abstractmethod @abstractmethod
def chat_generation_info(self, response: Any) -> Dict[str, Any]: def chat_generation_info(self, response: Any) -> Dict[str, Any]: ...
...
@abstractmethod @abstractmethod
def get_role(self, message: BaseMessage) -> str: def get_role(self, message: BaseMessage) -> str: ...
...
@abstractmethod @abstractmethod
def messages_to_oci_params(self, messages: Any) -> Dict[str, Any]: def messages_to_oci_params(self, messages: Any) -> Dict[str, Any]: ...
...
class CohereProvider(Provider): class CohereProvider(Provider):

View File

@ -1,4 +1,5 @@
"""OctoAI Endpoints chat wrapper. Relies heavily on ChatOpenAI.""" """OctoAI Endpoints chat wrapper. Relies heavily on ChatOpenAI."""
from typing import Dict from typing import Dict
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator from langchain_core.pydantic_v1 import Field, SecretStr, root_validator

View File

@ -1,4 +1,5 @@
"""PromptLayer wrapper.""" """PromptLayer wrapper."""
import datetime import datetime
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -1,4 +1,5 @@
"""Wrapper around Google VertexAI chat-based models.""" """Wrapper around Google VertexAI chat-based models."""
from __future__ import annotations from __future__ import annotations
import base64 import base64

View File

@ -1,4 +1,5 @@
"""Wrapper around YandexGPT chat models.""" """Wrapper around YandexGPT chat models."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""ChatYuan2 wrapper.""" """ChatYuan2 wrapper."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -9,6 +9,7 @@
BaseCrossEncoder --> <name>CrossEncoder # Examples: SagemakerEndpointCrossEncoder BaseCrossEncoder --> <name>CrossEncoder # Examples: SagemakerEndpointCrossEncoder
""" """
import importlib import importlib
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any

View File

@ -1,4 +1,5 @@
"""Interface to access to place that stores documents.""" """Interface to access to place that stores documents."""
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Dict, List, Union from typing import Dict, List, Union

View File

@ -1,4 +1,5 @@
"""Simple in memory docstore in the form of a dict.""" """Simple in memory docstore in the form of a dict."""
from typing import Dict, List, Optional, Union from typing import Dict, List, Optional, Union
from langchain_core.documents import Document from langchain_core.documents import Document

View File

@ -1,6 +1,5 @@
"""Wrapper around wikipedia API.""" """Wrapper around wikipedia API."""
from typing import Union from typing import Union
from langchain_core.documents import Document from langchain_core.documents import Document

View File

@ -60,9 +60,9 @@ def fetch_mime_types(file_types: Sequence[_FileType]) -> Dict[str, str]:
if file_type.value == "doc": if file_type.value == "doc":
mime_types_mapping[file_type.value] = "application/msword" mime_types_mapping[file_type.value] = "application/msword"
elif file_type.value == "docx": elif file_type.value == "docx":
mime_types_mapping[ mime_types_mapping[file_type.value] = (
file_type.value "application/vnd.openxmlformats-officedocument.wordprocessingml.document" # noqa: E501
] = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" # noqa: E501 )
elif file_type.value == "pdf": elif file_type.value == "pdf":
mime_types_mapping[file_type.value] = "application/pdf" mime_types_mapping[file_type.value] = "application/pdf"
return mime_types_mapping return mime_types_mapping

View File

@ -1,4 +1,5 @@
"""Use to load blobs from the local file system.""" """Use to load blobs from the local file system."""
import contextlib import contextlib
import mimetypes import mimetypes
import tempfile import tempfile

View File

@ -5,7 +5,6 @@ from langchain_community.document_loaders.blob_loaders.schema import Blob, BlobL
class YoutubeAudioLoader(BlobLoader): class YoutubeAudioLoader(BlobLoader):
"""Load YouTube urls as audio file(s).""" """Load YouTube urls as audio file(s)."""
def __init__(self, urls: List[str], save_dir: str): def __init__(self, urls: List[str], save_dir: str):

View File

@ -1,4 +1,5 @@
"""Load Documents from Docusarus Documentation""" """Load Documents from Docusarus Documentation"""
from typing import Any, List, Optional from typing import Any, List, Optional
from langchain_community.document_loaders.sitemap import SitemapLoader from langchain_community.document_loaders.sitemap import SitemapLoader

View File

@ -2,6 +2,7 @@
https://gist.github.com/foxmask/7b29c43a161e001ff04afdb2f181e31c https://gist.github.com/foxmask/7b29c43a161e001ff04afdb2f181e31c
""" """
import hashlib import hashlib
import logging import logging
from base64 import b64decode from base64 import b64decode

View File

@ -1,4 +1,5 @@
"""Loads Microsoft Excel files.""" """Loads Microsoft Excel files."""
from pathlib import Path from pathlib import Path
from typing import Any, List, Union from typing import Any, List, Union

View File

@ -1,4 +1,5 @@
"""Loader that uses unstructured to load HTML files.""" """Loader that uses unstructured to load HTML files."""
import logging import logging
from typing import Any, Iterator, List from typing import Any, Iterator, List

View File

@ -1,4 +1,5 @@
"""Loads .ipynb notebook files.""" """Loads .ipynb notebook files."""
import json import json
from pathlib import Path from pathlib import Path
from typing import Any, List, Union from typing import Any, List, Union

View File

@ -1,4 +1,5 @@
"""Loads data from OneDrive""" """Loads data from OneDrive"""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -4,6 +4,7 @@ You need to install two libraries to use this parser:
pip install google-cloud-documentai pip install google-cloud-documentai
pip install google-cloud-documentai-toolbox pip install google-cloud-documentai-toolbox
""" """
import logging import logging
import re import re
import time import time

View File

@ -2,6 +2,7 @@
This module contains some logic to help assemble more sophisticated parsers. This module contains some logic to help assemble more sophisticated parsers.
""" """
from typing import Iterator, Mapping, Optional from typing import Iterator, Mapping, Optional
from langchain_core.documents import Document from langchain_core.documents import Document

View File

@ -1,4 +1,5 @@
"""Module contains common parsers for PDFs.""" """Module contains common parsers for PDFs."""
from __future__ import annotations from __future__ import annotations
import warnings import warnings

View File

@ -1,4 +1,5 @@
"""Module includes a registry of default parser configurations.""" """Module includes a registry of default parser configurations."""
from langchain_community.document_loaders.base import BaseBlobParser from langchain_community.document_loaders.base import BaseBlobParser
from langchain_community.document_loaders.parsers.generic import MimeTypeBasedParser from langchain_community.document_loaders.parsers.generic import MimeTypeBasedParser
from langchain_community.document_loaders.parsers.msword import MsWordParser from langchain_community.document_loaders.parsers.msword import MsWordParser

View File

@ -1,4 +1,5 @@
"""Module for parsing text files..""" """Module for parsing text files.."""
from typing import Iterator from typing import Iterator
from langchain_core.documents import Document from langchain_core.documents import Document

View File

@ -213,9 +213,9 @@ class PebbloSafeLoader(BaseLoader):
if loading_end is True: if loading_end is True:
payload["loading_end"] = "true" payload["loading_end"] = "true"
if "loader_details" in payload: if "loader_details" in payload:
payload["loader_details"][ payload["loader_details"]["source_aggregate_size"] = (
"source_aggregate_size" self.source_aggregate_size
] = self.source_aggregate_size )
payload = Doc(**payload).dict(exclude_unset=True) payload = Doc(**payload).dict(exclude_unset=True)
# Raw payload to be sent to classifier # Raw payload to be sent to classifier
if self.classifier_location == "local": if self.classifier_location == "local":

View File

@ -1,4 +1,5 @@
"""Loads RST files.""" """Loads RST files."""
from pathlib import Path from pathlib import Path
from typing import Any, List, Union from typing import Any, List, Union

View File

@ -1,4 +1,5 @@
"""Loads rich text files.""" """Loads rich text files."""
from pathlib import Path from pathlib import Path
from typing import Any, List, Union from typing import Any, List, Union

View File

@ -1,4 +1,5 @@
"""Scrapfly Web Reader.""" """Scrapfly Web Reader."""
import logging import logging
from typing import Iterator, List, Literal, Optional from typing import Iterator, List, Literal, Optional

View File

@ -61,9 +61,9 @@ class TensorflowDatasetLoader(BaseLoader):
self.split_name: str = split_name self.split_name: str = split_name
self.load_max_docs = load_max_docs self.load_max_docs = load_max_docs
"""The maximum number of documents to load.""" """The maximum number of documents to load."""
self.sample_to_document_function: Optional[ self.sample_to_document_function: Optional[Callable[[Dict], Document]] = (
Callable[[Dict], Document] sample_to_document_function
] = sample_to_document_function )
"""Custom function that transform a dataset sample into a Document.""" """Custom function that transform a dataset sample into a Document."""
self._tfds_client = TensorflowDatasets( # type: ignore[call-arg] self._tfds_client = TensorflowDatasets( # type: ignore[call-arg]

View File

@ -1,4 +1,5 @@
"""Loader that uses unstructured to load files.""" """Loader that uses unstructured to load files."""
import collections import collections
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from pathlib import Path from pathlib import Path

View File

@ -1,4 +1,5 @@
"""Loader that uses unstructured to load HTML files.""" """Loader that uses unstructured to load HTML files."""
import logging import logging
from typing import Any, List from typing import Any, List

View File

@ -1,5 +1,5 @@
"""Loader that uses Playwright to load a page, then uses unstructured to load the html. """Loader that uses Playwright to load a page, then uses unstructured to parse html."""
"""
import logging import logging
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, AsyncIterator, Dict, Iterator, List, Optional from typing import TYPE_CHECKING, AsyncIterator, Dict, Iterator, List, Optional

View File

@ -1,5 +1,5 @@
"""Loader that uses Selenium to load a page, then uses unstructured to load the html. """Loader that uses Selenium to load a page, then uses unstructured to load the html."""
"""
import logging import logging
from typing import TYPE_CHECKING, List, Literal, Optional, Union from typing import TYPE_CHECKING, List, Literal, Optional, Union

View File

@ -1,4 +1,5 @@
"""Simple reader that reads weather data from OpenWeatherMap API""" """Simple reader that reads weather data from OpenWeatherMap API"""
from __future__ import annotations from __future__ import annotations
from datetime import datetime from datetime import datetime

View File

@ -1,4 +1,5 @@
"""Loads word documents.""" """Loads word documents."""
import os import os
import tempfile import tempfile
from abc import ABC from abc import ABC

View File

@ -1,4 +1,5 @@
"""Loads Microsoft Excel files.""" """Loads Microsoft Excel files."""
from pathlib import Path from pathlib import Path
from typing import Any, List, Union from typing import Any, List, Union

View File

@ -1,4 +1,5 @@
"""Loads YouTube transcript.""" """Loads YouTube transcript."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -1,4 +1,5 @@
"""Transform documents""" """Transform documents"""
from typing import Any, Callable, List, Sequence from typing import Any, Callable, List, Sequence
import numpy as np import numpy as np

View File

@ -1,4 +1,5 @@
"""Reorder documents""" """Reorder documents"""
from typing import Any, List, Sequence from typing import Any, List, Sequence
from langchain_core.documents import BaseDocumentTransformer, Document from langchain_core.documents import BaseDocumentTransformer, Document

View File

@ -1,4 +1,5 @@
"""Document transformers that use OpenAI Functions models""" """Document transformers that use OpenAI Functions models"""
from typing import Any, Dict, Optional, Sequence, Type, Union from typing import Any, Dict, Optional, Sequence, Type, Union
from langchain_core.documents import BaseDocumentTransformer, Document from langchain_core.documents import BaseDocumentTransformer, Document

View File

@ -1,4 +1,5 @@
"""Anyscale embeddings wrapper.""" """Anyscale embeddings wrapper."""
from __future__ import annotations from __future__ import annotations
from typing import Dict from typing import Dict

View File

@ -1,4 +1,5 @@
""" This file is for LLMRails Embedding """ """This file is for LLMRails Embedding"""
from typing import Dict, List, Optional from typing import Dict, List, Optional
import requests import requests

View File

@ -132,13 +132,13 @@ class OCIGenAIEmbeddings(BaseModel, Embeddings):
oci_config=client_kwargs["config"] oci_config=client_kwargs["config"]
) )
elif values["auth_type"] == OCIAuthType(3).name: elif values["auth_type"] == OCIAuthType(3).name:
client_kwargs[ client_kwargs["signer"] = (
"signer" oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
] = oci.auth.signers.InstancePrincipalsSecurityTokenSigner() )
elif values["auth_type"] == OCIAuthType(4).name: elif values["auth_type"] == OCIAuthType(4).name:
client_kwargs[ client_kwargs["signer"] = (
"signer" oci.auth.signers.get_resource_principals_signer()
] = oci.auth.signers.get_resource_principals_signer() )
else: else:
raise ValueError("Please provide valid value to auth_type") raise ValueError("Please provide valid value to auth_type")

View File

@ -1,4 +1,5 @@
"""HuggingFace sentence_transformer embedding models.""" """HuggingFace sentence_transformer embedding models."""
from langchain_community.embeddings.huggingface import HuggingFaceEmbeddings from langchain_community.embeddings.huggingface import HuggingFaceEmbeddings
SentenceTransformerEmbeddings = HuggingFaceEmbeddings SentenceTransformerEmbeddings = HuggingFaceEmbeddings

View File

@ -1,4 +1,5 @@
"""Wrapper around YandexGPT embedding models.""" """Wrapper around YandexGPT embedding models."""
from __future__ import annotations from __future__ import annotations
import logging import logging
@ -105,15 +106,15 @@ class YandexGPTEmbeddings(BaseModel, Embeddings):
if not values.get("doc_model_uri"): if not values.get("doc_model_uri"):
if values["folder_id"] == "": if values["folder_id"] == "":
raise ValueError("'doc_model_uri' or 'folder_id' must be provided.") raise ValueError("'doc_model_uri' or 'folder_id' must be provided.")
values[ values["doc_model_uri"] = (
"doc_model_uri" f"emb://{values['folder_id']}/{values['doc_model_name']}/{values['model_version']}"
] = f"emb://{values['folder_id']}/{values['doc_model_name']}/{values['model_version']}" )
if not values.get("model_uri"): if not values.get("model_uri"):
if values["folder_id"] == "": if values["folder_id"] == "":
raise ValueError("'model_uri' or 'folder_id' must be provided.") raise ValueError("'model_uri' or 'folder_id' must be provided.")
values[ values["model_uri"] = (
"model_uri" f"emb://{values['folder_id']}/{values['model_name']}/{values['model_version']}"
] = f"emb://{values['folder_id']}/{values['model_name']}/{values['model_version']}" )
if values["disable_request_logging"]: if values["disable_request_logging"]:
values["_grpc_metadata"].append( values["_grpc_metadata"].append(
( (

View File

@ -6,6 +6,7 @@ There could be multiple strategies for selecting examples. For example, one coul
select examples based on the similarity of the input to the examples. Another select examples based on the similarity of the input to the examples. Another
strategy could be to select examples based on the diversity of the examples. strategy could be to select examples based on the diversity of the examples.
""" """
from langchain_community.example_selectors.ngram_overlap import ( from langchain_community.example_selectors.ngram_overlap import (
NGramOverlapExampleSelector, NGramOverlapExampleSelector,
ngram_overlap_score, ngram_overlap_score,

View File

@ -3,6 +3,7 @@
https://www.nltk.org/_modules/nltk/translate/bleu_score.html https://www.nltk.org/_modules/nltk/translate/bleu_score.html
https://aclanthology.org/P02-1040.pdf https://aclanthology.org/P02-1040.pdf
""" """
from typing import Dict, List from typing import Dict, List
import numpy as np import numpy as np

View File

@ -1,4 +1,5 @@
"""Networkx wrapper for graph operations.""" """Networkx wrapper for graph operations."""
from __future__ import annotations from __future__ import annotations
from typing import Any, List, NamedTuple, Optional, Tuple from typing import Any, List, NamedTuple, Optional, Tuple

View File

@ -1,4 +1,5 @@
"""Wrapper around Anyscale Endpoint""" """Wrapper around Anyscale Endpoint"""
from typing import ( from typing import (
Any, Any,
Dict, Dict,

View File

@ -44,8 +44,7 @@ class _DatabricksClientBase(BaseModel, ABC):
@abstractmethod @abstractmethod
def post( def post(
self, request: Any, transform_output_fn: Optional[Callable[..., str]] = None self, request: Any, transform_output_fn: Optional[Callable[..., str]] = None
) -> Any: ) -> Any: ...
...
@property @property
def llm(self) -> bool: def llm(self) -> bool:

View File

@ -1,4 +1,5 @@
"""Wrapper around EdenAI's Generation API.""" """Wrapper around EdenAI's Generation API."""
import logging import logging
from typing import Any, Dict, List, Literal, Optional from typing import Any, Dict, List, Literal, Optional

View File

@ -1,4 +1,5 @@
"""Wrapper around Konko AI's Completion API.""" """Wrapper around Konko AI's Completion API."""
import logging import logging
import warnings import warnings
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional

View File

@ -39,12 +39,12 @@ class LayerupSecurity(LLM):
response_guardrails: Optional[List[str]] = [] response_guardrails: Optional[List[str]] = []
mask: bool = False mask: bool = False
metadata: Optional[Dict[str, Any]] = {} metadata: Optional[Dict[str, Any]] = {}
handle_prompt_guardrail_violation: Callable[ handle_prompt_guardrail_violation: Callable[[dict], str] = (
[dict], str default_guardrail_violation_handler
] = default_guardrail_violation_handler )
handle_response_guardrail_violation: Callable[ handle_response_guardrail_violation: Callable[[dict], str] = (
[dict], str default_guardrail_violation_handler
] = default_guardrail_violation_handler )
client: Any #: :meta private: client: Any #: :meta private:
@root_validator(pre=True) @root_validator(pre=True)

View File

@ -1,4 +1,5 @@
"""Base interface for loading large language model APIs.""" """Base interface for loading large language model APIs."""
import json import json
from pathlib import Path from pathlib import Path
from typing import Any, Union from typing import Any, Union

View File

@ -1,4 +1,5 @@
"""Wrapper around Minimax APIs.""" """Wrapper around Minimax APIs."""
from __future__ import annotations from __future__ import annotations
import logging import logging

View File

@ -18,12 +18,10 @@ CUSTOM_ENDPOINT_PREFIX = "ocid1.generativeaiendpoint"
class Provider(ABC): class Provider(ABC):
@property @property
@abstractmethod @abstractmethod
def stop_sequence_key(self) -> str: def stop_sequence_key(self) -> str: ...
...
@abstractmethod @abstractmethod
def completion_response_to_text(self, response: Any) -> str: def completion_response_to_text(self, response: Any) -> str: ...
...
class CohereProvider(Provider): class CohereProvider(Provider):
@ -144,13 +142,13 @@ class OCIGenAIBase(BaseModel, ABC):
oci_config=client_kwargs["config"] oci_config=client_kwargs["config"]
) )
elif values["auth_type"] == OCIAuthType(3).name: elif values["auth_type"] == OCIAuthType(3).name:
client_kwargs[ client_kwargs["signer"] = (
"signer" oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
] = oci.auth.signers.InstancePrincipalsSecurityTokenSigner() )
elif values["auth_type"] == OCIAuthType(4).name: elif values["auth_type"] == OCIAuthType(4).name:
client_kwargs[ client_kwargs["signer"] = (
"signer" oci.auth.signers.get_resource_principals_signer()
] = oci.auth.signers.get_resource_principals_signer() )
else: else:
raise ValueError( raise ValueError(
"Please provide valid value to auth_type, " "Please provide valid value to auth_type, "

View File

@ -93,9 +93,9 @@ class OpenLLM(LLM):
"""Keyword arguments to be passed to openllm.LLM""" """Keyword arguments to be passed to openllm.LLM"""
_runner: Optional[openllm.LLMRunner] = PrivateAttr(default=None) _runner: Optional[openllm.LLMRunner] = PrivateAttr(default=None)
_client: Union[ _client: Union[openllm.client.HTTPClient, openllm.client.GrpcClient, None] = (
openllm.client.HTTPClient, openllm.client.GrpcClient, None PrivateAttr(default=None)
] = PrivateAttr(default=None) )
class Config: class Config:
extra = "forbid" extra = "forbid"
@ -108,8 +108,7 @@ class OpenLLM(LLM):
model_id: Optional[str] = ..., model_id: Optional[str] = ...,
embedded: Literal[True, False] = ..., embedded: Literal[True, False] = ...,
**llm_kwargs: Any, **llm_kwargs: Any,
) -> None: ) -> None: ...
...
@overload @overload
def __init__( def __init__(
@ -118,8 +117,7 @@ class OpenLLM(LLM):
server_url: str = ..., server_url: str = ...,
server_type: Literal["grpc", "http"] = ..., server_type: Literal["grpc", "http"] = ...,
**llm_kwargs: Any, **llm_kwargs: Any,
) -> None: ) -> None: ...
...
def __init__( def __init__(
self, self,

View File

@ -3,6 +3,7 @@
Based on https://github.com/saharNooby/rwkv.cpp/blob/master/rwkv/chat_with_bot.py 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 https://github.com/BlinkDL/ChatRWKV/blob/main/v2/chat.py
""" """
from typing import Any, Dict, List, Mapping, Optional, Set from typing import Any, Dict, List, Mapping, Optional, Set
from langchain_core.callbacks import CallbackManagerForLLMRun from langchain_core.callbacks import CallbackManagerForLLMRun

Some files were not shown because too many files have changed in this diff Show More