ccurme
2d6b0bf3e3
core[patch]: add to RunnableLambda docstring ( #24575 )
...
Explain behavior when function returns a runnable.
2024-07-23 20:46:44 +00:00
Bagatur
918e1c8a93
core[patch]: Release 0.2.23 ( #24557 )
2024-07-23 09:01:18 -07:00
ZhangShenao
a14e02ab33
core[patch]: Fix word spelling error in globals.py ( #24532 )
...
Fix word spelling error in `globals.py`
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com >
2024-07-23 14:27:16 +00:00
Bagatur
70c71efcab
core[patch]: merge_content fix ( #24526 )
2024-07-22 22:20:22 -07:00
Ben Chambers
5ac936a284
community[minor]: add document transformer for extracting links ( #24186 )
...
- **Description:** Add a DocumentTransformer for executing one or more
`LinkExtractor`s and adding the extracted links to each document.
- **Issue:** n/a
- **Depedencies:** none
---------
Co-authored-by: Eugene Yurtsev <eugene@langchain.dev >
2024-07-22 22:01:21 -04:00
Erick Friis
3dce2e1d35
all: add release notes to pypi ( #24519 )
2024-07-22 13:59:13 -07:00
Bagatur
8a140ee77c
core[patch]: don't serialize BasePromptTemplate.input_types ( #24516 )
...
Candidate fix for #24513
2024-07-22 13:30:16 -07:00
Bagatur
236e957abb
core,groq,openai,mistralai,robocorp,fireworks,anthropic[patch]: Update BaseModel subclass and instance checks to handle both v1 and proper namespaces ( #24417 )
...
After this PR chat models will correctly handle pydantic 2 with
bind_tools and with_structured_output.
```python
import pydantic
print(pydantic.__version__)
```
2.8.2
```python
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field
class Add(BaseModel):
x: int
y: int
model = ChatOpenAI().bind_tools([Add])
print(model.invoke('2 + 5').tool_calls)
model = ChatOpenAI().with_structured_output(Add)
print(type(model.invoke('2 + 5')))
```
```
[{'name': 'Add', 'args': {'x': 2, 'y': 5}, 'id': 'call_PNUFa4pdfNOYXxIMHc6ps2Do', 'type': 'tool_call'}]
<class '__main__.Add'>
```
```python
from langchain_openai import ChatOpenAI
from pydantic.v1 import BaseModel, Field
class Add(BaseModel):
x: int
y: int
model = ChatOpenAI().bind_tools([Add])
print(model.invoke('2 + 5').tool_calls)
model = ChatOpenAI().with_structured_output(Add)
print(type(model.invoke('2 + 5')))
```
```python
[{'name': 'Add', 'args': {'x': 2, 'y': 5}, 'id': 'call_hhiHYP441cp14TtrHKx3Upg0', 'type': 'tool_call'}]
<class '__main__.Add'>
```
Addresses issues: https://github.com/langchain-ai/langchain/issues/22782
---------
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com >
2024-07-22 20:07:39 +00:00
ccurme
0f7569ddbc
core[patch]: enable RunnableWithMessageHistory without config ( #23775 )
...
Feedback that `RunnableWithMessageHistory` is unwieldy compared to
ConversationChain and similar legacy abstractions is common.
Legacy chains using memory typically had no explicit notion of threads
or separate sessions. To use `RunnableWithMessageHistory`, users are
forced to introduce this concept into their code. This possibly felt
like unnecessary boilerplate.
Here we enable `RunnableWithMessageHistory` to run without a config if
the `get_session_history` callable has no arguments. This enables
minimal implementations like the following:
```python
from langchain_core.chat_history import InMemoryChatMessageHistory
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-3.5-turbo-0125")
memory = InMemoryChatMessageHistory()
chain = RunnableWithMessageHistory(llm, lambda: memory)
chain.invoke("Hi I'm Bob") # Hello Bob!
chain.invoke("What is my name?") # Your name is Bob.
```
2024-07-22 10:36:53 -04:00
Nuno Campos
947628311b
core[patch]: Accept configurable keys top-level ( #23806 )
...
Co-authored-by: Bagatur <baskaryan@gmail.com >
2024-07-20 03:49:00 +00:00
Will Badart
74e3d796f1
core[patch]: ensure iterator_ in scope for _atransform_stream_with_config except ( #24454 )
...
Before, if an exception was raised in the outer `try` block in
`Runnable._atransform_stream_with_config` before `iterator_` is
assigned, the corresponding `finally` block would blow up with an
`UnboundLocalError`:
```txt
UnboundLocalError: cannot access local variable 'iterator_' where it is not associated with a value
```
By assigning an initial value to `iterator_` before entering the `try`
block, this commit ensures that the `finally` can run, and not bury the
"true" exception under a "During handling of the above exception [...]"
traceback.
Thanks for your consideration!
2024-07-20 03:24:04 +00:00
Eugene Yurtsev
5e48f35fba
core[minor]: Relax constraints on type checking for tools and parsers ( #24459 )
...
This will allow tools and parsers to accept pydantic models from any of
the
following namespaces:
* pydantic.BaseModel with pydantic 1
* pydantic.BaseModel with pydantic 2
* pydantic.v1.BaseModel with pydantic 2
2024-07-19 21:47:34 -04:00
Eun Hye Kim
9aae8ef416
core[patch]: Fix utils.json_schema.dereference_refs ( #24335 KeyError: 400 in JSON schema processing) ( #24337 )
...
Description:
This PR fixes a KeyError: 400 that occurs in the JSON schema processing
within the reduce_openapi_spec function. The _retrieve_ref function in
json_schema.py was modified to handle missing components gracefully by
continuing to the next component if the current one is not found. This
ensures that the OpenAPI specification is fully interpreted and the
agent executes without errors.
Issue:
Fixes issue #24335
Dependencies:
No additional dependencies are required for this change.
Twitter handle:
@lunara_x
2024-07-19 13:31:00 -04:00
Erick Friis
ef049769f0
core[patch]: Release 0.2.22 ( #24423 )
...
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com >
2024-07-19 09:09:24 -07:00
Bagatur
cd19ba9a07
core[patch]: core lint fix ( #24447 )
2024-07-19 09:01:22 -07:00
Nuno Campos
62b6965d2a
core: In ensure_config don't copy dunder configurable keys to metadata ( #24420 )
2024-07-18 22:28:52 +00:00
Eugene Yurtsev
ef22ebe431
standard-tests[patch]: Add pytest assert rewrites ( #24408 )
...
This will surface nice error messages in subclasses that fail assertions.
2024-07-18 21:41:11 +00:00
Eugene Yurtsev
f62b323108
core[minor]: Support all versions of pydantic base model in argsschema ( #24418 )
...
This adds support to any pydantic base model for tools.
The only potential issue is that `get_input_schema()` will not always
return a v1 base model.
2024-07-18 17:14:23 -04:00
Eugene Yurtsev
570566b858
core[patch]: Update API reference for astream events ( #24359 )
...
Update the API reference for astream events to include information about
custom events.
2024-07-17 21:48:53 -04:00
Bagatur
a4c101ae97
core[patch]: Release 0.2.21 ( #24372 )
2024-07-17 22:44:35 +00:00
William FH
c5a07e2dd8
core[patch]: add InjectedToolArg annotation ( #24279 )
...
```python
from typing_extensions import Annotated
from langchain_core.tools import tool, InjectedToolArg
from langchain_anthropic import ChatAnthropic
@tool
def multiply(x: int, y: int, not_for_model: Annotated[dict, InjectedToolArg]) -> str:
"""multiply."""
return x * y
ChatAnthropic(model='claude-3-sonnet-20240229',).bind_tools([multiply]).invoke('5 times 3').tool_calls
'''
-> [{'name': 'multiply',
'args': {'x': 5, 'y': 3},
'id': 'toolu_01Y1QazYWhu4R8vF4hF4z9no',
'type': 'tool_call'}]
'''
```
---------
Co-authored-by: Bagatur <baskaryan@gmail.com >
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com >
2024-07-17 15:28:40 -07:00
Eugene Yurtsev
96bac8e20d
core[patch]: Fix regression requiring input_variables in few chat prompt templates ( #24360 )
...
* Fix regression that requires users passing input_variables=[].
* Regression introduced by my own changes to this PR:
https://github.com/langchain-ai/langchain/pull/22851
2024-07-17 18:14:57 -04:00
Eugene Yurtsev
9e4a0e76f6
core[patch]: Fix one unit test for chat prompt template ( #24362 )
...
Minor change that fixes a unit test that had missing assertions.
2024-07-17 18:56:48 +00:00
Bagatur
80e7cd6cff
core[patch]: Release 0.2.20 ( #24322 )
2024-07-16 15:04:36 -07:00
Eugene Yurtsev
616196c620
Docs: Add how to dispatch custom callback events ( #24278 )
...
* Add how-to guide for dispatching custom callback events.
* Add links from index to the how to guide
* Add link from streaming from within a tool
* Update versionadded to correct release
https://github.com/langchain-ai/langchain/releases/tag/langchain-core%3D%3D0.2.15
2024-07-16 17:38:32 -04:00
Leonid Ganeline
5ccf8ebfac
core: docstrings vectorstores update ( #24281 )
...
Added missed docstrings. Formatted docstrings to the consistent form.
---------
Co-authored-by: Erick Friis <erick@langchain.dev >
2024-07-16 16:58:11 +00:00
Bagatur
dc42279eb5
core[patch]: fix Typing.cast import ( #24313 )
...
Fixes #24287
2024-07-16 16:53:48 +00:00
Leonid Ganeline
5fcf2ef7ca
core: docstrings documents ( #23506 )
...
Added missed docstrings. Formatted docstrings to the consistent form.
2024-07-16 10:43:54 -04:00
Shenhai Ran
5f2dea2b20
core[patch]: Add encoding options when create prompt template from a file ( #24054 )
...
- Uses default utf-8 encoding for loading prompt templates from file
---------
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com >
2024-07-16 09:35:09 -04:00
Leonid Ganeline
198b85334f
core[patch]: docstrings langchain_core/ files update ( #24285 )
...
Added missed docstrings. Formatted docstrings to the consistent form.
2024-07-16 09:21:51 -04:00
Tibor Reiss
1c753d1e81
core[patch]: Update typing for template format to include jinja2 as a Literal ( #24144 )
...
Fixes #23929 via adjusting the typing
2024-07-16 09:09:42 -04:00
JP-Ellis
f77659463a
core[patch]: allow message utils to work with lcel ( #23743 )
...
The functions `convert_to_messages` has had an expansion of the
arguments it can take:
1. Previously, it only could take a `Sequence` in order to iterate over
it. This has been broadened slightly to an `Iterable` (which should have
no other impact).
2. Support for `PromptValue` and `BaseChatPromptTemplate` has been
added. These are generated when combining messages using the overloaded
`+` operator.
Functions which rely on `convert_to_messages` (namely `filter_messages`,
`merge_message_runs` and `trim_messages`) have had the type of their
arguments similarly expanded.
Resolves #23706 .
<!--
If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.
-->
---------
Signed-off-by: JP-Ellis <josh@jpellis.me >
Co-authored-by: Bagatur <baskaryan@gmail.com >
2024-07-15 08:58:05 -07:00
Harold Martin
ccdaf14eff
docs: Spell check fixes ( #24217 )
...
**Description:** Spell check fixes for docs, comments, and a couple of
strings. No code change e.g. variable names.
**Issue:** none
**Dependencies:** none
**Twitter handle:** hmartin
2024-07-15 15:51:43 +00:00
Leonid Ganeline
cacdf96f9c
core docstrings tracers update ( #24211 )
...
Added missed docstrings. Formatted docstrings to the consistent form.
2024-07-15 11:37:09 -04:00
Leonid Ganeline
36ee083753
core: docstrings utils update ( #24213 )
...
Added missed docstrings. Formatted docstrings to the consistent form.
2024-07-15 11:36:00 -04:00
Bagatur
620b118c70
core[patch]: Release 0.2.19 ( #24272 )
2024-07-15 07:51:30 -07:00
ccurme
888fbc07b5
core[patch]: support passing args_schema through as_tool ( #24269 )
...
Note: this allows the schema to be passed in positionally.
```python
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.runnables import RunnableLambda
class Add(BaseModel):
"""Add two integers together."""
a: int = Field(..., description="First integer")
b: int = Field(..., description="Second integer")
def add(input: dict) -> int:
return input["a"] + input["b"]
runnable = RunnableLambda(add)
as_tool = runnable.as_tool(Add)
as_tool.args_schema.schema()
```
```
{'title': 'Add',
'description': 'Add two integers together.',
'type': 'object',
'properties': {'a': {'title': 'A',
'description': 'First integer',
'type': 'integer'},
'b': {'title': 'B', 'description': 'Second integer', 'type': 'integer'}},
'required': ['a', 'b']}
```
2024-07-15 07:51:05 -07:00
Bagatur
0da5078cad
langchain[minor]: Generic configurable model ( #23419 )
...
alternative to
[23244](https://github.com/langchain-ai/langchain/pull/23244 ). allows
you to use chat model declarative methods

2024-07-15 01:11:01 +00:00
Bagatur
d0728b0ba0
core[patch]: add tool name to tool message ( #24243 )
...
Copying current ToolNode behavior
2024-07-15 00:42:40 +00:00
Bagatur
5c3e2612da
core[patch]: Release 0.2.18 ( #24230 )
2024-07-13 09:14:43 -07:00
Bagatur
65321bf975
core[patch]: fix ToolCall "type" when streaming ( #24218 )
2024-07-13 08:59:03 -07:00
Eugene Yurtsev
8d82a0d483
core[patch]: Mark GraphVectorStore as beta ( #24195 )
...
* This PR marks graph vectorstore as beta
2024-07-12 14:28:06 -04:00
Bagatur
0a1e475a30
core[patch]: Release 0.2.17 ( #24189 )
2024-07-12 17:08:29 +00:00
Bagatur
6166ea67a8
core[minor]: rename ToolMessage.raw_output -> artifact ( #24185 )
2024-07-12 09:52:44 -07:00
Leonid Ganeline
aa3e3cfa40
core[patch]: docstrings runnables update ( #24161 )
...
Added missed docstrings. Formatted docstrings to the consistent form.
2024-07-12 11:27:06 -04:00
Erick Friis
1132fb801b
core: release 0.2.16 ( #24159 )
2024-07-11 23:59:41 +00:00
Nuno Campos
1d37aa8403
core: Remove extra newline ( #24157 )
2024-07-11 23:55:36 +00:00
Bagatur
8d100c58de
core[patch]: Tool accept RunnableConfig ( #24143 )
...
Relies on #24038
---------
Co-authored-by: Erick Friis <erick@langchain.dev >
2024-07-11 22:13:17 +00:00
Bagatur
5fd1e67808
core[minor], integrations...[patch]: Support ToolCall as Tool input and ToolMessage as Tool output ( #24038 )
...
Changes:
- ToolCall, InvalidToolCall and ToolCallChunk can all accept a "type"
parameter now
- LLM integration packages add "type" to all the above
- Tool supports ToolCall inputs that have "type" specified
- Tool outputs ToolMessage when a ToolCall is passed as input
- Tools can separately specify ToolMessage.content and
ToolMessage.raw_output
- Tools emit events for validation errors (using on_tool_error and
on_tool_end)
Example:
```python
@tool("structured_api", response_format="content_and_raw_output")
def _mock_structured_tool_with_raw_output(
arg1: int, arg2: bool, arg3: Optional[dict] = None
) -> Tuple[str, dict]:
"""A Structured Tool"""
return f"{arg1} {arg2}", {"arg1": arg1, "arg2": arg2, "arg3": arg3}
def test_tool_call_input_tool_message_with_raw_output() -> None:
tool_call: Dict = {
"name": "structured_api",
"args": {"arg1": 1, "arg2": True, "arg3": {"img": "base64string..."}},
"id": "123",
"type": "tool_call",
}
expected = ToolMessage("1 True", raw_output=tool_call["args"], tool_call_id="123")
tool = _mock_structured_tool_with_raw_output
actual = tool.invoke(tool_call)
assert actual == expected
tool_call.pop("type")
with pytest.raises(ValidationError):
tool.invoke(tool_call)
actual_content = tool.invoke(tool_call["args"])
assert actual_content == expected.content
```
---------
Co-authored-by: Erick Friis <erick@langchain.dev >
2024-07-11 14:54:02 -07:00
Bagatur
eeb996034b
core[patch]: Release 0.2.15 ( #24149 )
2024-07-11 21:34:25 +00:00