langchain/libs/core/tests/unit_tests
Eugene Yurtsev 5c2cfabec6
core[minor]: Add v2 implementation of astream events (#21638)
This PR introduces a v2 implementation of astream events that removes
intermediate abstractions and fixes some issues with v1 implementation.

The v2 implementation significantly reduces relevant code that's
associated with the astream events implementation together with
overhead.

After this PR, the astream events implementation:

- Uses an async callback handler
- No longer relies on BaseTracer
- No longer relies on json patch

As a result of this re-write, a number of issues were discovered with
the existing implementation.

## Changes in V2 vs. V1

### on_chat_model_end `output`

The outputs associated with `on_chat_model_end` changed depending on
whether it was within a chain or not.

As a root level runnable the output was: 

```python
"data": {"output": AIMessageChunk(content="hello world!", id='some id')}
```

As part of a chain the output was:

```
            "data": {
                "output": {
                    "generations": [
                        [
                            {
                                "generation_info": None,
                                "message": AIMessageChunk(
                                    content="hello world!", id=AnyStr()
                                ),
                                "text": "hello world!",
                                "type": "ChatGenerationChunk",
                            }
                        ]
                    ],
                    "llm_output": None,
                }
            },
```

After this PR, we will always use the simpler representation:

```python
"data": {"output": AIMessageChunk(content="hello world!", id='some id')}
```

**NOTE** Non chat models (i.e., regular LLMs) are still associated with
the more verbose format.

### Remove some `_stream` events

`on_retriever_stream` and `on_tool_stream` events were removed -- these
were not real events, but created as an artifact of implementing on top
of astream_log.

The same information is already available in the `x_on_end` events.

### Propagating Names

Names of runnables have been updated to be more consistent

```python
  model = GenericFakeChatModel(messages=infinite_cycle).configurable_fields(
        messages=ConfigurableField(
            id="messages",
            name="Messages",
            description="Messages return by the LLM",
        )
    )
```

Before:
```python
"name": "RunnableConfigurableFields",
```

After:
```python
"name": "GenericFakeChatModel",
```

### on_retriever_end

on_retriever_end will always return `output` which is a list of
documents (rather than a dict containing a key called "documents")

### Retry events

Removed the `on_retry` callback handler. It was incorrectly showing that
the failed function being retried has invoked `on_chain_end`


https://github.com/langchain-ai/langchain/pull/21638/files#diff-e512e3f84daf23029ebcceb11460f1c82056314653673e450a5831147d8cb84dL1394
2024-05-15 11:48:47 -04:00
..
_api core: use qualname in beta message (#20361) 2024-04-23 11:20:13 -07:00
callbacks community, core[callbacks]: move FileCallbackHandler from community to core (#20495) 2024-04-17 22:29:30 -04:00
chat_history core[patch],community[patch]: Move file chat history back to community (#20834) 2024-04-24 12:47:25 -04:00
data
dependencies community[minor]: Add glue catalog loader (#20220) 2024-04-16 11:39:23 -04:00
document_loaders core[minor]: Add aload to document loader (#19936) 2024-04-03 10:46:47 -04:00
documents core[minor]: move document compressor base (#17910) 2024-02-26 17:20:50 -08:00
embeddings core[minor]: moved fake llms and embeddings to core (#19226) 2024-03-18 10:01:26 -07:00
example_selectors core[minor]: Add async methods to MaxMarginalRelevanceExampleSelector (#19639) 2024-03-27 16:03:18 -04:00
examples core:adds tests for partial_variables (#15427) 2024-01-02 15:00:06 -08:00
fake core: Assign missing message ids in BaseChatModel (#19863) 2024-04-02 01:18:36 +00:00
indexing core[minor],langchain[patch]: Move base indexing interface and logic to core (#20667) 2024-04-24 13:18:42 -04:00
language_models community[patch]: update use of deprecated llm methods (#20393) 2024-04-12 17:28:23 -04:00
load BUG: more core fixes (#13665) 2023-11-21 15:15:48 -08:00
messages fix: core: Include in json output also fields set outside the constructor (#21342) 2024-05-06 14:37:36 -07:00
output_parsers core[patch]: improve comma separated list output parser to handle non-space separated list (#20434) 2024-04-25 20:10:56 +00:00
outputs core[patch]: fix ChatGeneration.text with content blocks (#20294) 2024-04-10 15:54:06 -07:00
prompts core: mustache prompt templates (#19980) 2024-04-10 11:25:32 -07:00
runnables core[minor]: Add v2 implementation of astream events (#21638) 2024-05-15 11:48:47 -04:00
stores core[minor],langchain[patch],community[patch]: Move storage interfaces to core (#20750) 2024-04-30 13:14:26 -04:00
tracers core: tracer: remove numeric execution order (#21220) 2024-05-02 15:38:55 -07:00
utils core[patch]: utils.guard_import fix (#21133) 2024-05-03 17:21:36 -04:00
__init__.py
conftest.py fix: core: Include in json output also fields set outside the constructor (#21342) 2024-05-06 14:37:36 -07:00
prompt_file.txt
stubs.py core: Assign missing message ids in BaseChatModel (#19863) 2024-04-02 01:18:36 +00:00
test_globals.py
test_imports.py infra: Fix test filesystem paths incompatible with windows (#14388) 2023-12-21 13:45:42 -08:00
test_messages.py core[patch]: Fixes for convert_messages (#21207) 2024-05-02 16:55:42 +00:00
test_outputs.py
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 [Patch] Dedent docstring (#20959) 2024-04-30 07:40:57 -07:00