Use an LLM to execute code
Project description
Manifest
man·i·fest [verb]
: to make something happen by imagining it and consciously thinking that it will happen
Manifest is an experiment in letting an LLM provide the return value for a function. It allows you to manifest powerful behaviors into existence merely by defining the function's facade.
Shout out to @dstufft for gifting me the PyPI repo
name manifest
🙏
Examples
Sentiment analysis
from manifest import ai
@ai
def is_pessimistic(text: str) -> bool:
""" Determines if the text is pessimistic"""
...
assert is_pessimistic("This is a silly tool and nobody will ever use it.")
Translation
from manifest import ai
@ai
def translate(english_text: str, target_lang: str) -> str:
""" Translates text from english into a target language """
...
assert translate("Hello", "fr") == "Bonjour"
Image analysis
You can pass in bytes to make use of a model's multimodal abilities. COMING SOON
import io
from manifest import ai
@ai
def breed_of_dog(image: io.BytesIO) -> str:
""" Determines the breed of dog from a photo """
...
image = open("/path/to/terrier.jpg", "r")
print(breed_of_dog(image))
Complex objects
Your function can use fairly complex data structures.
from dataclasses import dataclass
from manifest import ai
@dataclass
class Actor:
name: str
character: str
@dataclass
class Movie:
title: str
director: str
year: int
top_cast: list[Actor]
@ai
def similar_movie(movie: str, before_year: int | None=None) -> Movie:
"""Discovers a similar movie, before a certain year, if the year is
provided."""
...
like_inception = similar_movie("Inception")
print(like_inception)
How does it work?
Manifest relies heavily on runtime metadata, such as a function's name, docstring, arguments, and type hints. It uses all of these to compose a prompt behind the scenes, then sends the prompt to an LLM. The LLM "executes" the prompt, and returns a json-based format that we can safely parse back into the appropriate object.
To get the most out the @ai
decorator:
- Name your function well.
- Add type hints to your function.
- Add a high-value docstring to your function.
Limitations
You can only pass in and return the following types:
- Dataclasses
Enum
subclasses- primitives (str, int, bool, None, etc)
- basic container types (list, dict)
- unions
- Any combination of the above
Initialization
To make things super simple, manifest uses ambient LLM credentials, currently
just OPENAI_API_KEY
. If environment credentials are not found, you will be
instructed to initialize the library yourself.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.