HFAgentsCourse / tools /reverse_words.py
Alessio-Chiovelli's picture
typo value error reverse words tool
f8fd7f1
raw
history blame contribute delete
466 Bytes
from langchain_core.tools import tool
@tool
def reverse_words(text: str) -> str:
"""
Reverses the input word. For example, "hello" becomes "olleh".
This tool might be useful in enigmas or puzzles where the input query seems illogical and unreadable.
To use this tool, you need to provide a word with at least a character, otherwise it will raise an error.
"""
if not text:raise ValueError("Cannot reverse empty words.")
return text[::-1]