Skip to content

Allows navigator to display any assistant card #578

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
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from assistant_extensions import navigator
from assistant_extensions import dashboard_card, navigator
from pydantic import BaseModel
from semantic_workbench_assistant.assistant_app import ConversationContext

Expand Down Expand Up @@ -37,6 +37,7 @@ async def get_assistant_services(context: ConversationContext) -> str:
f"{metadata_for_navigator.get(template.id, '')}\n\n"
for service, metadata_for_navigator in navigator_visible_services
for template in service.templates
if dashboard_card.extract_metadata_for_dashboard_card(service.metadata, template.id)
])


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from ._dashboard_card import image_to_url, metadata, TemplateConfig, CardContent
from ._dashboard_card import image_to_url, metadata, TemplateConfig, CardContent, extract_metadata_for_dashboard_card

__all__ = ["metadata", "image_to_url", "TemplateConfig", "CardContent"]
__all__ = ["metadata", "image_to_url", "TemplateConfig", "CardContent", "extract_metadata_for_dashboard_card"]
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,17 @@ def metadata(*templates: TemplateConfig) -> dict[str, Any]:
return {
dashboard_card_metadata_key: template_dict,
}


def extract_metadata_for_dashboard_card(metadata: dict[str, Any], template_id: str) -> TemplateConfig | None:
"""
Extracts the metadata for a specific template ID from the assistant service metadata.
Args:
metadata (dict[str, Any]): The assistant service metadata.
template_id (str): The template ID to extract the metadata for.
Returns:
TemplateConfig | None: The metadata for the specified template ID, or None if not found.
"""
if dashboard_card_metadata_key not in metadata:
return None
return metadata[dashboard_card_metadata_key].get(template_id)
13 changes: 11 additions & 2 deletions workbench-app/src/components/FrontDoor/Controls/AssistantCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ interface AssistantCardProps {
newConversationMetadata?: { [key: string]: any };
hideContent?: boolean;
includeAssistantIds?: string[];
requireEnabled?: boolean;
}

export const AssistantCard: React.FC<AssistantCardProps> = (props) => {
const { assistantServiceId, templateId, hideContent, newConversationMetadata, includeAssistantIds } = props;
const {
assistantServiceId,
templateId,
hideContent,
newConversationMetadata,
includeAssistantIds,
requireEnabled,
} = props;
const { isFetching: createConversationIsFetching, assistants } = useCreateConversation();
const {
data: assistantServices,
Expand Down Expand Up @@ -193,7 +201,7 @@ export const AssistantCard: React.FC<AssistantCardProps> = (props) => {
service.metadata._dashboard_card &&
service.assistantServiceId === assistantServiceId &&
service.metadata._dashboard_card[templateId] &&
service.metadata._dashboard_card[templateId].enabled,
(!requireEnabled || service.metadata._dashboard_card[templateId].enabled),
);

if (!service) {
Expand All @@ -219,6 +227,7 @@ export const AssistantCard: React.FC<AssistantCardProps> = (props) => {
assistantInstances,
templateId,
assistantServiceId,
requireEnabled,
]);

if (!dashboardCard) {
Expand Down
1 change: 1 addition & 0 deletions workbench-app/src/components/FrontDoor/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export const MainContent: React.FC<MainContentProps> = (props) => {
key={ids.assistantServiceId + '/' + ids.templateId}
assistantServiceId={ids.assistantServiceId}
templateId={ids.templateId}
requireEnabled={true}
/>
))}
</div>
Expand Down