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 prompts and manage their execution. Key features:

  • Parallel: completions run concurrently
  • Lightweight: only dependency is openai
  • Lloam prompts: clean function syntax for inline prompts

Usage

pip install lloam

Overview: completions, prompts, agents

Lloam Completions

lloam.completion is a simple and familiar way to generate completions. It returns a Completion object, which manages the token stream. Tokens are accumulated concurrently, meaning completions won't block your program until you acess their results (e.g. with str() or print()).

from lloam import completion


# strings
prompt = "Snap, crackle, and"
who = completion(prompt, stop="!", model="gpt-3.5-turbo")

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

messages = [
    {"role": "system", "content": "You answer questions in haikus"},
    {"role": "user", "content": "What's loam"}
]
poem = completion(messages)

# ...completions are running concurrently...

print(who)     # pop
print(capitol) # The capital of France is Paris
print(poem)    # Soil rich and robust,
               # A blend of clay, sand, and silt,
               # Perfect for planting.

Lloam Prompts

Lloam prompts offer a clean templating syntax you can use to write more complex prompts inline. The language model fills the [holes], while {variables} are substituted into the prompt. Lloam prompts run concurrently just like completions, under the hood they are managing a sequence of Completions.

import lloam

@lloam.prompt(model="gpt-3.5-turbo")
def group_name(x, n=5):
    """
    One kind of {x} is a [name].

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


animal = group_name("domestic animal")
print("This prints immediately!")

# access variables later
print(animal.name)           # dog
print(animal.group_name)     # pack

You can also inspect the live state of a prompt with .inspect():

musician_type = group_name("musician", n=3)

import time
for _ in range(3):
    print(musician_type.inspect())
    print("---")
    time.sleep(0.5)

print(musician_type.name)
print(musician_type.group_name)

# output:

# One kind of musician is a [ ... ].

# 3 [ ... ]s makes a [     ].
# ---
# One kind of musician is a singer-songwriter.

# 3 singer-songwriters makes a [ ... ].
# ---
# One kind of musician is a singer-songwriter.

# 3 singer-songwriters makes a trio.
# ---
# singer-songwriter
# trio

Lloam Agents

Lloam encourages you to think of an agent as a datastructure around language. Here's how you could make a RAG Agent that has

  • a chat history
  • a database
  • a context for retrieved artifacts

You can see another example in examples/shell_agent.py. More stuff on agents coming soon!

import lloam

class RagAgent:
    def __init__(self, db):
        self.db = db
        self.history = []
        self.artifacts = {}

    def ask(self, question):
        self.history.append({"role": "user", "content": question})

        results = self.db.query(question)
        self.artifacts.update(results)

        answer = self.answer(question)

        self.history.append({"role": "assistant", "content": answer.answer})

        return {
            "answer": answer.answer
            "followup": answer.followup
        }


    @lloam.prompt
    def answer(self, question):
        """
        {self.artifacts}
        ---
        {self.history}

        user: {question}

        [answer]

        What would be a good followup question?
        [followup]
        """

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.3.tar.gz (11.4 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.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lloam-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b78263157be89841de711767dab074e15d6a3917742434f43fc5de68c385b2e7
MD5 0e98b8ffe07c3e2bdb3ce4e8af7a2a61
BLAKE2b-256 1ef54b346c74da0c6bb659c8d84542950192f0f9acb91345d9d36b00068764d7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for lloam-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 325d3d87d002a75f7a1d53457b52a2c6adcb72c6fbfa2c96b5d8989714924be9
MD5 1563b98fc89c5f856bada8646f7b2547
BLAKE2b-256 03eb5e51b9ab493a119749fb4b51a81be502626e3126fd16af212b32ae100cf6

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