Skip to main content

The bloat moat! - A lightweight LLM and Agent interaction library

Project description

tests

Python Test Status codecov PyPI version Documentation Status Code style: black pre-commit License: MIT Contributor Covenant

🤺 Fence

Fence is a simple, lightweight library for LLM communication. A lot of the functionality was inspired by/derived of LangChain (the OG LLM package) basics, since that's how the package was born - as a stripped down version of LangChain functionality, with cooler names.

🤔 Raison d'être

The simple answer: by accident. The slightly longer answer: LangChain used to be (is?) a pretty big package with a ton of dependencies. The upside is that it's powerful for PoC purposes, because it has it all.

The downsides:

  • It's big. It takes up a lot of space (which can be an issue in some environments/runtimes), often for functionality that isn't needed.
  • It's fairly complex. It's a big package with a lot of functionality, which can be overwhelming for new users.
  • It wasn't exactly dependable in an industrial setting before. Version jumps were common, and the package was often broken after a new release.

As a result, many developers (particularly those working in large production environments) have advocated for more lightweight, custom functionality that favors stability and robustness.

Circling back: why Fence?

Since our work was in a production environment, mostly dealing with Bedrock, we just started building some basic components from scratch. We needed a way to communicate with our models, which turned out to as the Link class (wink wink). Then, some other things were added left and right, and this eventually turned into a miniature package. Not in small part because it was fun to go down this road. But mostly because it strikes the right balance between convenience and flexiblity.

Naturally, it's nowhere as powerful as, for instance, LangChain. If you want to build a quick PoC with relatively complex logic, maybe go for the OG instead. If you want to be set on your way with a simple, lightweight package that's easy to understand and extend, Fence might be the way to go.

🛠️ How do I use it?

Fence just has a few basic components. See the notebooks for examples on how to use them. Documentation is coming soon, but for now, you can check out the source code for more details.

📦 Installation

You can install Fence from PyPI:

pip install fence-llm

👋 Look ma, no dependencies (kinda)!

Here's a hello world example:

from fence.links import Link
from fence.templates.string import StringTemplate
from fence.models.openai import GPT4omini

# Create a link
link = Link(
    model=GPT4omini(),
    template=StringTemplate("Write a poem about the value of a {topic}!"),
    name='hello_world_link'
)

# Run the link
output = link.run(topic='fence')['state']
print(output)

This will output something like:

[2024-10-04 17:45:15] [ℹ️ INFO] [links.run:203]              Executing <hello_world_link> Link
Sturdy wood and nails,
Boundaries draw peace and calm,
Guarding hearts within.

Much wow, very next level. There's more in the notebook section, with a lot more to cover!

💪 Features

What can I do with Fence?

  • Uniform interface for LLMs. Since our main use case was Bedrock, we built Fence to work with Bedrock models. However, it also has openAI support, and it's easy to extend to other models (contributors welcome!)
  • Links and Chains help you build complex pipelines with multiple models. This is a feature that's been around since LangChain, and it's still here. You can parametrize templates, and pass the output of one model to another.
  • Template classes that handle the basics, and that work across models (e.g., a MessageTemplate can be sent to a Bedrock Claude3 model, or to an openAI model - system/user/assistant formatting is handled under the hood).
  • Agents to move on to the sweet, sweet next level of LLM orchestration. Built using the ReAct pattern.
  • Basic utils on board for typical tasks like retries, parallelization, logging, output parsers, etc.

🤝 Contributing

We welcome contributions! Check out the CONTRIBUTING.md for more details.

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

fence_llm-1.0.14.tar.gz (111.5 kB view details)

Uploaded Source

Built Distribution

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

fence_llm-1.0.14-py3-none-any.whl (108.1 kB view details)

Uploaded Python 3

File details

Details for the file fence_llm-1.0.14.tar.gz.

File metadata

  • Download URL: fence_llm-1.0.14.tar.gz
  • Upload date:
  • Size: 111.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fence_llm-1.0.14.tar.gz
Algorithm Hash digest
SHA256 597a7a8e96e06ae9863c6427ec97a632c9bd6ccd211968421fdd765567cf798f
MD5 8f57d728a0c8b260b865fa4590894d41
BLAKE2b-256 7c6b7fbc5ceb813e625b25839f274f7141028e3354bce6c7bcc182d908a3f48e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fence_llm-1.0.14.tar.gz:

Publisher: publish-pipeline.yaml on WouterDurnez/fence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fence_llm-1.0.14-py3-none-any.whl.

File metadata

  • Download URL: fence_llm-1.0.14-py3-none-any.whl
  • Upload date:
  • Size: 108.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fence_llm-1.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 03fb3a2bf4170462ac35ea57515e1ce7944cb01a8c45afb10a1c49f668f03d38
MD5 4bc626eef1f6f44ef5add0ca4556a691
BLAKE2b-256 feaf6a1b43d2b9809dc34560f22601e968d392267c16a2a33c5a3a3a299b260e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fence_llm-1.0.14-py3-none-any.whl:

Publisher: publish-pipeline.yaml on WouterDurnez/fence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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