Using LLMs to Implement Abstract Methods in Python: The llm-strategy Package
The llm-strategy package is a Python package that uses LLMs (such as OpenAI's GPT-3) to implement abstract methods in interface classes. It does this by forwarding requests to the LLM and converting the responses back to Python data using Python's
@dataclasses. The package can use docstrings, type annotations, and method/function names as prompts for the LLM, and can automatically convert the results back into Python types (currently only supporting
@dataclasses). It can also extract a data schema to send to the LLM for interpretation. While the llm-strategy package still relies on some Python code, it has the potential to reduce the need for this code in the future by using additional, cheaper LLMs to automate the parsing of structured data.
The package includes an example implementation of the
llm_strategy decorator for the
CustomerDatabase classes using OpenAI's LLMs. The example code shows how to find the keys of the customers that match a natural language query best and how to load and store the customer database from/to a file using LLMs. There is also a full example in
customer_database_search.py for searching the customer database.
If you're interested in using LLMs in Python to improve your software engineering practices, the llm-strategy package may be worth exploring. For a wider perspective on why this package could be important in the future, check out this blog post.
Tags: Python, OpenAI, LLMs