Christophe Bornet
b3885c124f
core: Add ruff rules TC ( #29268 )
...
See https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc
Some fixes done for TC001,TC002 and TC003 but these rules are excluded
since they don't play well with Pydantic.
---------
Co-authored-by: Chester Curme <chester.curme@gmail.com >
2025-02-26 19:39:05 +00:00
Christophe Bornet
d31ec8810a
core: Add ruff rules for error messages (EM) ( #26965 )
...
All auto-fixes
Co-authored-by: Erick Friis <erick@langchain.dev >
2024-10-07 22:12:28 +00:00
Christophe Bornet
db8845a62a
core: Add ruff rules for pycodestyle Warning (W) ( #26964 )
...
All auto-fixes.
2024-09-30 09:31:43 -04:00
Christophe Bornet
3a1b9259a7
core: Add ruff rules for comprehensions (C4) ( #26829 )
2024-09-25 09:34:17 -04:00
Christophe Bornet
a47b332841
core: Put Python version as a project requirement so it is considered by ruff ( #26608 )
...
Ruff doesn't know about the python version in
`[tool.poetry.dependencies]`. It can get it from
`project.requires-python`.
Notes:
* poetry seems to have issues getting the python constraints from
`requires-python` and using `python` in per dependency constraints. So I
had to duplicate the info. I will open an issue on poetry.
* `inspect.isclass()` doesn't work correctly with `GenericAlias`
(`list[...]`, `dict[..., ...]`) on Python <3.11 so I added some `not
isinstance(type, GenericAlias)` checks:
Python 3.11
```pycon
>>> import inspect
>>> inspect.isclass(list)
True
>>> inspect.isclass(list[str])
False
```
Python 3.9
```pycon
>>> import inspect
>>> inspect.isclass(list)
True
>>> inspect.isclass(list[str])
True
```
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com >
2024-09-18 14:37:57 +00:00
Christophe Bornet
3a99467ccb
core[patch]: Add ruff rule UP006(use PEP585 annotations) ( #26574 )
...
* Added rules `UPD006` now that Pydantic is v2+
---------
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com >
2024-09-17 21:22:50 +00:00
Erick Friis
c2a3021bb0
multiple: pydantic 2 compatibility, v0.3 ( #26443 )
...
Signed-off-by: ChengZi <chen.zhang@zilliz.com >
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com >
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com >
Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com >
Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com >
Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no >
Co-authored-by: Bagatur <baskaryan@gmail.com >
Co-authored-by: ccurme <chester.curme@gmail.com >
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com >
Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com >
Co-authored-by: ZhangShenao <15201440436@163.com >
Co-authored-by: Friso H. Kingma <fhkingma@gmail.com >
Co-authored-by: ChengZi <chen.zhang@zilliz.com >
Co-authored-by: Nuno Campos <nuno@langchain.dev >
Co-authored-by: Morgante Pell <morgantep@google.com >
2024-09-13 14:38:45 -07:00
Nuno Campos
160fc7f246
core: Move json parsing in base chat model / output parser to bg thread ( #24031 )
...
- add version of AIMessageChunk.__add__ that can add many chunks,
instead of only 2
- In agenerate_from_stream merge and parse chunks in bg thread
- In output parse base classes do more work in bg threads where
appropriate
---------
Co-authored-by: William FH <13333726+hinthornw@users.noreply.github.com >
2024-07-09 12:26:36 -07:00
Leonid Ganeline
12c92b6c19
core: docstrings outputs
( #23889 )
...
Added missed docstrings. Formatted docstrings to the consistent form.
2024-07-05 12:18:17 -04:00
Bagatur
a0c2281540
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()
```
2024-07-03 10:33:27 -07:00
Eugene Yurtsev
3c917204dc
core[patch]: Add doc-strings to outputs, fix @root_validator ( #23190 )
...
- Document outputs namespace
- Update a vanilla @root_validator that was missed
2024-06-19 14:59:06 -04:00
Bagatur
50186da0a1
infra: rm unused # noqa violations ( #22049 )
...
Updating #21137
2024-05-22 15:21:08 -07:00
Bagatur
cb25fa0d55
core[patch]: fix ChatGeneration.text with content blocks ( #20294 )
2024-04-10 15:54:06 -07:00
Leonid Ganeline
2f2b77602e
docs: modules descriptions ( #17844 )
...
Several `core` modules do not have descriptions, like the
[agent](https://api.python.langchain.com/en/latest/core_api_reference.html#module-langchain_core.agents )
module.
- Added missed module descriptions. The descriptions are mostly copied
from the `langchain` or `community` package modules.
2024-02-21 15:58:21 -08:00
Leonid Ganeline
ae66bcbc10
core[patch]: docstring update ( #16813 )
...
- added missed docstrings
- formated docstrings to consistent form
2024-02-09 12:47:41 -08:00
Bagatur
84bf5787a7
core[patch], openai[patch]: Chat openai stream logprobs ( #16218 )
2024-01-19 09:16:09 -08:00
Harrison Chase
f5befe3b89
manual mapping ( #14422 )
2023-12-08 16:29:33 -08:00
Bagatur
d32e511826
REFACTOR: Refactor langchain_core ( #13627 )
...
Changes:
- remove langchain_core/schema since no clear distinction b/n schema and
non-schema modules
- make every module that doesn't end in -y plural
- where easy have 1-2 classes per file
- no more than one level of nesting in directories
- only import from top level core modules in langchain
2023-11-21 08:35:29 -08:00