from smolagents.tools import Tool from huggingface_hub import InferenceClient class TranslateTool(Tool): name = "translate" description = "Translate text from Chinese to English" inputs = {"text": {"type": "string", "description": "The text to translate"}} output_type = "string" model_id = "Helsinki-NLP/opus-mt-zh-en" client = InferenceClient(model_id) def forward(self, text: str) -> str: response = self.client.text_generation( f"Translate from Chinese to English: {text}", max_new_tokens=100 ) return response def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)