mirror of
https://github.com/langchain-ai/agents-from-scratch-ts.git
synced 2026-07-01 21:34:00 -04:00
28 lines
842 B
Python
28 lines
842 B
Python
"""Define the configurable parameters for the agent."""
|
|
|
|
import os
|
|
from dataclasses import dataclass, fields
|
|
from typing import Any, Optional
|
|
|
|
from langchain_core.runnables import RunnableConfig
|
|
|
|
@dataclass(kw_only=True)
|
|
class Configuration:
|
|
"""Main configuration class."""
|
|
# llm =
|
|
|
|
@classmethod
|
|
def from_runnable_config(
|
|
cls, config: Optional[RunnableConfig] = None
|
|
) -> "Configuration":
|
|
"""Create a Configuration instance from a RunnableConfig."""
|
|
configurable = (
|
|
config["configurable"] if config and "configurable" in config else {}
|
|
)
|
|
values: dict[str, Any] = {
|
|
f.name: os.environ.get(f.name.upper(), configurable.get(f.name))
|
|
for f in fields(cls)
|
|
if f.init
|
|
}
|
|
|
|
return cls(**{k: v for k, v in values.items() if v}) |