repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from typing import Any, Optional |
| #2 | |
| #3 | |
| #4 | def merge_metadata_dict(left: Optional[dict[str, Any]], right: Optional[dict[str, Any]]) -> Optional[dict[str, Any]]: |
| #5 | """ |
| #6 | Merge the metadatas of two BaseMessage types. |
| #7 | |
| #8 | Args: |
| #9 | left (dict[str, Any]): metadata of human message |
| #10 | right (dict[str, Any]): metadata of AI message |
| #11 | |
| #12 | Returns: |
| #13 | dict[str, Any]: combined metadata dict with dedup |
| #14 | to be saved in db. |
| #15 | """ |
| #16 | if not left and not right: |
| #17 | return None |
| #18 | elif not left: |
| #19 | return right |
| #20 | elif not right: |
| #21 | return left |
| #22 | |
| #23 | merged = left.copy() |
| #24 | for k, v in right.items(): |
| #25 | if k not in merged: |
| #26 | merged[k] = v |
| #27 | elif type(merged[k]) is not type(v): |
| #28 | raise ValueError(f'additional_kwargs["{k}"] already exists in this message,' " but with a different type.") |
| #29 | elif isinstance(merged[k], str): |
| #30 | merged[k] += v |
| #31 | elif isinstance(merged[k], dict): |
| #32 | merged[k] = merge_metadata_dict(merged[k], v) |
| #33 | else: |
| #34 | raise ValueError(f"Additional kwargs key {k} already exists in this message.") |
| #35 | return merged |
| #36 |