langchain/libs/core/tests/unit_tests
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
..
_api core[patch]: fix validation of @deprecated decorator (#22513) 2024-06-14 16:52:30 +00:00
caches core[minor]: Add maxsize for InMemoryCache (#23405) 2024-07-01 14:21:21 -04:00
callbacks core[minor]: Add dispatching for custom events (#24080) 2024-07-11 02:25:12 +00:00
chat_history core[patch],community[patch]: Move file chat history back to community (#20834) 2024-04-24 12:47:25 -04:00
data Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00
dependencies community[minor]: Add glue catalog loader (#20220) 2024-04-16 11:39:23 -04:00
document_loaders infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
documents core[minor]: Create BaseMedia object (#23639) 2024-07-01 15:07:30 -04:00
embeddings core[minor]: moved fake llms and embeddings to core (#19226) 2024-03-18 10:01:26 -07:00
example_selectors infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
examples core:adds tests for partial_variables (#15427) 2024-01-02 15:00:06 -08:00
fake core[patch]: Use InMemoryChatMessageHistory in unit tests (#23916) 2024-07-05 20:10:54 +00:00
indexing core[patch]: Clean up indexing test code (#24139) 2024-07-11 18:54:46 +00:00
language_models docs: Spell check fixes (#24217) 2024-07-15 15:51:43 +00:00
load BUG: more core fixes (#13665) 2023-11-21 15:15:48 -08:00
messages core[patch]: allow message utils to work with lcel (#23743) 2024-07-15 08:58:05 -07:00
output_parsers core[minor]: Relax constraints on type checking for tools and parsers (#24459) 2024-07-19 21:47:34 -04:00
outputs core[patch]: fix ChatGeneration.text with content blocks (#20294) 2024-04-10 15:54:06 -07:00
prompts core,groq,openai,mistralai,robocorp,fireworks,anthropic[patch]: Update BaseModel subclass and instance checks to handle both v1 and proper namespaces (#24417) 2024-07-22 20:07:39 +00:00
runnables core[patch]: enable RunnableWithMessageHistory without config (#23775) 2024-07-22 10:36:53 -04:00
stores standard-tests[patch]: Add pytest assert rewrites (#24408) 2024-07-18 21:41:11 +00:00
tracers core[minor]: Add an async root listener and with_alisteners method (#22151) 2024-06-06 16:03:44 -04:00
utils core[patch]: Fix utils.json_schema.dereference_refs (#24335 KeyError: 400 in JSON schema processing) (#24337) 2024-07-19 13:31:00 -04:00
vectorstores core[minor],community[patch],standard-tests[patch]: Move InMemoryImplementation to langchain-core (#23986) 2024-07-08 14:11:51 -07:00
__init__.py Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00
conftest.py infra: update mypy 1.10, ruff 0.5 (#23721) 2024-07-03 10:33:27 -07:00
prompt_file.txt Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00
stubs.py core: Assign missing message ids in BaseChatModel (#19863) 2024-04-02 01:18:36 +00:00
test_globals.py Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00
test_graph_vectorstores.py core[minor]: Add Graph Store component (#23092) 2024-07-05 12:24:10 -04:00
test_imports.py core[patch]: Speed up unit tests for imports (#23837) 2024-07-03 15:55:15 -04:00
test_messages.py core[patch]: fix ToolCall "type" when streaming (#24218) 2024-07-13 08:59:03 -07:00
test_outputs.py REFACTOR: Refactor langchain_core (#13627) 2023-11-21 08:35:29 -08:00
test_sys_info.py core(minor): Add a way to print out system information for debugging purposes. (#15718) 2024-01-08 12:20:18 -08:00
test_tools.py core[minor]: Relax constraints on type checking for tools and parsers (#24459) 2024-07-19 21:47:34 -04:00