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
Bagatur
8e0d5813c2
langchain[patch], experimental[patch]: replace langchain.schema imports ( #15410 )
...
Import from core instead.
Ran:
```bash
git grep -l 'from langchain.schema\.output_parser' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.output_parser/from\ langchain_core.output_parsers/g"
git grep -l 'from langchain.schema\.messages' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.messages/from\ langchain_core.messages/g"
git grep -l 'from langchain.schema\.document' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.document/from\ langchain_core.documents/g"
git grep -l 'from langchain.schema\.runnable' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.runnable/from\ langchain_core.runnables/g"
git grep -l 'from langchain.schema\.vectorstore' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.vectorstore/from\ langchain_core.vectorstores/g"
git grep -l 'from langchain.schema\.language_model' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.language_model/from\ langchain_core.language_models/g"
git grep -l 'from langchain.schema\.embeddings' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.embeddings/from\ langchain_core.embeddings/g"
git grep -l 'from langchain.schema\.storage' | xargs -L 1 sed -i '' "s/from\ langchain\.schema\.storage/from\ langchain_core.stores/g"
git checkout master libs/langchain/tests/unit_tests/schema/
make format
cd libs/experimental
make format
cd ../langchain
make format
```
2024-01-02 15:09:45 -05:00