smartfunc: Turn Docstrings into LLM-Functions

https://news.ycombinator.com/rss Hits: 10
Summary

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 do get a few nice benefits from the llm library though: The llm library is well maintained and has a large community library is well maintained and has a large community An ecosystem of backends for different LLM providers Many of the vendors have async support, which allows us to do microbatching support, which allows us to do microbatching Many of the vendors have schema support, which allows us to use Pydantic models to define the response You can use .env files to store your API keys Extra features Schemas The following snippet shows how you might create a re-useable backend decorator that uses a system prompt. Also notice how we're able to use a Pydantic model to define the response. from smartfunc import backend from pydantic import BaseModel from dotenv import load_dotenv load_dotenv ( ".env" ) class Summary ( BaseModel ): summary : str pros : list [ str ] cons : list [ str ] llmify = backend ( "gpt-4o-mini" , system = "You are a helpful assistant." , temperature = 0.5 ) @ llmify def gener...

First seen: 2025-04-10 14:44

Last seen: 2025-04-11 01:46