Commit Graph

778 Commits (9a29398fe629aa62fc5bc237ec20f8461a039f7f)

Author SHA1 Message Date
Erick Friis 3dc7d447aa
infra: reenable min version testing 2, ci ignore ai21 (#25709) 1 month ago
James Espichan Vilca 080741d336
core[patch]: Fix type for inner input in base prompts (#25713)
Thank you for contributing to LangChain!

- [ ] **PR title**: "langchain-core: Fix type"
- The file to modify is located in
/libs/core/langchain_core/prompts/base.py


- [ ] **PR message**: 
- **Description:** The change is a type for the inner input variable,
the type go from dict to Any. This change is required since the method
_validate input expects a type that is not only a dictionary.
    - **Dependencies:** There are no dependencies for this change


- [ ] **Add tests and docs**: 
1. A test is not needed. This error occurs because I overrode a portion
of the _validate_input method, which is causing a 'beartype' to raise an
error.
1 month ago
Christophe Bornet 7f1e444efa
partners: Use simsimd types (#25299)
The simsimd package [now has
types](https://github.com/ashvardanian/SimSIMD/releases/tag/v5.0.0)
1 month ago
Erick Friis b28bc252c4
core[patch]: mmr util (#25689) 1 month ago
Erick Friis 6096c80b71
core: pydantic output parser streaming fix (#24415)
Co-authored-by: Bagatur <baskaryan@gmail.com>
1 month ago
Eugene Yurtsev c316361115
core[patch]: Add _api.rename_parameter to support renaming of parameters in functions (#25101)
Add ability to rename paramerters in function signatures

```python

    @rename_parameter(since="2.0.0", removal="3.0.0", old="old_name", new="new_name")
    def foo(new_name: str) -> str:
        """original doc"""
        return new_name
```

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
1 month ago
Yusuke Fukasawa 0258cb96fa
core[patch]: add additionalProperties recursively to oai function if strict (#25169)
Hello. 
First of all, thank you for maintaining such a great project.

## Description
In https://github.com/langchain-ai/langchain/pull/25123, support for
structured_output is added. However, `"additionalProperties": false`
needs to be included at all levels when a nested object is generated.

error from current code:
https://gist.github.com/fufufukakaka/e9b475300e6934853d119428e390f204
```
BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for response_format 'JokeWithEvaluation': In context=('properties', 'self_evaluation'), 'additionalProperties' is required to be supplied and to be false", 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}
```

Reference: [Introducing Structured Outputs in the
API](https://openai.com/index/introducing-structured-outputs-in-the-api/)

```json
{
  "model": "gpt-4o-2024-08-06",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful math tutor."
    },
    {
      "role": "user",
      "content": "solve 8x + 31 = 2"
    }
  ],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "math_response",
      "strict": true,
      "schema": {
        "type": "object",
        "properties": {
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "explanation": {
                  "type": "string"
                },
                "output": {
                  "type": "string"
                }
              },
              "required": ["explanation", "output"],
              "additionalProperties": false
            }
          },
          "final_answer": {
            "type": "string"
          }
        },
        "required": ["steps", "final_answer"],
        "additionalProperties": false
      }
    }
  }
}
```

In the current code, `"additionalProperties": false` is only added at
the last level.
This PR introduces the `_add_additional_properties_key` function, which
recursively adds `"additionalProperties": false` to the entire JSON
schema for the request.

Twitter handle: `@fukkaa1225`

Thank you!

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
1 month ago
Bagatur b35ee09b3f
infra: xfail pydantic v2 arg to py function (#25686)
Issue to track: #25687
1 month ago
Christophe Bornet ee98da4f4e
core[patch]: Add UP(upgrade) ruff rules (#25358) 1 month ago
William FH 294f7fcb38
core[patch]: Remove different parent run id warning (#25683) 1 month ago
Vadym Barda 46d344c33d
core[patch]: support drawing nested subgraphs in draw_mermaid (#25581)
Previously the code was able to only handle a single level of nesting
for subgraphs in mermaid. This change adds support for arbitrary nesting
of subgraphs.
1 month ago
CastaChick 7d13a2f958
core[patch]: add option to specify the chunk separator in `merge_message_runs` (#24783)
**Description:**
LLM will stop generating text even in the middle of a sentence if
`finish_reason` is `length` (for OpenAI) or `stop_reason` is
`max_tokens` (for Anthropic).
To obtain longer outputs from LLM, we should call the message generation
API multiple times and merge the results into the text to circumvent the
API's output token limit.
The extra line breaks forced by the `merge_message_runs` function when
seamlessly merging messages can be annoying, so I added the option to
specify the chunk separator.

**Issue:**
No corresponding issues.

**Dependencies:**
No dependencies required.

**Twitter handle:**
@hanama_chem
https://x.com/hanama_chem

---------

Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Bagatur <baskaryan@gmail.com>
1 month ago
Ivan 5b9290a449
Fix UnionType type var replacement (#25566)
[langchain_core] Fix UnionType type var replacement

- Added types.UnionType to typing.Union mapping

Type replacement cause `TypeError: 'type' object is not subscriptable`
if any of union type comes as function `_py_38_safe_origin` return
`types.UnionType` instead of `typing.Union`

```python
>>> from types import UnionType
>>> from typing import Union, get_origin
>>> type_ = get_origin(str | None)
>>> type_
<class 'types.UnionType'>
>>> UnionType[(str, None)]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
>>> Union[(str, None)]
typing.Optional[str]
```

---------

Co-authored-by: Chester Curme <chester.curme@gmail.com>
1 month ago
William FH 8230ba47f3
core[patch]: Improve some error messages and add another test for checking RunnableWithMessageHistory (#25209)
Also add more useful error messages.

---------

Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
1 month ago
Bagatur 39c44817ae
infra: test convert_message (#25632) 1 month ago
Bagatur 628574b9c2
core[patch]: Release 0.2.34 (#25622) 1 month ago
Bagatur 0bc3845e1e
core[patch]: support oai dicts as messages (#25621)
and update langsmtih example selector docs
1 month ago
Erick Friis e37caa9b9a
core: fix fallback context overwriting (#25550)
fixes #25337
1 month ago
Bagatur 8a71f1b41b
core[minor]: add langsmith document loader (#25493)
needs tests
1 month ago
Bagatur 4bd005adb6
core[patch]: Allow bound models as token_counter in trim_messages (#25563) 1 month ago
Erick Friis e01c6789c4
core,community: add beta decorator to missed GraphVectorStore extensions (#25562) 1 month ago
Bagatur 6b98207eda
infra: test chat prompt ser/des (#25557) 1 month ago
Bagatur df98552b6f
core[patch]: Release 0.2.33 (#25498) 1 month ago
ccurme b83f1eb0d5
core, partners: implement standard tracing params for LLMs (#25410) 1 month ago
Eugene Yurtsev e18511bb22
core[minor], anthropic[patch]: Upgrade @root_validator usage to be consistent with pydantic 2 (#25457)
anthropic: Upgrade `@root_validator` usage to be consistent with
pydantic 2
core: support looking up multiple keys from env in from_env factory
1 month ago
Eugene Yurtsev eb3870e9d8
fireworks[patch]: Upgrade @root_validators to be pydantic 2 compliant (#25443)
Update @root_validators to be pydantic 2 compliant
1 month ago
William FH 75ae585deb
Merge support for group manager (#25360) 1 month ago
Bagatur ec8ffc8f40
core[patch]: Release 0.2.32 (#25420) 1 month ago
Bagatur 2494cecabf
core[patch]: tool import fix (#25419) 1 month ago
Bagatur a58d4ba340
core[patch]: Release 0.2.31 (#25388) 1 month ago
Chengyu Yan d0ad713937
core: fix issue#24660, slove error messages about `ValueError` when use model with history (#25183)
- **Description:**
This PR will slove error messages about `ValueError` when use model with
history.
Detail in #24660.
#22933 causes that
`langchain_core.runnables.history.RunnableWithMessageHistory._get_output_messages`
miss type check of `output_val` if `output_val` is `False`. After
running `RunnableWithMessageHistory._is_not_async`, `output` is `False`.

249945a572/libs/core/langchain_core/runnables/history.py (L323-L334)

15a36dd0a2/libs/core/langchain_core/runnables/history.py (L461-L471)
~~I suggest that `_get_output_messages` return empty list when
`output_val == False`.~~

- **Issue**:
  - #24660

- **Dependencies:**: No Change.

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
1 month ago
Bagatur 493e474063
docs: udpated api reference (#25172)
- Move the API reference into the vercel build
- Update api reference organization and styling
1 month ago
Eugene Yurtsev dc51cc5690
core[minor]: Prevent PydanticOutputParser from encoding schema as ASCII (#25386)
This allows users to provide parameter descriptions in the pydantic
models in other languages.

Continuing this PR: https://github.com/langchain-ai/langchain/pull/24809
1 month ago
ccurme 27690506d0
multiple: update removal targets (#25361) 1 month ago
Erick Friis 252f0877d1
core: release 0.2.30 (#25321) 1 month ago
Eugene Yurtsev 056c7c2983
core[patch]: Update API reference for fake embeddings (#25313)
Issue: https://github.com/langchain-ai/langchain/issues/24856

Using the same template for the fake embeddings in langchain_core as
used in the integrations.
1 month ago
ccurme e77eeee6ee
core[patch]: add standard tracing params for retrievers (#25240) 1 month ago
gbaian10 aa2722cbe2
docs: update numbering of items in docstring (#25267)
A problem similar to #25093 .

Co-authored-by: ccurme <chester.curme@gmail.com>
1 month ago
Eugene Yurtsev 6dd9f053e3
core[patch]: Deprecating beta upsert APIs in vectorstore (#25069)
This PR deprecates the beta upsert APIs in vectorstore.

We'll introduce them in a V2 abstraction instead to keep the existing
vectorstore implementations lighter weight.

The main problem with the existing APIs is that it's a bit more
challenging to
implement the correct behavior w/ respect to IDs since ID can be present
in
both the function signature and as an optional attribute on the document
object.

But VectorStores that pass the standard tests should have implemented
the semantics properly!

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2 months ago
Eugene Yurtsev b6f0174bb9
community[patch],core[patch]: Update EdenaiTool root_validator and add unit test in core (#25233)
This PR gets rid `root_validators(allow_reuse=True)` logic used in
EdenAI Tool in preparation for pydantic 2 upgrade.
- add another test to secret_from_env_factory
2 months ago
blueoom c3ced4c6ce
core[patch]: use time.monotonic() instead time.time() in InMemoryRateLimiter
**Description:**

The get time point method in the _consume() method of
core.rate_limiters.InMemoryRateLimiter uses time.time(), which can be
affected by system time backwards. Therefore, it is recommended to use
the monotonically increasing monotonic() to obtain the time

```python
        with self._consume_lock:
            now = time.time()  # time.time() -> time.monotonic()

            # initialize on first call to avoid a burst
            if self.last is None:
                self.last = now

            elapsed = now - self.last  # when use time.time(), elapsed may be negative when system time backwards

```
2 months ago
Bagatur 7040013140
core[patch]: fix deprecation pydantic bug (#25204)
#25004 is incompatible with pydantic < 1.10.17. Introduces fix for this.
2 months ago
Eugene Yurtsev 429a0ee7fd
core[minor]: Add factory for looking up secrets from the env (#25198)
Add factory method for looking secrets from the env.
2 months ago
Erick Friis c6ece6a96d
core: autodetect more ls params (#25044)
Co-authored-by: ccurme <chester.curme@gmail.com>
2 months ago
Eugene Yurtsev 30fb345342
core[minor]: Add from_env utility (#25189)
Add a utility that can be used as a default factory

The goal will be to start migrating from of the pydantic models to use
`from_env` as a default factory if possible.

```python

from pydantic import Field, BaseModel
from langchain_core.utils import from_env

class Foo(BaseModel):
   name: str = Field(default_factory=from_env('HELLO'))
```
2 months ago
Eugene Yurtsev 2f209d84fa
core[patch]: Add pydantic get_fields adapter (#25187)
Add adapter to get fields
2 months ago
Eugene Yurtsev 425f6ffa5b
core[patch]: Fix aindex API (#25155)
A previous PR accidentally broke the aindex API by renaming a positional
argument vectorstore into vector_store. This PR reverts this change.
2 months ago
Eugene Yurtsev 7b1a132aff
core[patch]: Add unit tests for Serializable (#25152)
Add a few test cases for serializable (many other test cases already
covered
throguh runnable tests).
2 months ago
Bagatur df99b832a7
core[patch]: support Field deprecation (#25004)
![Screenshot 2024-08-02 at 4 23 17
PM](https://github.com/user-attachments/assets/c757e093-877e-4af6-9dcd-984195454158)
2 months ago
ccurme 803eba3163
core[patch]: check for model_fields attribute (#25108)
`__fields__` raises a warning in pydantic v2
2 months ago