-
Notifications
You must be signed in to change notification settings - Fork 33
/
configuration.py
44 lines (37 loc) · 1.53 KB
/
configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
from dataclasses import dataclass, field, fields
from typing import Any, Optional
from langchain_core.runnables import RunnableConfig
from typing_extensions import Annotated
from dataclasses import dataclass
DEFAULT_REPORT_STRUCTURE = """The report structure should focus on breaking-down the user-provided topic:
1. Introduction (no research needed)
- Brief overview of the topic area
2. Main Body Sections:
- Each section should focus on a sub-topic of the user-provided topic
- Include any key concepts and definitions
- Provide real-world examples or case studies where applicable
3. Conclusion
- Aim for 1 structural element (either a list of table) that distills the main body sections
- Provide a concise summary of the report"""
@dataclass(kw_only=True)
class Configuration:
"""The configurable fields for the chatbot."""
report_structure: str = DEFAULT_REPORT_STRUCTURE
number_of_queries: int = 2
tavily_topic: str = "general"
tavily_days: str = None
@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})