Skip to main content

LLMFlows - Simple, Explicit and Transparent LLM Apps

Project description

LLMFlows - Simple, Explicit, and Transparent LLM Apps

Twitter Pylint workflow License PyPi Stars Release date

About

LLMFlows is a simple and lightweight framework for building LLM-powered applications.

Installation

You can quickly install LLMFlows with pip

pip install llmflows

Documentation

The full documentation including user guides and api reference can be found at readthedocs.

Philosophy

Simple

Our goal is to build a simple, well documented framework with a minimal set of classes and abstractions that allow users to build flexible LLM-powered apps without compromising on capabilities.

Explicit

We want to create an explicit API enabling users to write clean, and readable code while being able to easily create complex flows of LLMs interacting with each other.

Transparent

We aim helping users have full transparency on their LLM-powered apps by providing traceable flows, and complete information for each component of the app making it easy to monitor, maintain, and debug.

Usage

Here is a minimal example of an LLM with a PromptTemplate:

from llmflows.llms.openai import OpenAI
from llmflows.prompts.prompt_template import PromptTemplate

prompt_template = PromptTemplate(
   prompt="Generate a title for a 90s hip-hop song about {topic}."
)
llm_prompt = prompt_template.get_prompt(topic="friendship")

llm = OpenAI()
song_title = llm.generate(llm_prompt)

While this is a good example on how easy it is to use LLMFlows, real-world applications are more complex and have dependencies between prompts, and LLMs outputs. Let's take a look at such example. Complex flow With LLMFlows it's quite easy to reproduce this flow by utilizing the Flow and Flowstep classes. LLMFlows will figure out the dependencies and make sure each flowstep is executed only when the flowsteps it depends on are complete:

from llmflows.flows import Flow, Flowstep
from llmflows.llms import OpenAI
from llmflows.prompts import PromptTemplate

# Create prompt templates
title_template = PromptTemplate("What is a good title of a movie about {topic}?")
song_template = PromptTemplate(
    "What is a good song title of a soundtrack for a movie called {movie_title}?"
)
characters_template = PromptTemplate(
    "What are two main characters for a movie called {movie_title}?"
)
lyrics_template = PromptTemplate(
    "Write lyrics of a movie song called {song_title}. The main characters are"
    " {main_characters}"
)

# Create flowsteps
flowstep1 = FlowStep(
    name="Flowstep 1",
    llm=OpenAI(),
    prompt_template=title_template,
    output_key="movie_title",
)

flowstep2 = FlowStep(
    name="Flowstep 2",
    llm=OpenAI(),
    prompt_template=song_template,
    output_key="song_title",
)

flowstep3 = FlowStep(
    name="Flowstep 3",
    llm=OpenAI(),
    prompt_template=characters_template,
    output_key="main_characters",
)

flowstep4 = FlowStep(
    name="Flowstep 4",
    llm=OpenAI(),
    prompt_template=lyrics_template,
    output_key="song_lyrics",
)

# Connect flowsteps
flowstep1.connect(flowstep2, flowstep3, flowstep4)
flowstep2.connect(flowstep4)
flowstep3.connect(flowstep4)

# Create and run Flow
soundtrack_flow = Flow(flowstep1)
soundtrack_flow.execute(topic="friendship")

In fact, LLMFlows provides async, and threaded classes so any complex DAG can be executed in parallel. For more examples such as how to create question answering apps and web applications with Flask and FastAPI check our documentation.

FAQ

How is this different than langchain?

Langchain is a great library and LLMFlows has been been certainly inspired by it. However, our philosophy is a bit different. Langchian has a "chain for everything" philosophy and provides many classes that come with multiple LLM calls, logic, and built-in default prompts. While this is great for beginners and default use-cases, we feel this can be a bit overwhelming if users want to do anything "out of the ordinary". In contrast, we are focusing on providing as few building blocks as possible and having an easy to understand API while matching (and in some cases exceeding) the capabilities of langchain.

You only have OpenAI wrappers but I want to use AcmeLLM?

We decided to release the library initially supporting only OpenAI LLMs but we have a roadmap and we will slowly add new wrappers around the most popular models. If you are willing to spend some time we are looking for contributors and maintainers

You only support Pinecone and Redis vector DBs do you have plans to extend the list?

Yes! We will also add Redis, Elastic Search and other popular solutions over time. If you want to help us out check out our contribution section.

Why can't I find any info related to document loaders?

For the time being we have decided not to implement document loaders for few reasons:

  1. There are plenty of capable libraries like Llama-index and langchain that have tons of loaders.
  2. We think it is awkward to mix document loaders together with LLM and prompt management libraries since usually document loading happens in separate pipelines and are not part of the LLM-powered app.
  3. Real-life documents are messy. In our experience, no matter how many loaders are out there they will never cover all the specific use-cases.

While we are not going to invest time into document loaders we might decide to change direction if we get significant interest and contributors.

What about agents?

We believe agents are the future of LLM-powered apps and we have a few basic examples in the repo. However, we are working on a agent-focused library built on top of llmflow.

License

LLMFlows is covered by the MIT license. For more information check LICENCE.md.

Contributing

Thank you for spending the time to read our README! If you like what you saw and are considering contributing please check CONTRIBUTING.md

Links

Twitter

Documentation

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

llmflows-0.0.5.tar.gz (21.2 kB view hashes)

Uploaded Source

Built Distribution

llmflows-0.0.5-py3-none-any.whl (34.0 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