mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-07 05:30:39 +00:00
Add Environment Info to Run (#4691)
Store the environment info within the `extra` fields of the Run
This commit is contained in:
parent
d3300bd799
commit
97434a64c5
@ -8,6 +8,7 @@ from uuid import UUID
|
|||||||
|
|
||||||
from pydantic import BaseModel, Field, root_validator
|
from pydantic import BaseModel, Field, root_validator
|
||||||
|
|
||||||
|
from langchain.env import get_runtime_environment
|
||||||
from langchain.schema import LLMResult
|
from langchain.schema import LLMResult
|
||||||
|
|
||||||
|
|
||||||
@ -136,6 +137,14 @@ class RunCreate(RunBase):
|
|||||||
name: str
|
name: str
|
||||||
session_id: UUID
|
session_id: UUID
|
||||||
|
|
||||||
|
@root_validator(pre=True)
|
||||||
|
def add_runtime_env(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
"""Add env info to the run."""
|
||||||
|
extra = values.get("extra", {})
|
||||||
|
extra["runtime"] = get_runtime_environment()
|
||||||
|
values["extra"] = extra
|
||||||
|
return values
|
||||||
|
|
||||||
|
|
||||||
ChainRun.update_forward_refs()
|
ChainRun.update_forward_refs()
|
||||||
ToolRun.update_forward_refs()
|
ToolRun.update_forward_refs()
|
||||||
|
16
langchain/env.py
Normal file
16
langchain/env.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import platform
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=1)
|
||||||
|
def get_runtime_environment() -> dict:
|
||||||
|
"""Get information about the environment."""
|
||||||
|
# Lazy import to avoid circular imports
|
||||||
|
from langchain import __version__
|
||||||
|
|
||||||
|
return {
|
||||||
|
"library_version": __version__,
|
||||||
|
"platform": platform.platform(),
|
||||||
|
"runtime": "python",
|
||||||
|
"runtime_version": platform.python_version(),
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user