smartfunc  by koaning

SDK for turning docstrings into LLM functions

created 4 months ago
498 stars

Top 63.2% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
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

3 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
26 stars in the last 90 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
2 more.

prompt-engine by microsoft

0.0%
3k
NPM library for LLM prompt engineering
created 3 years ago
updated 2 years ago
Feedback? Help us improve.