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
..
2024-06-24 14:48:23 -04:00
2024-07-15 11:34:59 -04:00
2024-07-08 16:09:29 -04:00
2024-07-11 21:45:30 +02:00
2024-07-17 12:00:16 -04:00
2024-07-22 20:07:39 +00:00
2024-07-01 20:10:15 +00:00
2024-07-01 20:10:15 +00:00
2024-05-20 14:33:57 +00:00
2024-07-13 08:59:03 -07:00
2024-07-22 20:07:39 +00:00
2024-07-01 20:10:15 +00:00
2024-07-19 02:25:38 +00:00
2024-07-03 10:33:27 -07:00
2024-07-01 20:10:15 +00:00
2024-07-08 16:09:29 -04:00
2024-07-01 20:10:15 +00:00
2024-07-08 16:09:29 -04:00
2024-05-22 21:47:28 +00:00
2024-07-08 16:09:29 -04:00
2024-07-08 16:09:29 -04:00
2024-07-08 16:09:29 -04:00
2024-07-03 10:33:27 -07:00
2024-07-08 16:09:29 -04:00
2024-07-22 20:07:39 +00:00
2024-06-27 22:12:16 +00:00
2024-07-11 10:55:02 -04:00
2024-05-22 08:12:53 -07:00
2024-07-08 16:09:29 -04:00
2024-07-03 10:33:27 -07:00
2024-07-08 16:09:29 -04:00
2024-07-11 11:31:48 -07:00
2024-07-08 16:09:29 -04:00
2024-06-12 13:59:05 -04:00
2024-07-02 08:48:49 -04:00
2024-07-08 16:09:29 -04:00
2024-07-03 10:33:27 -07:00
2024-07-08 16:09:29 -04:00
2024-07-08 16:09:29 -04:00
2024-07-19 20:19:14 -07:00
2024-07-22 20:07:39 +00:00
2024-07-08 16:09:29 -04:00
2024-07-03 10:33:27 -07:00
2024-07-08 16:09:29 -04:00
2024-07-01 18:12:24 +00:00