dmfelder commited on
Commit
c14a3f4
·
verified ·
1 Parent(s): 71f9fba

Create sort_words_alphabetically.py

Browse files
Files changed (1) hide show
  1. tools/sort_words_alphabetically.py +25 -0
tools/sort_words_alphabetically.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+
3
+ from langchain_core.tools import tool
4
+ from loguru import logger
5
+
6
+
7
+ @tool("sort_words_alphabetically_tool", parse_docstring=True)
8
+ def sort_words_alphabetically(words: List[str]) -> str:
9
+ """Sort a list of words alphabetically and join them with commas.
10
+ Args:
11
+ words (List[str]): List of strings to be sorted
12
+ Returns:
13
+ str: A string containing all sorted words joined with commas
14
+ """
15
+ logger.info(f"use sort_words_alphabetically with param: {words}")
16
+ sorted_words = sorted(words)
17
+
18
+ result = ", ".join(sorted_words)
19
+
20
+ return result
21
+
22
+
23
+ if __name__ == "__main__":
24
+ print(sort_words_alphabetically.invoke({"words": ["broccoli", "celery", "sweet potatoes", "lettuce"]}))
25
+