langchain/libs/core/tests/unit_tests
Ant White e3ea365725
core: use friendlier names for duplicated nodes in mermaid output (#27747)
Thank you for contributing to LangChain!

- [x] **PR title**: "core: use friendlier names for duplicated nodes in
mermaid output"

- **Description:** When generating the Mermaid visualization of a chain,
if the chain had multiple nodes of the same type, the reid function
would replace their names with the UUID node_id. This made the generated
graph difficult to understand. This change deduplicates the nodes in a
chain by appending an index to their names.
- **Issue:** None
- **Discussion:**
https://github.com/langchain-ai/langchain/discussions/27714
- **Dependencies:** None

- [ ] **Add tests and docs**:  
- Currently this functionality is not covered by unit tests, happy to
add tests if you'd like


- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

# Example Code:
```python
from langchain_core.runnables import RunnablePassthrough

def fake_llm(prompt: str) -> str: # Fake LLM for the example
    return "completion"

runnable = {
    'llm1':  fake_llm,
    'llm2':  fake_llm,
} | RunnablePassthrough.assign(
    total_chars=lambda inputs: len(inputs['llm1'] + inputs['llm2'])
)

print(runnable.get_graph().draw_mermaid(with_styles=False))
```

# Before
```mermaid
graph TD;
	Parallel_llm1_llm2_Input --> 0b01139db5ed4587ad37964e3a40c0ec;
	0b01139db5ed4587ad37964e3a40c0ec --> Parallel_llm1_llm2_Output;
	Parallel_llm1_llm2_Input --> a98d4b56bd294156a651230b9293347f;
	a98d4b56bd294156a651230b9293347f --> Parallel_llm1_llm2_Output;
	Parallel_total_chars_Input --> Lambda;
	Lambda --> Parallel_total_chars_Output;
	Parallel_total_chars_Input --> Passthrough;
	Passthrough --> Parallel_total_chars_Output;
	Parallel_llm1_llm2_Output --> Parallel_total_chars_Input;
```

# After
```mermaid
graph TD;
	Parallel_llm1_llm2_Input --> fake_llm_1;
	fake_llm_1 --> Parallel_llm1_llm2_Output;
	Parallel_llm1_llm2_Input --> fake_llm_2;
	fake_llm_2 --> Parallel_llm1_llm2_Output;
	Parallel_total_chars_Input --> Lambda;
	Lambda --> Parallel_total_chars_Output;
	Parallel_total_chars_Input --> Passthrough;
	Passthrough --> Parallel_total_chars_Output;
	Parallel_llm1_llm2_Output --> Parallel_total_chars_Input;
```
2024-10-31 16:52:00 -04:00
..
_api multiple: rely on asyncio_mode auto in tests (#27200) 2024-10-15 16:26:38 +00:00
caches core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
callbacks core[patch]: Update AsyncCallbackManager to honor run_inline attribute and prevent context loss (#26885) 2024-10-07 14:59:29 -04:00
chat_history core: Add various ruff rules (#26836) 2024-10-07 22:30:27 +00: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 core: Add ruff rules for comprehensions (C4) (#26829) 2024-09-25 09:34:17 -04:00
documents multiple: pydantic 2 compatibility, v0.3 (#26443) 2024-09-13 14:38:45 -07:00
embeddings core[minor]: moved fake llms and embeddings to core (#19226) 2024-03-18 10:01:26 -07:00
example_selectors core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
examples core:adds tests for partial_variables (#15427) 2024-01-02 15:00:06 -08:00
fake core: fix batch race condition in FakeListChatModel (#26924) 2024-10-03 23:14:31 +00:00
indexing core[minor]: add **kwargs to index and aindex functions for custom vector_field support (#26998) 2024-10-07 14:52:50 -04:00
language_models core: Add various ruff rules (#26836) 2024-10-07 22:30:27 +00:00
load core[patch]: fix repr and str for Serializable (#26786) 2024-10-24 08:36:35 -07:00
messages Support message trimming on single messages (#27729) 2024-10-30 04:27:52 +00:00
output_parsers core: JsonOutputParser UTF characters bug (#27306) 2024-10-29 14:48:53 +00:00
outputs core[patch]: fix ChatGeneration.text with content blocks (#20294) 2024-04-10 15:54:06 -07:00
prompts core[patch]: rm image loading (#27797) 2024-10-31 10:34:51 -07:00
rate_limiters core[minor]: Add BaseModel.rate_limiter, RateLimiter abstraction and in-memory implementation (#24669) 2024-07-26 03:03:34 +00:00
runnables core: use friendlier names for duplicated nodes in mermaid output (#27747) 2024-10-31 16:52:00 -04:00
stores core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
tracers core[patch]: Add ruff rules for flake8-simplify (SIM) (#26848) 2024-09-27 20:13:23 +00:00
utils core[patch]: support bedrock converse -> openai tool (#27754) 2024-10-30 12:20:39 -07:00
vectorstores core: Add various ruff rules (#26836) 2024-10-07 22:30:27 +00:00
__init__.py Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00
conftest.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
prompt_file.txt Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00
pydantic_utils.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
stubs.py core: Add various ruff rules (#26836) 2024-10-07 22:30:27 +00:00
test_globals.py Separate out langchain_core package (#13577) 2023-11-20 13:09:30 -08:00
test_imports.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
test_messages.py core: Add various ruff rules (#26836) 2024-10-07 22:30:27 +00:00
test_outputs.py REFACTOR: Refactor langchain_core (#13627) 2023-11-21 08:35:29 -08:00
test_prompt_values.py multiple: pydantic 2 compatibility, v0.3 (#26443) 2024-09-13 14:38:45 -07:00
test_pydantic_serde.py core: Add N(naming) ruff rules (#25362) 2024-09-19 05:09:39 +00: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[patch]: make get_all_basemodel_annotations public (#27761) 2024-10-30 14:43:29 -07:00