Skip to content

Refactor template ID usage to utilize constants for improved maintain… #584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions assistants/project-assistant/assistant/chat.py
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
from assistant.command_processor import command_registry
from assistant.respond import respond_to_conversation
from assistant.team_welcome import generate_team_welcome_message
from assistant.utils import load_text_include
from assistant.utils import CONTEXT_TRANSFER_TEMPLATE_ID, DEFAULT_TEMPLATE_ID, load_text_include

from .config import assistant_config
from .conversation_project_link import ConversationProjectManager
@@ -71,7 +71,7 @@ async def content_evaluator_factory(
},
additional_templates=[
AssistantTemplate(
id="knowledge_transfer",
id=CONTEXT_TRANSFER_TEMPLATE_ID,
name="Knowledge Transfer Assistant",
description="An assistant for capturing and sharing complex information for others to explore.",
),
@@ -80,7 +80,7 @@ async def content_evaluator_factory(
**dashboard_card.metadata(
dashboard_card.TemplateConfig(
enabled=False,
template_id="default",
template_id=DEFAULT_TEMPLATE_ID,
background_color="rgb(159, 216, 159)",
icon=dashboard_card.image_to_url(
pathlib.Path(__file__).parent / "assets" / "icon.svg", "image/svg+xml"
@@ -92,7 +92,7 @@ async def content_evaluator_factory(
),
dashboard_card.TemplateConfig(
enabled=True,
template_id="knowledge_transfer",
template_id=CONTEXT_TRANSFER_TEMPLATE_ID,
icon=dashboard_card.image_to_url(
pathlib.Path(__file__).parent / "assets" / "icon_context_transfer.svg", "image/svg+xml"
),
5 changes: 3 additions & 2 deletions assistants/project-assistant/assistant/project_common.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@

from .conversation_project_link import ConversationProjectManager
from .logging import logger
from .utils import DEFAULT_TEMPLATE_ID
from .project_data import LogEntryType
from .project_storage import ProjectStorage
from .project_storage_models import ConversationRole
@@ -28,10 +29,10 @@ class ConfigurationTemplate(Enum):


def get_template(context: ConversationContext) -> ConfigurationTemplate:
template_id = context.assistant._template_id or "default"
template_id = context.assistant._template_id or DEFAULT_TEMPLATE_ID
return (
ConfigurationTemplate.PROJECT_ASSISTANT
if template_id == "default"
if template_id == DEFAULT_TEMPLATE_ID
else ConfigurationTemplate.CONTEXT_TRANSFER_ASSISTANT
)

6 changes: 3 additions & 3 deletions assistants/project-assistant/assistant/tools.py
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
from .project_notifications import ProjectNotifier
from .project_storage import ProjectStorage, ProjectStorageManager
from .project_storage_models import ConversationRole
from .utils import is_context_transfer_assistant
from .utils import DEFAULT_TEMPLATE_ID, is_context_transfer_assistant


async def invoke_command_handler(
@@ -97,10 +97,10 @@ def __init__(self, context: ConversationContext, role: ConversationRole):
self.tool_functions = ToolFunctions()
self.is_context_transfer = is_context_transfer_assistant(context)

template_id = context.assistant._template_id or "default"
template_id = context.assistant._template_id or DEFAULT_TEMPLATE_ID
self.config_template = (
ConfigurationTemplate.PROJECT_ASSISTANT
if template_id == "default"
if template_id == DEFAULT_TEMPLATE_ID
else ConfigurationTemplate.CONTEXT_TRANSFER_ASSISTANT
)

1 change: 1 addition & 0 deletions assistants/project-assistant/assistant/utils.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
from .logging import logger

CONTEXT_TRANSFER_TEMPLATE_ID = "knowledge_transfer"
DEFAULT_TEMPLATE_ID = "default"


def is_context_transfer_assistant(context: ConversationContext) -> bool:
3 changes: 2 additions & 1 deletion assistants/project-assistant/tests/test_project_tools.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,8 @@ def context(self):
# Add the assistant attribute for the get_project_tools test
context.assistant = MagicMock()
# Use the correct property name (_template_id)
context.assistant._template_id = "default"
from assistant.utils import DEFAULT_TEMPLATE_ID
context.assistant._template_id = DEFAULT_TEMPLATE_ID
return context

def test_initialization(self, context):