smartfunc  by koaning

SDK for turning docstrings into LLM functions

Created 6 months ago
502 stars

Top 62.0% on SourcePulse

GitHubView on GitHub
Project Summary

This library simplifies LLM interactions by transforming Python docstrings into executable prompts, targeting developers who want to quickly prototype LLM-powered features. It leverages the llm library to parse docstrings, inject variables, and execute prompts against various LLM backends, offering a streamlined approach to prompt engineering.

How It Works

The core mechanism involves a decorator that parses a function's docstring, treating it as a Jinja2 template. This template is then populated with function arguments at runtime to construct a prompt. The prompt is sent to an LLM backend specified in the decorator, and the response is returned. This approach provides syntactic sugar over the llm library, enabling features like Pydantic schema validation for structured outputs and flexible prompt customization via inner functions.

Quick Start & Requirements

  • Install via pip: pip install smartfunc
  • Requires an LLM API key (e.g., OpenAI) configured via .env files.
  • Supports various LLM backends available through the llm library.
  • Official documentation and examples are available.

Highlighted Details

  • Turns docstrings into LLM-executable prompts using Jinja2 templating.
  • Supports Pydantic models for structured LLM responses.
  • Allows for advanced prompt engineering by returning strings from inner functions.
  • Includes async_backend for asynchronous operations and microbatching.
  • Offers a debug=True mode to inspect prompts and responses.

Maintenance & Community

The project is maintained by koaning and relies on the llm library, which has a large community and is actively maintained.

Licensing & Compatibility

The library is released under the MIT license, permitting commercial use and integration with closed-source projects.

Limitations & Caveats

The library is designed for simplicity and rapid prototyping, intentionally omitting features found in more comprehensive libraries like instructor, ell, or marvin. Schema support is backend-dependent, and users may encounter errors if a chosen backend does not support it.

Health Check
Last Commit

5 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
4 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera), and
6 more.

prompt-engine by microsoft

0.1%
3k
NPM library for LLM prompt engineering
Created 3 years ago
Updated 2 years ago
Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Kevin Hou Kevin Hou(Head of Product Engineering at Windsurf), and
6 more.

TypeChat by microsoft

0.1%
9k
Library for building natural language interfaces using types
Created 2 years ago
Updated 2 months ago
Feedback? Help us improve.