Skip to main content

Easily integrate LLMs into Python code.

Project description

magic-lamp

PyPI - Version

Easily integrate LLM calls into Python code. By default, uses a local LLM.

Quickstart

pip install magic-lamp

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

import magic_lamp

format_name = magic_lamp.Function(
    'Format this surname in a way that it would be written out.',
    examples=[
        ("PERALTA", "Peralta"),
        ("OCONNELL", "O'Connel"),
        ("MCDONALD", "McDonald")
    ],
)

print(format_name("MCDOWELL"))

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.3.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

magic_lamp-0.3.0-py3-none-any.whl (3.9 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