man·i·fest [verb]
: to make something happen by imagining it and consciously thinking that it will happen
Want to use an LLM in your code without writing prompts or setting up an LLM client? Manifest makes it as easy as writing a function that describes what you want.
Classify some text as positive or not.
from manifest import ai
@ai
def is_optimistic(text: str) -> bool:
""" Determines if the text is optimistic"""
assert is_optimistic("This is amazing!")
Translate text from one language to another.
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"
Analyze images by passing in a Path to a file.
from pathlib import Path
from manifest import ai
@ai
def breed_of_dog(image: Path) -> str:
"""Determines the breed of dog from a photo"""
image = Path("path/to/dog.jpg")
print(breed_of_dog(image))
For advanced uses, you can return 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)
pip install manifest
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.
Manifest doesn't work from the REPL, due to it needing access to the source code of the functions it decorates.
You can only pass in and return the following types:
- Dataclasses
Enum
subclasses- primitives (str, int, bool, None, etc)
- basic container types (list, dict, tuple)
- unions
- Any combination of the above
The prompt templates are also a little fiddly sometimes. They can be improved.
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.