Skip to main content

Easily integrate LLMs into Python code.

Project description

magic-lamp

PyPI - Version

Create magic LLM-powered Python functions that return anything you ask for. Downloads and uses a local LLM.

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

magic_lamp-0.4.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

magic_lamp-0.4.0-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page