Add Environment Info to Run (#4691)

Store the environment info within the `extra` fields of the Run
dynamic_agent_tools
Zander Chase 1 year ago committed by GitHub
parent d3300bd799
commit 97434a64c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@ from uuid import UUID
from pydantic import BaseModel, Field, root_validator
from langchain.env import get_runtime_environment
from langchain.schema import LLMResult
@ -136,6 +137,14 @@ class RunCreate(RunBase):
name: str
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()
ToolRun.update_forward_refs()

@ -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…
Cancel
Save