Python package for strongly-typed LLM function calls
Top 47.6% on sourcepulse
Fructose provides a Pythonic interface for interacting with Large Language Models (LLMs) by treating LLM calls as strongly-typed functions. It targets developers seeking to integrate LLMs into applications with predictable data structures and robust error handling, simplifying complex LLM interactions through type annotations and decorators.
How It Works
Fructose uses a Python decorator (@ai
) that introspects type-annotated functions. When a decorated function is called, Fructose constructs a prompt based on the function's signature, docstring, and type hints, then sends it to an LLM (defaulting to OpenAI). The LLM's response is parsed and validated against the function's return type, supporting primitive, compound, and dataclass types. This approach ensures type safety and reduces boilerplate code for LLM integration.
Quick Start & Requirements
pip3 install fructose
export OPENAI_API_KEY=sk-abcdefghijklmnopqrstuvwxyz
)Highlighted Details
@ai
decorated functions) via the uses
argument.chain_of_thought
), and custom OpenAI clients for proxying or alternative API endpoints.Maintenance & Community
The project is currently paused due to maintenance being directed elsewhere. The authors suggest alternatives like Instructor or Marvin and welcome forks or new maintainers.
Licensing & Compatibility
The README does not explicitly state a license. Compatibility with commercial or closed-source projects is not specified.
Limitations & Caveats
Fructose is in v0, indicating an unstable API that may break between versions. LLM generation non-determinism can also lead to call failures. The project is under a maintenance pause, and official support for alternative LLM providers or APIs is not guaranteed.
1 year ago
1 day