Smartfunc: Turn Docstrings into LLM-Functions
Published on: 2025-04-30 21:43:11
smartfunc
Turn docstrings into LLM-functions
If you're keen for a demo, you may appreciate this YouTube video:
Installation
uv pip install smartfunc
What is this?
Here is a nice example of what is possible with this library:
from smartfunc import backend @ backend ( "gpt-4" ) def generate_summary ( text : str ): """Generate a summary of the following text: {{ text }}""" pass
The generate_summary function will now return a string with the summary of the text that you give it.
How does it work?
This library wraps around the llm library made by Simon Willison. The docstring is parsed and turned into a Jinja2 template which we inject with variables to generate a prompt at runtime. We then use the backend given by the decorator to run the prompt and return the result.
The llm library is minimalistic and while it does not support all the features out there it does offer a solid foundation to build on. This library is mainly meant as a method to add some syntactic sugar on top. We
... Read full article.