Skip to content

Magic LLM-powered Python functions that return anything you ask for. Many caveats.

License

Notifications You must be signed in to change notification settings

rameshvarun/magic-lamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

magic-lamp

PyPI - Version

Create magic LLM-powered Python functions that return anything you ask for. Many caveats.

Quickstart

pip install magic-lamp

Define a function with a description and a set of examples.

import magic_lamp

get_atoms = magic_lamp.Function(
    "Break this molecule down into it's constituent atoms. Return as a set.",
    examples=[
        ("water", {"hydrogen", "oxygen"}),
        ("glucose", {"carbon", "hydrogen", "oxygen"}),
    ],
)

print(get_atoms("ammonia")) # => {"nitrogen", "hydrogen"}

Functions can return any Python literal (strings, numbers, dicts, tuples lists, etc). No API keys are required, since by default magic-lamp downloads and runs a local LLM.

Configuring the LLM

By default, magic-lamp downloads and runs a local LLM from Hugging Face. For more complex tasks, OpenAI models will perform better.

Using OpenAI

OPENAI_API_KEY must be set in the environment. Pass in the name of a gpt-* model to the function constructor.

import magic_lamp

format_number = magic_lamp.Function(
    'Write this number out in words.',
    examples=[
        (1, "one"),
        (35, "thirty-five"),
        (15690, "fifteen thousand, six hundred ninety"),
    ],
    model="gpt-4o-mini"
)

print(format_number(328745226793))

Links

About

Magic LLM-powered Python functions that return anything you ask for. Many caveats.

Topics

Resources

License

Stars

Watchers

Forks