from typing import Dict, List, Any from smolagents.tools import Tool class HealthcareLLMVisualizerTool(Tool): name = "healthcare_llm_visualizer" description = "Creates interactive visualizations for analyzing LLM applications in Healthcare" inputs = { 'data': { 'type': 'object', # Using 'object' for dictionary input 'description': 'Data for visualization in format: {"items": [{"category": "name", "value": number}]}' } } output_type = "string" # Changed from 'str' to 'string' def prepare_data(self, raw_data: Dict) -> Dict[str, List[Dict[str, Any]]]: """Convert raw data into format suitable for visualization""" categories = {} # Process trends for item in raw_data.get('trends', []): category = item['category'] categories[category] = categories.get(category, 0) + 1 # Process implementations for item in raw_data.get('implementations', []): category = item['category'] categories[category] = categories.get(category, 0) + 1 # Process success cases for item in raw_data.get('success_cases', []): category = item['category'] categories[category] = categories.get(category, 0) + 1 # Convert to required format return { "items": [ {"category": cat, "value": val} for cat, val in categories.items() ] } def forward(self, data: Dict) -> str: """Creates a visualization from the provided data""" try: # Prepare data for visualization viz_data = self.prepare_data(data) # Create React component chart_code = """ import React from 'react'; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'; const HealthcareLLMChart = () => { const data = DATA_PLACEHOLDER; return (

LLM Applications in Healthcare

); }; export default HealthcareLLMChart; """.replace('DATA_PLACEHOLDER', str(viz_data)) return chart_code except Exception as e: return f"Error creating visualization: {str(e)}"