Skip to main content

A fertile collection of primitives for building things with LLMs

Project description

Rich primitives for building with LLMs

Lloam 🌱

Lloam is a minimal prompting library offering a clean way to write prompt templates and manage their execution. Key features:

  • Manage parallel completions without touching asyncio
  • Light: only dependency is openai
  • Call prompt templates as functions
  • Doesn't stream unwanted tokens

Lloam Prompts

Lloam prompts make a prompt template callable as a function. The prompt template goes in the docstring of the lloam function, and returns a Prompt object that runs the completions in the background.

  • Variables ({x}) are substituded into the prompt with curly braces like f-strings.
  • Holes ([name]) are filled by the language model, and can be used as variables afterward.
  • Completions run in the background and only block when you access variables
import lloam

@lloam.prompt
def test(x, y=5):
    """
    One kind of {x} is a [name].

    {y} {name}s makes a [group_name].
    """

template = test("domestic animal") # fills template in the background

# ... code here runs immediately ...

# access completions later
print(template.name)           # dog
print(template.group_name)     # pack

Inspect running templates: You can print a template while it's running to investigate its state.

template = test("domestic animal")

import time

for _ in range(3):
    print(template)
    print("---")
    time.sleep(0.5)

# One kind of domestic animal is a [ ... ].
#
# 5 [ ... ]s makes a [     ].
# ---
# One kind of domestic animal is a dog.
#
# 5 dogs makes a [ ... ].
# ---
# One kind of domestic animal is a dog.
#
# 5 dogs makes a pack.
# ---

Infer stopping conditions: Uses the context of a prompt to infer stopping conditions, like quotes, commas, and periods

@lloam.prompt
def jsonify(entity):
    """
    \{"name": "{entity}", "color": "[color]", "taste": "[taste]" \}
    """

template = jsonify("mango")

mango_json = json.loads(str(template).strip())
print(mango_json)
# {'name': 'mango', 'color': 'yellow', 'taste': 'sweet and tangy'}

Lloam Completions

For a traditional completion, use the completion function. A completion runs in the background until you call .result(), making it simple to run several completions in parallel without blocking your program.

from lloam import completion

# messages
messages = [
    {"role": "system", "content": "You are a helpful assistant"},
    {"role": "user", "content": "What is loam?"}
]
loam_definition = completion(messages)

# strings
prompt = "Billy Joel said: Sing us a song you're "
lyric = completion(prompt, stop=[".", "!", "\n"])

# chunks
chunks = ["The capi", "tal of", " France ", "is", " "]
capitol = completion(chunks, stop=".")


print(loam.result())
# Loam is fertile soil,
# A mix of sand, silt, and clay,
# Perfect for planting.

print(lyric.result())
# the piano man 

print(capitol.result())
# Paris

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

lloam-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lloam-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file lloam-0.1.1.tar.gz.

File metadata

  • Download URL: lloam-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for lloam-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3fa986126dba18745777b2b558df4aa9dad849157472e6efca24edd68ddf43a1
MD5 cda6dd60a13befa652691c4ff999820b
BLAKE2b-256 e6bce0e86e01257c483b04a66cf52097f5d2a15c335287b6ee5b17ef55db798c

See more details on using hashes here.

File details

Details for the file lloam-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lloam-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for lloam-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 105977dc8a5697e7cfca60c6a0d56b721e68f8f37d376ca11be2a1ffbd2fad37
MD5 9d0825b0a277d2102bd1983e53f46fb2
BLAKE2b-256 e6d4e62fab05ad6a7abab17aea8a065f6261b0810b2a6226026074b14219dff5

See more details on using hashes here.

Supported by

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