mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-21 06:33:41 +00:00
refactor: move ID prefixes
This commit is contained in:
@@ -26,18 +26,6 @@ from langchain_core.utils.usage import _dict_int_op
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_LC_AUTO_PREFIX = "lc_"
|
||||
"""LangChain auto-generated ID prefix for messages and content blocks."""
|
||||
|
||||
_LC_ID_PREFIX = f"{_LC_AUTO_PREFIX}run-"
|
||||
"""Internal tracing/callback system identifier.
|
||||
|
||||
Used for:
|
||||
- Tracing. Every LangChain operation (LLM call, chain execution, tool use, etc.)
|
||||
gets a unique run_id (UUID)
|
||||
- Enables tracking parent-child relationships between operations
|
||||
"""
|
||||
|
||||
|
||||
class InputTokenDetails(TypedDict, total=False):
|
||||
"""Breakdown of input token counts.
|
||||
@@ -523,15 +511,15 @@ def add_ai_message_chunks(
|
||||
for id_ in candidates:
|
||||
if (
|
||||
id_
|
||||
and not id_.startswith(_LC_ID_PREFIX)
|
||||
and not id_.startswith(_LC_AUTO_PREFIX)
|
||||
and not id_.startswith(types.LC_ID_PREFIX)
|
||||
and not id_.startswith(types.LC_AUTO_PREFIX)
|
||||
):
|
||||
chunk_id = id_
|
||||
break
|
||||
else:
|
||||
# second pass: prefer lc_run-* ids over lc_* ids
|
||||
for id_ in candidates:
|
||||
if id_ and id_.startswith(_LC_ID_PREFIX):
|
||||
if id_ and id_.startswith(types.LC_ID_PREFIX):
|
||||
chunk_id = id_
|
||||
break
|
||||
else:
|
||||
|
||||
@@ -135,6 +135,18 @@ from uuid import uuid4
|
||||
|
||||
from typing_extensions import NotRequired, TypedDict, TypeGuard
|
||||
|
||||
LC_AUTO_PREFIX = "lc_"
|
||||
"""LangChain auto-generated ID prefix for messages and content blocks."""
|
||||
|
||||
LC_ID_PREFIX = f"{LC_AUTO_PREFIX}run-"
|
||||
"""Internal tracing/callback system identifier.
|
||||
|
||||
Used for:
|
||||
- Tracing. Every LangChain operation (LLM call, chain execution, tool use, etc.)
|
||||
gets a unique run_id (UUID)
|
||||
- Enables tracking parent-child relationships between operations
|
||||
"""
|
||||
|
||||
|
||||
def _ensure_id(id_val: Optional[str]) -> str:
|
||||
"""Ensure the ID is a valid string, generating a new UUID if not provided.
|
||||
@@ -148,7 +160,7 @@ def _ensure_id(id_val: Optional[str]) -> str:
|
||||
Returns:
|
||||
A string ID, either the validated provided value or a newly generated UUID4.
|
||||
"""
|
||||
return id_val or str(f"lc_{uuid4()}")
|
||||
return id_val or str(f"{LC_AUTO_PREFIX}{uuid4()}")
|
||||
|
||||
|
||||
class Citation(TypedDict):
|
||||
|
||||
Reference in New Issue
Block a user