llmware-ai / llmware
- среда, 13 декабря 2023 г. в 00:00:09
Providing enterprise-grade LLM-based development framework, tools, and fine-tuned models.
llmware
is a unified, open, extensible framework for LLM-based application patterns including Retrieval Augmented Generation (RAG). This project provides a comprehensive set of tools that anyone can use – from beginner to the most sophisticated AI developer – to rapidly build industrial-grade enterprise LLM-based applications. Key differentiators include: source citation for Q & A scenarios, fact checking, and other guardrails for model hallucination.
With llmware
, our goal is to contribute to and help catalyze an open community around the new combination of open, extensible technologies being assembled to accomplish fact-based generative workflows.
llmware
is an integrated framework comprised of four major components:
pip install llmware
or
python3 -m pip install llmware
See Working with llmware for other options to get up and running.
MongoDB and Milvus are optional and used to provide production-grade database and vector embedding capabilities. The fastest way to get started is to use the provided Docker Compose file which takes care of running them both:
curl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose.yaml
and then run the containers:
docker compose up -d
Not ready to install MongoDB or Milvus? Check out what you can do without them in our examples section.
See Running MongoDB and Milvus for other options to get up and running with these optional dependencies.
# This example demonstrates Retrieval Augmented Retrieval (RAG):
import os
from llmware.library import Library
from llmware.retrieval import Query
from llmware.prompts import Prompt
from llmware.setup import Setup
# Update this value with your own API Key, either by setting the env var or editing it directly here:
openai_api_key = os.environ["OPENAI_API_KEY"]
# A self-contained end-to-end example of RAG
def end_to_end_rag():
# Create a library called "Agreements", and load it with llmware sample files
print (f"\n > Creating library 'Agreements'...")
library = Library().create_new_library("Agreements")
sample_files_path = Setup().load_sample_files()
library.add_files(os.path.join(sample_files_path,"Agreements"))
# Create vector embeddings for the library using the "industry-bert-contracts model and store them in Milvus
print (f"\n > Generating vector embeddings using embedding model: 'industry-bert-contracts'...")
library.install_new_embedding(embedding_model_name="industry-bert-contracts", vector_db="milvus")
# Perform a semantic search against our library. This will gather evidence to be used in the LLM prompt
print (f"\n > Performing a semantic query...")
os.environ["TOKENIZERS_PARALLELISM"] = "false" # Avoid a HuggingFace tokenizer warning
query_results = Query(library).semantic_query("Termination", result_count=20)
# Create a new prompter using the GPT-4 and add the query_results captured above
prompt_text = "Summarize the termination provisions"
print (f"\n > Prompting LLM with '{prompt_text}'")
prompter = Prompt().load_model("gpt-4", api_key=openai_api_key)
sources = prompter.add_source_query_results(query_results)
# Prompt the LLM with the sources and a query string
responses = prompter.prompt_with_source(prompt_text, prompt_name="summarize_with_bullets")
for response in responses:
print ("\n > LLM response\n" + response["llm_response"])
# Finally, generate a CSV report that can be shared
print (f"\n > Generating CSV report...")
report_data = prompter.send_to_human_for_review()
print ("File: " + report_data["report_fp"] + "\n")
end_to_end_rag()
> python examples/rag_with_openai.py
> Creating library 'Agreements'...
> Generating vector embeddings using embedding model: 'industry-bert-contracts'...
> Performing a semantic query...
> Prompting LLM with 'Summarize the termination provisions'
> LLM response
- Employment period ends on the first occurrence of either the 6th anniversary of the effective date or a company sale.
- Early termination possible as outlined in sections 3.1 through 3.4.
- Employer can terminate executive's employment under section 3.1 anytime without cause, with at least 30 days' prior written notice.
- If notice is given, the executive is allowed to seek other employment during the notice period.
> Generating CSV report...
File: /Users/llmware/llmware_data/prompt_history/interaction_report_Fri Sep 29 12:07:42 2023.csv
To get started with a proprietary model, you need to provide your own API Keys. If you don't yet have one, more information can be found at: AI21, Ai Bloks, Anthropic, Cohere, Google, OpenAI.
API keys and secrets for models, aws, and pinecone can be set-up for use in environment variables or managed however you prefer.
You can also access the llmware
public model repository which includes out-of-the-box custom trained sentence transformer embedding models fine-tuned for the following industries: Insurance, Contracts, Asset Management, SEC. These domain specific models along with llmware's generative BLING model series ("Best Little Instruction-following No-GPU-required") and DRAGON model series ("Delivering RAG on ...") are available at llmware on Huggingface. Explore using the model repository and the llmware
Huggingface integration in llmware examples.
There are several options for getting MongoDB running
docker run -d -p 27017:27017 -v mongodb-volume:/data/db --name=mongodb mongo:latest
Create a docker-compose.yaml file with the content:
version: "3"
services:
mongodb:
container_name: mongodb
image: 'mongo:latest'
volumes:
- mongodb-volume:/data/db
ports:
- '27017:27017'
volumes:
llmware-mongodb:
driver: local
and then run:
docker compose up
You can connect to an existing MongoDB deployment by setting the connection string to the environment variable, COLLECTION_DB_URI
. See the example script, Using Mongo Atlas, for detailed information on how to use Mongo Atlas as the NoSQL and/or Vector Database for llmware
.
Additional information on finding and formatting connection strings can be found in the MongoDB Connection Strings Documentation.
The llmware repo can be pulled locally to get access to all the examples, or to work directly with the latest version of the llmware code.
git clone git@github.com:llmware-ai/llmware.git
or download/extract a zip of the llmware repository
Update the local copy of the repository:
git pull
Download the shared llmware native libraries and dependencies by running the load_native_libraries.sh script. This pulls the right wheel for your platform and extracts the llmware native libraries and dependencies into the proper place in the local repository.
./scripts/dev/load_native_libraries.sh
At the top level of the llmware repository run the following command:
pip install .
Questions and discussions are welcome in our github discussions.
Interested in contributing to llmware? We welcome involvement from the community to extend and enhance the framework!
Information on ways to participate can be found in our Contributors Guide. As with all aspects of this project, contributing is governed by our Code of Conduct.
Supported Operating Systems:
Supported Vector Databases:
Prereqs:
Optional:
Known issues:
8 Dec 2023: llmware v0.1.11
30 Nov 2023: llmware v0.1.10
24 Nov 2023: llmware v0.1.9
17 Nov 2023: llmware v0.1.8
14 Nov 2023: llmware v0.1.7
03 Nov 2023: llmware v0.1.6
27 Oct 2023: llmware v0.1.5
llmware
BLING models).20 Oct 2023: llmware v0.1.4
13 Oct 2023: llmware v0.1.3
06 Oct 2023: llmware v0.1.1
02 Oct 2023: llmware v0.1.0 🔥 Initial release of llmware to open source!! 🔥