Spaces:
Sleeping
Sleeping
File size: 1,318 Bytes
1e165d6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import datetime
import os
from typing import Any, Dict, Union
from smolagents.tools import Tool
class MarkdownWriterTool(Tool):
name = "markdown_writer"
description = """Writes the given text content, which should be a summary in Markdown format, to a Markdown file with a timestamped filename.
The assistant should provide a summary as text in Markdown format.
Args:
markdown_content: The text content in Markdown format to be written to the file.
"""
inputs = {"markdown_content": {"type": "string", "description": "The Markdown content to write to the file."}}
output_type = "string"
def forward(self, markdown_content: str) -> str:
"""Writes the given Markdown content to a file with a timestamped name."""
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"summary_{timestamp}.md"
filepath = os.path.join(os.getcwd(), filename) # Save in the current working directory
try:
with open(filepath, "w", encoding="utf-8") as f:
f.write(markdown_content)
return f"Successfully wrote content to {filepath}"
except Exception as e:
return f"Error writing to file: {str(e)}"
def __init__(self, *args, **kwargs):
self.is_initialized = False
|