Easily integrate LLMs into Python code.
Project description
magic-lamp
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
- https://github.com/jackmpcollins/magentic - A similar concept but using decorators.
- https://github.com/PrefectHQ/marvin - Antoher similar concept.
- https://github.com/abetlen/llama-cpp-python - Used by this library to run the local LLM.
- https://ai.meta.com/blog/meta-llama-3-1/ - Llama 3.1 8b is the default model.
- https://huggingface.co/bullerwins/Meta-Llama-3.1-8B-Instruct-GGUF - Uses these GGUFs by default.
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
Built Distribution
File details
Details for the file magic_lamp-0.4.1.tar.gz
.
File metadata
- Download URL: magic_lamp-0.4.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-39-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 234f496ab958c3c221f8090b56a0f6e673c20bd8b3cae072440b5203a48b9f6d |
|
MD5 | 923ec0fb1f1ef8636a35e96ee4fdc521 |
|
BLAKE2b-256 | ddb208345d4fddbb974bf8b111fdc2dd80a753e8979de1bd7c5607596ca0f77a |
File details
Details for the file magic_lamp-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: magic_lamp-0.4.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-39-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecc215928b03b99b09f3722c215b938e51a0263d8f4f62b6427b7c78a3c87a70 |
|
MD5 | 0ca2ad0cbba664289f27196586a01ace |
|
BLAKE2b-256 | 8d4f3ec727a54b982e065fa150e0d2f6c3c4e0ea4a659d36bcce8fc688709975 |