LaunchLLM / domain_templates /custom_domain.py
Bmccloud22's picture
Deploy LaunchLLM - Production AI Training Platform
ec8f374 verified
"""
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
}