langchain/libs/core
Jeremy Naccache a14cf87576
core[patch]: Add **kwargs to Langchain's dumps() to allow passing of json.dumps() … (#10628)
…parameters.

In Langchain's `dumps()` function, I've added a `**kwargs` parameter.
This allows users to pass additional parameters to the underlying
`json.dumps()` function, providing greater flexibility and control over
JSON serialization.

Many parameters available in `json.dumps()` can be useful or even
necessary in specific situations. For example, when using an Agent with
return_intermediate_steps set to true, the output is a list of
AgentAction objects. These objects can't be serialized without using
Langchain's `dumps()` function.

The issue arises when using the Agent with a language other than
English, which may contain non-ASCII characters like 'é'. The default
behavior of `json.dumps()` sets ensure_ascii to true, converting
`{"name": "José"}` into `{"name": "Jos\u00e9"}`. This can make the
output hard to read, especially in the case of intermediate steps in
agent logs.

By allowing users to pass additional parameters to `json.dumps()` via
Langchain's dumps(), we can solve this problem. For instance, users can
set `ensure_ascii=False` to maintain the original characters.

This update also enables users to pass other useful `json.dumps()`
parameters like `sort_keys`, providing even more flexibility.

The implementation takes into account edge cases where a user might pass
a "default" parameter, which is already defined by `dumps()`, or an
"indent" parameter, which is also predefined if `pretty=True` is set.

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2023-11-30 08:52:24 -08:00
..
langchain_core core[patch]: Add **kwargs to Langchain's dumps() to allow passing of json.dumps() … (#10628) 2023-11-30 08:52:24 -08:00
scripts INFRA: Lint for imports (#13632) 2023-11-21 17:42:56 -08:00
tests Track RunnableAssign as a separate run trace (#13972) 2023-11-28 22:02:31 +00:00
Makefile infra[patch]: add base deps and fix docs lint (#13998) 2023-11-28 17:27:37 -08:00
poetry.lock RELEASE: 0.0.341 (#13926) 2023-11-27 09:51:12 -08:00
pyproject.toml core[patch]: release 0.0.7 (#13989) 2023-11-28 14:05:01 -08:00
README.md Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00

langchain-core