llmflows

stoyan-stoyanov/llmflows

Simple, Explicit and Transparent LLM Applications

706
Stars
35
Forks
19
Open issues
10
Watchers
1y
Last push
Python MITCreated Jun 26, 2023

Overview

LLMFlows is a framework in Python aimed at facilitating the creation of explicit and transparent AI applications powered by Large Language Models (LLMs). It supports building chatbots, Q&A systems, and similar applications without hidden prompts or calls.

Capability facts

No sourced capability facts yet. Facts appear after ingest scans repo manifests (Dockerfile, package.json, MCP configs).

Categories

Tags

README

Documentation: https://llmflows.readthedocs.io
PyPI: https://pypi.org/project/llmflows
Twitter: https://twitter.com/LLMFlows
Substack: https://llmflows.substack.com

🤖 About LLM Flows

LLMFlows is a framework for building simple, explicit, and transparent LLM(Large Language Model) applications such as chatbots, question-answering systems, and agents.

At its core, LLMFlows provides a minimalistic set of abstractions that allow you to utilize LLMs and vector stores and build well-structured and explicit apps that don't have hidden prompts or LLM calls. LLM Flows ensures complete transparency for each component, making monitoring, maintenance, and debugging easy.

📦 Installation

pip install llmflows

🧭 Philosophy

Simple

Our goal is to build a simple, well-documented framework with minimal 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 easily creating complex flows of LLMs interacting with each other. LLMFlows' classes give users full control and do not have any hidden prompts or LLM calls.

Transparent

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

▶️ Live Demo

Check out LLM-99 - a demo app that uses LLMs to explain superconductors in simple terms. The app is built with LLMFlows, and FastAPI and uses Pinecone to store document embeddings created from Wikipedia articles. You can find the source code for this demo app and other examples in our examples folder.

🧪 Getting Started

LLMs

LLMs are one of the main abstractions in LLMFlows. LLM classes are wrappers around LLM APIs such as OpenAI's APIs. They provide methods for configuring and calling these APIs, retrying failed calls, and formatting the responses.

from llmflows.llms import OpenAI

llm = OpenAI(api_key="<your-openai-api-key>")

result, call_data, model_config = llm.generate(
   prompt="Generate a cool title for an 80s rock song"
)

PromptTemplates

The PromptTemplate class allows us to create strings with variables that we can fill in dynamically later on. Once a prompt template object is created an actual prompt can be generated by providing the required variables.

from llmflows.llms import OpenAI
from llmflows.prompts 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")

print(llm_prompt)

llm = OpenAI(api_key="<your-openai-api-key>")
song_title = llm.generate(llm_prompt)

print(song_title)

Chat LLMs

Unlike regular LLMs that only require a prompt to generate text, chat LLMs require a conversation history. The conversation history is represented as a list of messages between a user and an assistant. This conversation history is sent to the model, and a new message is generated based on it.

LLMFlows provides a MessageHistory class to manage the required conversation history for chat LLMs.

You can build a simple chatbot by using the OpenAIChat and MessageHistory classes:

from llmflows.llms import OpenAIChat, MessageHistory

llm = OpenAIChat(api_key="<your-openai-api-key>")
message_hist

Command menu

Search tools or jump to a page