LLM Strategy logo

LLM Strategy

Free

implementing the Strategy Pattern using LLMs ![GitHub Repo stars](https://img.shields.io/github/stars/BlackHC/llm-strategy?style=social)

FreeFree tier
Type
Open Source

About LLM Strategy

llm-strategy is an open-source Python library that implements the Strategy Pattern using Large Language Models (LLMs), such as OpenAI's GPT-3. It provides a decorator @llm_strategy that connects Python code to an LLM, enabling the LLM to 'implement' abstract methods in interface classes. The library automatically converts LLM responses back into Python data structures using @dataclasses, leveraging docstrings, type annotations, and function/method names as prompts. It includes support for hyperparameter tracking and trace collection, facilitating meta-optimization and experimentation. The project aims to reduce boilerplate code for LLM integration and explores future possibilities of using cheaper LLMs for automated parsing of structured data.

Key Features

Provides an `@llm_strategy` decorator to implement abstract methods via LLM calls
Uses docstrings, type annotations, and function names as prompts for the LLM
Automatically converts LLM responses into Python `@dataclasses` and structured types
Supports Generics for meta-optimization tasks (hyperparameter tracking and trace collection)
Includes a package for hyperparameter tracking and collecting traces from LLMs
Open source and free to use

Pros & Cons

Pros
  • Provides a strongly-typed interface to LLMs, reducing runtime errors
  • Minimizes boilerplate code for integrating LLM responses into Python applications
  • Enables systematic experimentation and optimization of LLM behavior
  • Open source with active development and documentation
Cons
  • Currently designed for OpenAI's GPT-3 (requires an API key and incurs costs)
  • Limited to Python `@dataclasses` for structured output (no support for other serialization formats out of the box)
  • Experimental project with potential limitations in handling complex or nested type schemas
  • Documentation and examples may be limited for advanced use cases

Best For

Implementing abstract interface methods using an LLM instead of traditional codeMeta-optimizing LLM prompts and hyperparameters by collecting execution tracesAutomatically parsing and structuring LLM responses into typed Python objectsExploring the combination of Software Engineering patterns with Generative AI