File size: 4,521 Bytes
ec8f374
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
Custom domain template for user-defined domains.
"""
from typing import List
from .base_domain import BaseDomain


class CustomDomain(BaseDomain):
    """
    Custom domain template that allows users to define
    their own domain specifications.
    """

    def __init__(
        self,
        name: str = "Custom Domain",
        description: str = "User-defined custom domain",
        icon: str = "🎯",
        topics: List[str] = None,
        system_prompt: str = None
    ):
        super().__init__()
        self._name = name
        self._description = description
        self._icon = icon
        self._topics = topics or []
        self._system_prompt = system_prompt or self._default_system_prompt()

    def _default_system_prompt(self) -> str:
        """Generate default system prompt for custom domain"""
        return f"""You are an expert assistant specialized in {self._name}.

Your role is to:
1. Provide accurate, helpful information in your domain of expertise
2. Explain concepts clearly and thoroughly
3. Adapt your responses to the user's level of understanding
4. Acknowledge the limits of your knowledge
5. Recommend seeking professional advice when appropriate

Guidelines:
- Be thorough but concise
- Use examples to illustrate concepts
- Break down complex topics into understandable parts
- Stay focused on your area of expertise
- Always prioritize accuracy and helpfulness"""

    def get_topics(self) -> List[str]:
        """Get custom domain topics"""
        if not self._topics:
            return [
                "General Knowledge",
                "Problem Solving",
                "Analysis",
                "Research",
                "Communication"
            ]
        return self._topics

    def get_system_prompt(self) -> str:
        """Get custom domain system prompt"""
        return self._system_prompt

    def set_topics(self, topics: List[str]) -> None:
        """
        Set custom topics for this domain.

        Args:
            topics: List of topic strings
        """
        self._topics = topics

    def set_system_prompt(self, prompt: str) -> None:
        """
        Set custom system prompt for this domain.

        Args:
            prompt: System prompt string
        """
        self._system_prompt = prompt

    def set_name(self, name: str) -> None:
        """
        Set custom domain name.

        Args:
            name: Domain name
        """
        self._name = name

    def set_description(self, description: str) -> None:
        """
        Set custom domain description.

        Args:
            description: Domain description
        """
        self._description = description

    def set_icon(self, icon: str) -> None:
        """
        Set custom domain icon.

        Args:
            icon: Icon (emoji) string
        """
        self._icon = icon

    def get_example_questions(self) -> List[str]:
        """Get example questions for custom domain"""
        return [
            f"What are the key concepts in {self._name}?",
            f"Can you explain [topic] in {self._name}?",
            f"What are best practices for {self._name}?",
            f"How do I get started with {self._name}?",
            f"What are common challenges in {self._name}?"
        ]

    def get_specialized_tools(self) -> List[dict]:
        """Get specialized tools for custom domain"""
        # Custom domains can define their own tools
        # Default: empty list
        return []

    @classmethod
    def from_config(cls, config: dict) -> 'CustomDomain':
        """
        Create CustomDomain from configuration dictionary.

        Args:
            config: Dictionary with keys: name, description, icon, topics, system_prompt

        Returns:
            CustomDomain instance
        """
        return cls(
            name=config.get('name', 'Custom Domain'),
            description=config.get('description', 'User-defined custom domain'),
            icon=config.get('icon', '🎯'),
            topics=config.get('topics', []),
            system_prompt=config.get('system_prompt')
        )

    def to_config(self) -> dict:
        """
        Export domain configuration as dictionary.

        Returns:
            Dictionary with domain configuration
        """
        return {
            'name': self._name,
            'description': self._description,
            'icon': self._icon,
            'topics': self._topics,
            'system_prompt': self._system_prompt
        }