Skip to content

Commit dc42260

Browse files
authored
Merge pull request #757 from AnswerDotAI/llmtool-docs
Add template support to llmtool decorator
2 parents 5bbb17f + cb090a8 commit dc42260

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

fastcore/imports.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ def is_usable_tool(func:callable):
108108

109109
__llmtools__ = set()
110110

111-
def llmtool(f):
112-
assert is_usable_tool(f), f"Function {f.__name__} is not usable as a tool"
113-
__llmtools__.add(f.__name__)
114-
f.__llmtool__ = True
115-
return f
111+
def llmtool(f=None, **tmpls):
112+
"Decorator to mark a function as an LLM tool. Pass `**tmpls` to format the docstring."
113+
def decorator(fn):
114+
assert is_usable_tool(fn), f"Function {fn.__name__} is not usable as a tool"
115+
if fn.__doc__ and tmpls: fn.__doc__ = fn.__doc__.format(**tmpls)
116+
__llmtools__.add(fn.__name__)
117+
fn.__llmtool__ = True
118+
return fn
119+
if f: return decorator(f)
120+
return decorator
116121

0 commit comments

Comments
 (0)