GithubHelp home page GithubHelp logo

llmware-ai / llmware Goto Github PK

View Code? Open in Web Editor NEW
3.1K 39.0 272.0 354.8 MB

Providing enterprise-grade LLM-based development framework, tools, and fine-tuned models.

Home Page: https://llmware-ai.github.io/llmware/

License: Apache License 2.0

Python 99.72% Shell 0.23% Dockerfile 0.04%
ai bert embedding-vectors embeddings faiss generative-ai information-retrieval large-language-models machine-learning milvus

llmware's Introduction

llmware

Static Badge PyPI - Version discord

🧰🛠️🔩The Ultimate Toolkit for Building LLM Apps

From quickly building POCs to scalable LLM Apps for the enterprise, LLMWare is packed with all the tools you need.

llmware is an integrated framework with over 50+ models in Hugging Face for quickly developing LLM-based applications including Retrieval Augmented Generation (RAG) and Multi-Step Orchestration of Agent Workflows.

This project provides a comprehensive set of tools that anyone can use - from a beginner to the most sophisticated AI developer - to rapidly build industrial-grade, knowledge-based enterprise LLM applications.

Our specific focus is on making it easy to integrate open source small specialized models and connecting enterprise knowledge safely and securely.

Join us on Discord | Watch Youtube Tutorials | Explore our Model Families on Huggingface

New to RAG? Check out the Fast Start video series

🔥🔥🔥 Multi-Model Agents with SLIM Models - Intro-Video 🔥🔥🔥
Can't wait? Get SLIMs right away:

from llmware.models import ModelCatalog

ModelCatalog().get_llm_toolkit()  # get all SLIM models, delivered as small, fast quantized tools 
ModelCatalog().tool_test_run("slim-sentiment-tool") # see the model in action with test script included  

🎯 Key features

Writing code withllmware is based on a few main concepts:

Model Catalog: Access all models the same way with easy lookup, regardless of underlying implementation.
#   50+ Models in Catalog with 20+ RAG-optimized BLING, DRAGON and Industry BERT models
#   Full support for GGUF, HuggingFace, Sentence Transformers and major API-based models
#   Easy to extend to add custom models - see examples

from llmware.models import ModelCatalog
from llmware.prompts import Prompt

#   all models accessed through the ModelCatalog
models = ModelCatalog().list_all_models()

#   to use any model in the ModelCatalog - "load_model" method and pass the model_name parameter
my_model = ModelCatalog().load_model("llmware/bling-tiny-llama-v0")
output = my_model.inference("what is the future of AI?", add_context="Here is the article to read")

#   to integrate model into a Prompt
prompter = Prompt().load_model("llmware/bling-tiny-llama-v0")
response = prompter.prompt_main("what is the future of AI?", context="Insert Sources of information")
Library: ingest, organize and index a collection of knowledge at scale - Parse, Text Chunk and Embed.
from llmware.library import Library

#   to parse and text chunk a set of documents (pdf, pptx, docx, xlsx, txt, csv, md, json)

#   step 1 - create a library, which is the 'knowledge-base container' construct
#          - libraries have both text collection (DB) resources, and file resources (e.g., llmware_data/accounts/{library_name})
#          - embeddings and queries are run against a library

lib = Library().create_new_library("my_library")

#    step 2 - add_files is the universal ingestion function - point it at a local file folder with mixed file types
#           - files will be routed by file extension to the correct parser, parsed, text chunked and indexed in text collection DB

lib.add_files("/folder/path/to/my/files")

#   to install an embedding on a library - pick an embedding model and vector_db
lib.install_new_embedding(embedding_model_name="mini-lm-sbert", vector_db="milvus", batch_size=500)

#   to add a second embedding to the same library (mix-and-match models + vector db)
lib.install_new_embedding(embedding_model_name="industry-bert-sec", vector_db="faiss", batch_size=100)

#   easy to create multiple libraries for different projects and groups

finance_lib = Library().create_new_library("finance_q4_2023")
finance_lib.add_files("/finance_folder/")

hr_lib = Library().create_new_library("hr_policies")
hr_lib.add_files("/hr_folder/")

#    pull library card with key metadata - documents, text chunks, images, tables, embedding record
lib_card = Library().get_library_card("my_library")

#   see all libraries
all_my_libs = Library().get_all_library_cards()
Query: query libraries with mix of text, semantic, hybrid, metadata, and custom filters.
from llmware.retrieval import Query
from llmware.library import Library

#   step 1 - load the previously created library 
lib = Library().load_library("my_library")

#   step 2 - create a query object and pass the library
q = Query(lib)

#    step 3 - run lots of different queries  (many other options in the examples)

#    basic text query
results1 = q.text_query("text query", result_count=20, exact_mode=False)

#    semantic query
results2 = q.semantic_query("semantic query", result_count=10)

#    combining a text query restricted to only certain documents in the library and "exact" match to the query
results3 = q.text_query_with_document_filter("new query", {"file_name": "selected file name"}, exact_mode=True)

#   to apply a specific embedding (if multiple on library), pass the names when creating the query object
q2 = Query(lib, embedding_model_name="mini_lm_sbert", vector_db="milvus")
results4 = q2.semantic_query("new semantic query")
Prompt with Sources: the easiest way to combine knowledge retrieval with a LLM inference.
from llmware.prompts import Prompt
from llmware.retrieval import Query
from llmware.library import Library

#   build a prompt
prompter = Prompt().load_model("llmware/bling-tiny-llama-v0")

#   add a file -> file is parsed, text chunked, filtered by query, and then packaged as model-ready context,
#   including in batches, if needed, to fit the model context window

source = prompter.add_source_document("/folder/to/one/doc/", "filename", query="fast query")

#   attach query results (from a Query) into a Prompt
my_lib = Library().load_library("my_library")
results = Query(my_lib).query("my query")
source2 = prompter.add_source_query_results(results)

#   run a new query against a library and load directly into a prompt
source3 = prompter.add_source_new_query(my_lib, query="my new query", query_type="semantic", result_count=15)

#   to run inference with 'prompt with sources'
responses = prompter.prompt_with_source("my query")

#   to run fact-checks - post inference
fact_check = prompter.evidence_check_sources(responses)

#   to view source materials (batched 'model-ready' and attached to prompt)
source_materials = prompter.review_sources_summary()

#   to see the full prompt history
prompt_history = prompter.get_current_history()
RAG-Optimized Models - 1-7B parameter models designed for RAG workflow integration and running locally.
""" This 'Hello World' example demonstrates how to get started using local BLING models with provided context """

import time
from llmware.prompts import Prompt


def hello_world_questions():

    test_list = [

    {"query": "What is the total amount of the invoice?",
     "answer": "$22,500.00",
     "context": "Services Vendor Inc. \n100 Elm Street Pleasantville, NY \nTO Alpha Inc. 5900 1st Street "
                "Los Angeles, CA \nDescription Front End Engineering Service $5000.00 \n Back End Engineering"
                " Service $7500.00 \n Quality Assurance Manager $10,000.00 \n Total Amount $22,500.00 \n"
                "Make all checks payable to Services Vendor Inc. Payment is due within 30 days."
                "If you have any questions concerning this invoice, contact Bia Hermes. "
                "THANK YOU FOR YOUR BUSINESS!  INVOICE INVOICE # 0001 DATE 01/01/2022 FOR Alpha Project P.O. # 1000"},

    {"query": "What was the amount of the trade surplus?",
     "answer": "62.4 billion yen ($416.6 million)",
     "context": "Japan’s September trade balance swings into surplus, surprising expectations"
                "Japan recorded a trade surplus of 62.4 billion yen ($416.6 million) for September, "
                "beating expectations from economists polled by Reuters for a trade deficit of 42.5 "
                "billion yen. Data from Japan’s customs agency revealed that exports in September "
                "increased 4.3% year on year, while imports slid 16.3% compared to the same period "
                "last year. According to FactSet, exports to Asia fell for the ninth straight month, "
                "which reflected ongoing China weakness. Exports were supported by shipments to "
                "Western markets, FactSet added. — Lim Hui Jie"},

    {"query": "When did the LISP machine market collapse?",
     "answer": "1987.",
     "context": "The attendees became the leaders of AI research in the 1960s."
                "  They and their students produced programs that the press described as 'astonishing': "
                "computers were learning checkers strategies, solving word problems in algebra, "
                "proving logical theorems and speaking English.  By the middle of the 1960s, research in "
                "the U.S. was heavily funded by the Department of Defense and laboratories had been "
                "established around the world. Herbert Simon predicted, 'machines will be capable, "
                "within twenty years, of doing any work a man can do'.  Marvin Minsky agreed, writing, "
                "'within a generation ... the problem of creating 'artificial intelligence' will "
                "substantially be solved'. They had, however, underestimated the difficulty of the problem.  "
                "Both the U.S. and British governments cut off exploratory research in response "
                "to the criticism of Sir James Lighthill and ongoing pressure from the US Congress "
                "to fund more productive projects. Minsky's and Papert's book Perceptrons was understood "
                "as proving that artificial neural networks approach would never be useful for solving "
                "real-world tasks, thus discrediting the approach altogether.  The 'AI winter', a period "
                "when obtaining funding for AI projects was difficult, followed.  In the early 1980s, "
                "AI research was revived by the commercial success of expert systems, a form of AI "
                "program that simulated the knowledge and analytical skills of human experts. By 1985, "
                "the market for AI had reached over a billion dollars. At the same time, Japan's fifth "
                "generation computer project inspired the U.S. and British governments to restore funding "
                "for academic research. However, beginning with the collapse of the Lisp Machine market "
                "in 1987, AI once again fell into disrepute, and a second, longer-lasting winter began."},

    {"query": "What is the current rate on 10-year treasuries?",
     "answer": "4.58%",
     "context": "Stocks rallied Friday even after the release of stronger-than-expected U.S. jobs data "
                "and a major increase in Treasury yields.  The Dow Jones Industrial Average gained 195.12 points, "
                "or 0.76%, to close at 31,419.58. The S&P 500 added 1.59% at 4,008.50. The tech-heavy "
                "Nasdaq Composite rose 1.35%, closing at 12,299.68. The U.S. economy added 438,000 jobs in "
                "August, the Labor Department said. Economists polled by Dow Jones expected 273,000 "
                "jobs. However, wages rose less than expected last month.  Stocks posted a stunning "
                "turnaround on Friday, after initially falling on the stronger-than-expected jobs report. "
                "At its session low, the Dow had fallen as much as 198 points; it surged by more than "
                "500 points at the height of the rally. The Nasdaq and the S&P 500 slid by 0.8% during "
                "their lowest points in the day.  Traders were unclear of the reason for the intraday "
                "reversal. Some noted it could be the softer wage number in the jobs report that made "
                "investors rethink their earlier bearish stance. Others noted the pullback in yields from "
                "the day’s highs. Part of the rally may just be to do a market that had gotten extremely "
                "oversold with the S&P 500 at one point this week down more than 9% from its high earlier "
                "this year.  Yields initially surged after the report, with the 10-year Treasury rate trading "
                "near its highest level in 14 years. The benchmark rate later eased from those levels, but "
                "was still up around 6 basis points at 4.58%.  'We’re seeing a little bit of a give back "
                "in yields from where we were around 4.8%. [With] them pulling back a bit, I think that’s "
                "helping the stock market,' said Margaret Jones, chief investment officer at Vibrant Industries "
                "Capital Advisors. 'We’ve had a lot of weakness in the market in recent weeks, and potentially "
                "some oversold conditions.'"},

    {"query": "Is the expected gross margin greater than 70%?",
     "answer": "Yes, between 71.5% and 72.%",
     "context": "Outlook NVIDIA’s outlook for the third quarter of fiscal 2024 is as follows:"
                "Revenue is expected to be $16.00 billion, plus or minus 2%. GAAP and non-GAAP "
                "gross margins are expected to be 71.5% and 72.5%, respectively, plus or minus "
                "50 basis points.  GAAP and non-GAAP operating expenses are expected to be "
                "approximately $2.95 billion and $2.00 billion, respectively.  GAAP and non-GAAP "
                "other income and expense are expected to be an income of approximately $100 "
                "million, excluding gains and losses from non-affiliated investments. GAAP and "
                "non-GAAP tax rates are expected to be 14.5%, plus or minus 1%, excluding any discrete items."
                "Highlights NVIDIA achieved progress since its previous earnings announcement "
                "in these areas:  Data Center Second-quarter revenue was a record $10.32 billion, "
                "up 141% from the previous quarter and up 171% from a year ago. Announced that the "
                "NVIDIA® GH200 Grace™ Hopper™ Superchip for complex AI and HPC workloads is shipping "
                "this quarter, with a second-generation version with HBM3e memory expected to ship "
                "in Q2 of calendar 2024. "},

    {"query": "What is Bank of America's rating on Target?",
     "answer": "Buy",
     "context": "Here are some of the tickers on my radar for Thursday, Oct. 12, taken directly from "
                "my reporter’s notebook: It’s the one-year anniversary of the S&P 500′s bear market bottom "
                "of 3,577. Since then, as of Wednesday’s close of 4,376, the broad market index "
                "soared more than 22%.  Hotter than expected September consumer price index, consumer "
                "inflation. The Social Security Administration issues announced a 3.2% cost-of-living "
                "adjustment for 2024.  Chipotle Mexican Grill (CMG) plans price increases. Pricing power. "
                "Cites consumer price index showing sticky retail inflation for the fourth time "
                "in two years. Bank of America upgrades Target (TGT) to buy from neutral. Cites "
                "risk/reward from depressed levels. Traffic could improve. Gross margin upside. "
                "Merchandising better. Freight and transportation better. Target to report quarter "
                "next month. In retail, the CNBC Investing Club portfolio owns TJX Companies (TJX), "
                "the off-price juggernaut behind T.J. Maxx, Marshalls and HomeGoods. Goldman Sachs "
                "tactical buy trades on Club names Wells Fargo (WFC), which reports quarter Friday, "
                "Humana (HUM) and Nvidia (NVDA). BofA initiates Snowflake (SNOW) with a buy rating."
                "If you like this story, sign up for Jim Cramer’s Top 10 Morning Thoughts on the "
                "Market email newsletter for free. Barclays cuts price targets on consumer products: "
                "UTZ Brands (UTZ) to $16 per share from $17. Kraft Heinz (KHC) to $36 per share from "
                "$38. Cyclical drag. J.M. Smucker (SJM) to $129 from $160. Secular headwinds. "
                "Coca-Cola (KO) to $59 from $70. Barclays cut PTs on housing-related stocks: Toll Brothers"
                "(TOL) to $74 per share from $82. Keeps underweight. Lowers Trex (TREX) and Azek"
                "(AZEK), too. Goldman Sachs (GS) announces sale of fintech platform and warns on "
                "third quarter of 19-cent per share drag on earnings. The buyer: investors led by "
                "private equity firm Sixth Street. Exiting a mistake. Rise in consumer engagement for "
                "Spotify (SPOT), says Morgan Stanley. The analysts hike price target to $190 per share "
                "from $185. Keeps overweight (buy) rating. JPMorgan loves elf Beauty (ELF). Keeps "
                "overweight (buy) rating but lowers price target to $139 per share from $150. "
                "Sees “still challenging” environment into third-quarter print. The Club owns shares "
                "in high-end beauty company Estee Lauder (EL). Barclays upgrades First Solar (FSLR) "
                "to overweight from equal weight (buy from hold) but lowers price target to $224 per "
                "share from $230. Risk reward upgrade. Best visibility of utility scale names."},

    {"query": "What was the rate of decline in 3rd quarter sales?",
     "answer": "20% year-on-year.",
     "context": "Nokia said it would cut up to 14,000 jobs as part of a cost cutting plan following "
                "third quarter earnings that plunged. The Finnish telecommunications giant said that "
                "it will reduce its cost base and increase operation efficiency to “address the "
                "challenging market environment. The substantial layoffs come after Nokia reported "
                "third-quarter net sales declined 20% year-on-year to 4.98 billion euros. Profit over "
                "the period plunged by 69% year-on-year to 133 million euros."},

    {"query": "What is a list of the key points?",
     "answer": "•Stocks rallied on Friday with stronger-than-expected U.S jobs data and increase in "
               "Treasury yields;\n•Dow Jones gained 195.12 points;\n•S&P 500 added 1.59%;\n•Nasdaq Composite rose "
               "1.35%;\n•U.S. economy added 438,000 jobs in August, better than the 273,000 expected;\n"
               "•10-year Treasury rate trading near the highest level in 14 years at 4.58%.",
     "context": "Stocks rallied Friday even after the release of stronger-than-expected U.S. jobs data "
               "and a major increase in Treasury yields.  The Dow Jones Industrial Average gained 195.12 points, "
               "or 0.76%, to close at 31,419.58. The S&P 500 added 1.59% at 4,008.50. The tech-heavy "
               "Nasdaq Composite rose 1.35%, closing at 12,299.68. The U.S. economy added 438,000 jobs in "
               "August, the Labor Department said. Economists polled by Dow Jones expected 273,000 "
               "jobs. However, wages rose less than expected last month.  Stocks posted a stunning "
               "turnaround on Friday, after initially falling on the stronger-than-expected jobs report. "
               "At its session low, the Dow had fallen as much as 198 points; it surged by more than "
               "500 points at the height of the rally. The Nasdaq and the S&P 500 slid by 0.8% during "
               "their lowest points in the day.  Traders were unclear of the reason for the intraday "
               "reversal. Some noted it could be the softer wage number in the jobs report that made "
               "investors rethink their earlier bearish stance. Others noted the pullback in yields from "
               "the day’s highs. Part of the rally may just be to do a market that had gotten extremely "
               "oversold with the S&P 500 at one point this week down more than 9% from its high earlier "
               "this year.  Yields initially surged after the report, with the 10-year Treasury rate trading "
               "near its highest level in 14 years. The benchmark rate later eased from those levels, but "
               "was still up around 6 basis points at 4.58%.  'We’re seeing a little bit of a give back "
               "in yields from where we were around 4.8%. [With] them pulling back a bit, I think that’s "
               "helping the stock market,' said Margaret Jones, chief investment officer at Vibrant Industries "
               "Capital Advisors. 'We’ve had a lot of weakness in the market in recent weeks, and potentially "
               "some oversold conditions.'"}

    ]

    return test_list


# this is the main script to be run

def bling_meets_llmware_hello_world (model_name):

    t0 = time.time()

    # load the questions
    test_list = hello_world_questions()

    print(f"\n > Loading Model: {model_name}...")

    # load the model 
    prompter = Prompt().load_model(model_name)

    t1 = time.time()
    print(f"\n > Model {model_name} load time: {t1-t0} seconds")
 
    for i, entries in enumerate(test_list):

        print(f"\n{i+1}. Query: {entries['query']}")
     
        # run the prompt
        output = prompter.prompt_main(entries["query"],context=entries["context"]
                                      , prompt_name="default_with_context",temperature=0.30)

        # print out the results
        llm_response = output["llm_response"].strip("\n")
        print(f"LLM Response: {llm_response}")
        print(f"Gold Answer: {entries['answer']}")
        print(f"LLM Usage: {output['usage']}")

    t2 = time.time()

    print(f"\nTotal processing time: {t2-t1} seconds")

    return 0


if __name__ == "__main__":

    # list of 'rag-instruct' laptop-ready small bling models on HuggingFace

    model_list = ["llmware/bling-1b-0.1",                    #  fastest + most popular
                  "llmware/bling-tiny-llama-v0",             #  *** newest ***
                  "llmware/bling-1.4b-0.1",
                  "llmware/bling-falcon-1b-0.1",
                  "llmware/bling-cerebras-1.3b-0.1",
                  "llmware/bling-sheared-llama-1.3b-0.1",    
                  "llmware/bling-sheared-llama-2.7b-0.1",
                  "llmware/bling-red-pajamas-3b-0.1",
                  "llmware/bling-stable-lm-3b-4e1t-v0"        # most accurate
                  ]

    #  dragon models are 6-7B and designed for GPU use - but the GGUF versions run nicely on a laptop with at least 16 GB of RAM
    gguf_models = ["llmware/dragon-yi-6b-gguf", "llmware/dragon-llama-7b-gguf", "llmware/dragon-mistral-7b-gguf"]

    #   try the newest bling model - 'tiny-llama' or load a gguf model
    bling_meets_llmware_hello_world(model_list[1])

    #   check out the model card on Huggingface for RAG benchmark test performance results and other useful information
Simple-to-Scale Database Options - integrated data stores from laptop to parallelized cluster.
from llmware.configs import LLMWareConfig

#   to set the collection database - mongo, sqlite, postgres
LLMWareConfig().set_active_db("mongo")

#   to set the vector database (or declare when installing)
#   --options: milvus, pg_vector (postgres), redis, qdrant, faiss, pinecone, mongo atlas
LLMWareConfig().set_vector_db("milvus")

#   for fast start - no installations required
LLMWareConfig().set_active_db("sqlite")
LLMWareConfig().set_vector_db("faiss")

#   for single postgres deployment
LLMWareConfig().set_active_db("postgres")
LLMWareConfig().set_vector_db("postgres")

#   to install mongo, milvus, postgres - see the docker-compose scripts as well as examples
🔥 Agents with Function Calls and SLIM Models 🔥
from llmware.agents import LLMfx

text = ("Tesla stock fell 8% in premarket trading after reporting fourth-quarter revenue and profit that "
        "missed analysts’ estimates. The electric vehicle company also warned that vehicle volume growth in "
        "2024 'may be notably lower' than last year’s growth rate. Automotive revenue, meanwhile, increased "
        "just 1% from a year earlier, partly because the EVs were selling for less than they had in the past. "
        "Tesla implemented steep price cuts in the second half of the year around the world. In a Wednesday "
        "presentation, the company warned investors that it’s 'currently between two major growth waves.'")

#   create an agent using LLMfx class
agent = LLMfx()

#   load text to process
agent.load_work(text)

#   load 'models' as 'tools' to be used in analysis process
agent.load_tool("sentiment")
agent.load_tool("extract")
agent.load_tool("topics")
agent.load_tool("boolean")

#   run function calls using different tools
agent.sentiment()
agent.topics()
agent.extract(params=["company"])
agent.extract(params=["automotive revenue growth"])
agent.xsum()
agent.boolean(params=["is 2024 growth expected to be strong? (explain)"])

#   at end of processing, show the report that was automatically aggregated by key
report = agent.show_report()

#   displays a summary of the activity in the process
activity_summary = agent.activity_summary()

#   list of the responses gathered
for i, entries in enumerate(agent.response_list):
    print("update: response analysis: ", i, entries)

output = {"report": report, "activity_summary": activity_summary, "journal": agent.journal}  
🚀 Start coding - Quick Start for RAG 🚀
# This example illustrates a simple contract analysis
# using a RAG-optimized LLM running locally

import os
import re
from llmware.prompts import Prompt, HumanInTheLoop
from llmware.setup import Setup
from llmware.configs import LLMWareConfig

def contract_analysis_on_laptop (model_name):

    #  In this scenario, we will:
    #  -- download a set of sample contract files
    #  -- create a Prompt and load a BLING LLM model
    #  -- parse each contract, extract the relevant passages, and pass questions to a local LLM

    #  Main loop - Iterate thru each contract:
    #
    #      1.  parse the document in memory (convert from PDF file into text chunks with metadata)
    #      2.  filter the parsed text chunks with a "topic" (e.g., "governing law") to extract relevant passages
    #      3.  package and assemble the text chunks into a model-ready context
    #      4.  ask three key questions for each contract to the LLM
    #      5.  print to the screen
    #      6.  save the results in both json and csv for furthe processing and review.

    #  Load the llmware sample files

    print (f"\n > Loading the llmware sample files...")

    sample_files_path = Setup().load_sample_files()
    contracts_path = os.path.join(sample_files_path,"Agreements")
 
    #  Query list - these are the 3 main topics and questions that we would like the LLM to analyze for each contract

    query_list = {"executive employment agreement": "What are the name of the two parties?",
                  "base salary": "What is the executive's base salary?",
                  "governing law": "What is the governing law?"}

    #  Load the selected model by name that was passed into the function

    print (f"\n > Loading model {model_name}...")

    prompter = Prompt().load_model(model_name)

    #  Main loop

    for i, contract in enumerate(os.listdir(contracts_path)):

        #   excluding Mac file artifact (annoying, but fact of life in demos)
        if contract != ".DS_Store":

            print("\nAnalyzing contract: ", str(i+1), contract)

            print("LLM Responses:")

            for key, value in query_list.items():

                # step 1 + 2 + 3 above - contract is parsed, text-chunked, filtered by topic key,
                # ... and then packaged into the prompt

                source = prompter.add_source_document(contracts_path, contract, query=key)

                # step 4 above - calling the LLM with 'source' information already packaged into the prompt

                responses = prompter.prompt_with_source(value, prompt_name="just_the_facts", temperature=0.3)

                # step 5 above - print out to screen

                for r, response in enumerate(responses):
                    print(key, ":", re.sub("[\n]"," ", response["llm_response"]).strip())

                # We're done with this contract, clear the source from the prompt
                prompter.clear_source_materials()

    # step 6 above - saving the analysis to jsonl and csv

    # Save jsonl report to jsonl to /prompt_history folder
    print("\nPrompt state saved at: ", os.path.join(LLMWareConfig.get_prompt_path(),prompter.prompt_id))
    prompter.save_state()

    # Save csv report that includes the model, response, prompt, and evidence for human-in-the-loop review
    csv_output = HumanInTheLoop(prompter).export_current_interaction_to_csv()
    print("csv output saved at:  ", csv_output)


if __name__ == "__main__":

    # use local cpu model - smallest, fastest (use larger BLING models for higher accuracy)
    model = "llmware/bling-tiny-llama-v0"

    contract_analysis_on_laptop(model)

🔥 What's New? 🔥

-Small, specialized, function-calling Extract Model - introducing slim-extract - video and example

-LLM to Answer Yes/No questions - introducing slim-boolean model - video and example

-Natural Language Query to CSV End to End example - using slim-sql model - video and example

-Multi-Model Agents with SLIM models - multi-step Agents with SLIMs on CPU - video - example

-OCR Embedded Document Images Example - (example)

-Enhanced Parser Functions for PDF, Word, Powerpoint and Excel - new text-chunking controls and strategies, extract tables, images, header text - (example)

-Fast start with no db installation - SQLite (text collection) and FAISS (vector file database) - example

-Postgres integration as option for text collection with PGVector support (example)

-GGUF support - check out examples - GGUF (example) and Videos video

🌱 Getting Started

Step 1 - Install llmware - pip3 install llmware

Step 2- Go to Examples - Get Started Fast with 100+ 'Cut-and-Paste' Recipes

🔥 Top New Examples 🔥

End-to-End Scenario - Function Calls with SLIM Extract and Web Services for Financial Research
New to LLMWare - Fast Start tutorial series
SLIM Examples - SLIM Models

Example Detail
1. BLING models fast start (code / video) Get started with fast, accurate, CPU-based models - question-answering, key-value extraction, and basic summarization.
2. Parse and Embed 500 PDF Documents (code) End-to-end example for Parsing, Embedding and Querying UN Resolution documents with Milvus
3. Hybrid Retrieval - Semantic + Text (code) Using 'dual pass' retrieval to combine best of semantic and text search
4. Multiple Embeddings with PG Vector (code / video) Comparing Multiple Embedding Models using Postgres / PG Vector
5. DRAGON GGUF Models (code / video) State-of-the-Art 7B RAG GGUF Models.
6. RAG with BLING (code / video) Using contract analysis as an example, experiment with RAG for complex document analysis and text extraction using llmware's BLING ~1B parameter GPT model running on your laptop.
7. Master Service Agreement Analysis with DRAGON (code / video) Analyzing MSAs using DRAGON YI 6B Model.
8. Streamlit Example (code) Upload pdfs, and run inference on llmware BLING models.
9. Integrating LM Studio (code / video) Integrating LM Studio Models with LLMWare
10. Prompts With Sources (code) Attach wide range of knowledge sources directly into Prompts.
11. Fact Checking (code) Explore the full set of evidence methods in this example script that analyzes a set of contracts.
12. Using 7B GGUF Chat Models (code) Using 4 state of the art 7B chat models in minutes running locally

Check out: llmware examples

Step 3 - Tutorial Videos - check out our Youtube channel for high-impact 5-10 minute tutorials on the latest examples.

🎬 Check out these videos to get started quickly:

Data Store Options

Fast Start: use SQLite3 and FAISS out-of-the-box - no install required
from llmware.configs import LLMWareConfig 
LLMWareConfig().set_active_db("sqlite")   
LLMWareConfig().set_vector_db("faiss")
Speed + Scale: use MongoDB (text collection) and Milvus (vector db) - install with Docker Compose
curl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose.yaml
docker compose up -d
from llmware.configs import LLMWareConfig
LLMWareConfig().set_active_db("mongo")
LLMWareConfig().set_vector_db("milvus")
Postgres: use Postgres for both text collection and vector DB - install with Docker Compose
curl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose-pgvector.yaml
docker compose up -d
from llmware.configs import LLMWareConfig
LLMWareConfig().set_active_db("postgres")
LLMWareConfig().set_vector_db("postgres")
Mix-and-Match: LLMWare supports 3 text collection databases (Mongo, Postgres, SQLite) and 10 vector databases (Milvus, PGVector-Postgres, Neo4j, Redis, Mongo-Atlas, Qdrant, Faiss, LanceDB, ChromaDB and Pinecone)
# scripts to deploy other options
curl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose-redis-stack.yaml

Meet our Models

  • SLIM model series: small, specialized models fine-tuned for function calling and multi-step, multi-model Agent workflows.
  • DRAGON model series: Production-grade RAG-optimized 6-7B parameter models - "Delivering RAG on ..." the leading foundation base models.
  • BLING model series: Small CPU-based RAG-optimized, instruct-following 1B-3B parameter models.
  • Industry BERT models: out-of-the-box custom trained sentence transformer embedding models fine-tuned for the following industries: Insurance, Contracts, Asset Management, SEC.
  • GGUF Quantization: we provide 'gguf' and 'tool' versions of many SLIM, DRAGON and BLING models, optimized for CPU deployment.

Using LLMs and setting-up API keys & secrets

LLMWare is an open platform and supports a wide range of open source and proprietary models. To use LLMWare, you do not need to use any proprietary LLM - we would encourage you to experiment with SLIM, BLING, DRAGON, Industry-BERT, the GGUF examples, along with bringing in your favorite models from HuggingFace and Sentence Transformers.

If you would like to use a proprietary model, you will need to provide your own API Keys. API keys and secrets for models, aws, and pinecone can be set-up for use in environment variables or passed directly to method calls.

✍️ Working with the llmware Github repository

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 [email protected]:llmware-ai/llmware.git
Roadmap - Where are we going ...
  • 💡 Making it easy to deploy fine-tuned open source models to build state-of-the-art RAG workflows
  • 💡 Private cloud - keeping documents, data pipelines, data stores, and models safe and secure
  • 💡 Model quantization, especially GGUF, and democratizing the game-changing use of 7B CPU-based LLMs
  • 💡 Developing small specialized RAG optimized LLMs between 1B-7B parameters
  • 💡 Industry-specific LLMs, embedding models and processes to support core knowledge-based use cases
  • 💡 Enterprise scalability - containerization, worker deployments and Kubernetes
  • 💡 Integration of SQL and other scale enterprise data sources
  • 💡 Multi-step, multi-model Agent-based workflows with small, specialized function-calling models
  • 💡 New Documentation - Coming Soon

Like our models, we aspire for llmware to be "small, but mighty" - easy to use and get started, but packing a powerful punch!

Interested in contributing to llmware? 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.

Questions and discussions are welcome in our github discussions.

📣 Release notes and Change Log

Thursday, April 25 - v0.2.11-WIP Update

  • Updates to gguf libs for Phi-3 and Llama-3
  • Added Phi-3 and Llama-3 and Quantized Versions to Model Catalog
  • Integrated WhisperCPP Model class and prebuilt shared libraries
  • Changes being merged into the main branch with PyPy build targeted for the weekend

Monday, April 22 - v0.2.10 Update

  • Updates to Agent class to support Natural Language queries of Custom Tables on Postgres example
  • New Agent API endpoint implemented with LLMWare Inference Server and new Agent capabilities example

Tuesday, April 16 - v0.2.9 Update

  • New CustomTable class to rapidly create custom DB tables in conjunction with LLM-based workflows.
  • Enhanced methods for converting CSV and JSON/JSONL files into DB tables.
  • See new examples Creating Custom Table example

Tuesday, April 9 - v0.2.8 Update

  • Office Parser (Word Docx, Powerpoint PPTX, and Excel XLSX) - multiple improvements - new libs + Python method.
  • Includes: several fixes, improved text chunking controls, header text extraction and configuration options.
  • Generally, new office parser options conform with the new PDF parser options.
  • Please see Office Parsing Configs example

Wednesday, April 3 - v0.2.7 Update

  • PDF Parser - multiple improvements - new libs + Python methods.
  • Includes: UTF-8 encoding for European languages.
  • Includes: Better text chunking controls, header text extraction and configuration options.
  • Please see PDF Parsing Configs example for more details.
  • Note: deprecating support for aarch64-linux (will use 0.2.6 parsers). Full support going forward for Linux Ubuntu20+ on x86_64 + with CUDA.

Friday, March 22 - v0.2.6 Update

  • New SLIM models: summary, extract, xsum, boolean, tags-3b, and combo sentiment-ner.
  • New logit and sampling analytics.
  • New SLIM examples showing how to use the new models.

Thursday, March 14 - v0.2.5 Update

  • Improved support for GGUF on CUDA (Windows and Linux), with new prebuilt binaries and exception handling.
  • Enhanced model configuration options (sampling, temperature, top logit capture).
  • Added full back-level support for Ubuntu 20+ with parsers and GGUF engine.
  • Support for new Anthropic Claude 3 models.
  • New retrieval methods: document_lookup and aggregate_text.
  • New model: bling-stablelm-3b-tool - fast, accurate 3b quantized question-answering model - one of our new favorites.

Wednesday, February 28 - v0.2.4 Update

  • Major upgrade of GGUF Generative Model class - support for Stable-LM-3B, CUDA build options, and better control over sampling strategies.
  • Note: new GGUF llama.cpp built libs packaged with build starting in v0.2.4.
  • Improved GPU support for HF Embedding Models.

Friday, February 16 - v0.2.3 Update

  • Added 10+ embedding models to ModelCatalog - nomic, jina, bge, gte, ember and uae-large.
  • Updated OpenAI support >=1.0 and new text-3 embedding models.
  • SLIM model keys and output_values now accessible in ModelCatalog.
  • Updating encodings to 'utf-8-sig' to better handle txt/csv files with bom.

Reported notable issues on priority resolution path

  • older linux versions with GLIBC < 2.31
  • 3.12 python support - waiting on one last dependency (coming soon)

Supported Operating Systems: MacOS (Metal and x86), Linux (x86 and aarch64), Windows

  • note on Linux: we test most extensively on Ubuntu 22 and now Ubuntu 20 and recommend where possible
  • if you need another Linux version, please raise an issue - we will prioritize testing and ensure support.

Supported Vector Databases: Milvus, Postgres (PGVector), Neo4j, Redis, LanceDB, ChromaDB, Qdrant, FAISS, Pinecone, Mongo Atlas Vector Search

Supported Text Index Databases: MongoDB, Postgres, SQLite

Optional
🚧 Change Log

Latest Updates - 19 Jan 2024 - llmware v0.2.0

  • Added new database integration options - Postgres and SQlite
  • Improved status update and parser event logging options for parallelized parsing
  • Significant enhancements to interactions between Embedding + Text collection databases
  • Improved error exception handling in loading dynamic modules

Latest Updates - 15 Jan 2024: llmware v0.1.15

  • Enhancements to dual pass retrieval queries
  • Expanded configuration objects and options for endpoint resources

Latest Updates - 30 Dec 2023: llmware v0.1.14

  • Added support for Open Chat inference servers (compatible with OpenAI API)
  • Improved capabilities for multiple embedding models and vector DB configurations
  • Added docker-compose install scripts for PGVector and Redis vector databases
  • Added 'bling-tiny-llama' to model catalog

Latest Updates - 22 Dec 2023: llmware v0.1.13

  • Added 3 new vector databases - Postgres (PG Vector), Redis, and Qdrant

  • Improved support for integrating sentence transformers directly in the model catalog

  • Improvements in the model catalog attributes

  • Multiple new Examples in Models & Embeddings, including GGUF, Vector database, and model catalog

  • 17 Dec 2023: llmware v0.1.12

    • dragon-deci-7b added to catalog - RAG-finetuned model on high-performance new 7B model base from Deci
    • New GGUFGenerativeModel class for easy integration of GGUF Models
    • Adding prebuilt llama_cpp / ctransformer shared libraries for Mac M1, Mac x86, Linux x86 and Windows
    • 3 DRAGON models packaged as Q4_K_M GGUF models for CPU laptop use (dragon-mistral-7b, dragon-llama-7b, dragon-yi-6b)
    • 4 leading open source chat models added to default catalog with Q4_K_M
  • 8 Dec 2023: llmware v0.1.11

    • New fast start examples for high volume Document Ingestion and Embeddings with Milvus.
    • New LLMWare 'Pop up' Inference Server model class and example script.
    • New Invoice Processing example for RAG.
    • Improved Windows stack management to support parsing larger documents.
    • Enhancing debugging log output mode options for PDF and Office parsers.
  • 30 Nov 2023: llmware v0.1.10

    • Windows added as a supported operating system.
    • Further enhancements to native code for stack management.
    • Minor defect fixes.
  • 24 Nov 2023: llmware v0.1.9

    • Markdown (.md) files are now parsed and treated as text files.
    • PDF and Office parser stack optimizations which should avoid the need to set ulimit -s.
    • New llmware_models_fast_start.py example that allows discovery and selection of all llmware HuggingFace models.
    • Native dependencies (shared libraries and dependencies) now included in repo to faciliate local development.
    • Updates to the Status class to support PDF and Office document parsing status updates.
    • Minor defect fixes including image block handling in library exports.
  • 17 Nov 2023: llmware v0.1.8

    • Enhanced generation performance by allowing each model to specific the trailing space parameter.
    • Improved handling for eos_token_id for llama2 and mistral.
    • Improved support for Hugging Face dynamic loading
    • New examples with the new llmware DRAGON models.
  • 14 Nov 2023: llmware v0.1.7

    • Moved to Python Wheel package format for PyPi distribution to provide seamless installation of native dependencies on all supported platforms.
    • ModelCatalog enhancements:
      • OpenAI update to include newly announced ‘turbo’ 4 and 3.5 models.
      • Cohere embedding v3 update to include new Cohere embedding models.
      • BLING models as out-of-the-box registered options in the catalog. They can be instantiated like any other model, even without the “hf=True” flag.
      • Ability to register new model names, within existing model classes, with the register method in ModelCatalog.
    • Prompt enhancements:
      • “evidence_metadata” added to prompt_main output dictionaries allowing prompt_main responses to be plug into the evidence and fact-checking steps without modification.
      • API key can now be passed directly in a prompt.load_model(model_name, api_key = “[my-api-key]”)
    • LLMWareInference Server - Initial delivery:
      • New Class for LLMWareModel which is a wrapper on a custom HF-style API-based model.
      • LLMWareInferenceServer is a new class that can be instantiated on a remote (GPU) server to create a testing API-server that can be integrated into any Prompt workflow.
  • 03 Nov 2023: llmware v0.1.6

    • Updated packaging to require mongo-c-driver 1.24.4 to temporarily workaround segmentation fault with mongo-c-driver 1.25.
    • Updates in python code needed in anticipation of future Windows support.
  • 27 Oct 2023: llmware v0.1.5

    • Four new example scripts focused on RAG workflows with small, fine-tuned instruct models that run on a laptop (llmware BLING models).
    • Expanded options for setting temperature inside a prompt class.
    • Improvement in post processing of Hugging Face model generation.
    • Streamlined loading of Hugging Face generative models into prompts.
    • Initial delivery of a central status class: read/write of embedding status with a consistent interface for callers.
    • Enhanced in-memory dictionary search support for multi-key queries.
    • Removed trailing space in human-bot wrapping to improve generation quality in some fine-tuned models.
    • Minor defect fixes, updated test scripts, and version update for Werkzeug to address dependency security alert.
  • 20 Oct 2023: llmware v0.1.4

    • GPU support for Hugging Face models.
    • Defect fixes and additional test scripts.
  • 13 Oct 2023: llmware v0.1.3

    • MongoDB Atlas Vector Search support.
    • Support for authentication using a MongoDB connection string.
    • Document summarization methods.
    • Improvements in capturing the model context window automatically and passing changes in the expected output length.
    • Dataset card and description with lookup by name.
    • Processing time added to model inference usage dictionary.
    • Additional test scripts, examples, and defect fixes.
  • 06 Oct 2023: llmware v0.1.1

    • Added test scripts to the github repository for regression testing.
    • Minor defect fixes and version update of Pillow to address dependency security alert.
  • 02 Oct 2023: llmware v0.1.0 🔥 Initial release of llmware to open source!! 🔥

llmware's People

Contributors

a-kapoor avatar abhineshjha avatar alexanderivory avatar anush008 avatar chair300 avatar doberst avatar drewskidang avatar jessberl avatar johncharrington avatar macos avatar nydocutest avatar osi1880vr avatar philipkd avatar raghavdixit99 avatar sevask avatar shneeba avatar turnham avatar ucekmez avatar virunew avatar xocolatl-aficionado avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

llmware's Issues

Vector DB: Add support for Cassandra

Expand Vector DB support to include Cassandra.

Milvus and Pinecone implementations in the embeddings.py can be used as a guide.

Scope includes:
Updating LLMWareConfig, EmbeddingHandler
Creating an Embedding class specific to Cassandra
Test scripts and example code

error while running Prompts\document_summarizer.py

  • error in document_summarizer.py

Traceback (most recent call last):
File "d:\home\john\Projects\llmware-main\examples\Prompts\document_summarizer.py", line 87, in
summary_library = test_summarize_document_from_library(llm_model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\home\john\Projects\llmware-main\examples\Prompts\document_summarizer.py", line 59, in test_summarize_document_from_library
summary = prompter.summarize_document_from_library(lib,filename=fn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\prompts.py", line 872, in summarize_document_from_library
output_text += entries["llm_response"] + "\n"
~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'llm_response'

I added the following check in prompts.py at line 870 on my system and it ran fine.
for i, entries in enumerate(response):
# print("update: summaries - ", i, entries)
if 'llm_response' in entries:
output_text += entries["llm_response"] + "\n"

John

Vector DB: Add support for Deep Lake

Expand Vector DB support to include Deep Lake.

Milvus and Pinecone implementations in the embeddings.py can be used as a guide.

Scope includes:
Updating LLMWareConfig, EmbeddingHandler
Creating an Embedding class specific to Deep Lake
Test scripts and example code

invoice_processing.py failed to write out CSV report

Hi, I ran example/invoice_processing.py on my Windows laptop,
it worked quite well, except failing to write out CSV report at the end

see error trace below.

Analyzing invoice:  41 zetq Simple Invoice .pdf
LLM Response -  What is the total amount of the invoice?  -   $330.00
LLM Response -  What is the invoice number?  -   #23.
LLM Response -  What are the names of the two parties?  -   Not Found.

update: prompt state saved at:  C:\Users\p2p2l\llmware_data\prompt_history\85735d4d-a542-4feb-9f7d-9f5faeef0406
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_5752\1846019278.py in <module>
----> 1 invoice_processing(run_on_cpu=True)

~\AppData\Local\Temp\ipykernel_5752\3297449807.py in invoice_processing(run_on_cpu)
     67 
     68     # Generate CSV report for easy Human review in Excel
---> 69     csv_output = HumanInTheLoop(prompter).export_current_interaction_to_csv()
     70 
     71     print("\nupdate: csv output for human review - ", csv_output)

c:\users\p2p2l\projects\gongwork\llmware\llmware\prompts.py in export_current_interaction_to_csv(self, output_path, report_name)
   1880         # this method will take the current interaction state and dump to csv ffor user to review and edit
   1881 
-> 1882         output = PromptState(self.prompt).generate_interaction_report_current_state(output_path=output_path,
   1883                                                                                     report_name=report_name)
   1884 

c:\users\p2p2l\projects\gongwork\llmware\llmware\resources.py in generate_interaction_report_current_state(self, output_path, report_name)
   1069         report_fp = os.path.join(output_path,report_name)
   1070 
-> 1071         with open(report_fp, 'w', encoding='utf-8', newline='') as csvfile:
   1072             c = csv.writer(csvfile, dialect='excel', doublequote=False, delimiter=',', escapechar=']')
   1073 

OSError: [Errno 22] Invalid argument: 'C:\\Users\\p2p2l\\llmware_data\\prompt_history\\interaction_report_Fri Dec  8 23:05:09 2023.csv'

I made a temp fix locally,

    def get_current_time_now (time_str="%a %b %e %H:%M:%S %Y"):
        if os.name == "nt": time_str="%Y-%m-%d_%H%M%S"
        return datetime.now().strftime(time_str)

Let me know if I should submit a fix PR

llmware always creates collection in 'default' vector database

It seems that currently the framework does not have option to provide own database name for vector database . All collections are created in 'default' database. This is an issue because if I run-tests.py, the 'default' database is cleared and all collections are deleted , this results in loss of all data. So we need an option for providing a non 'default' database name for vector database as a parameter while calling install_new_embeddings() function in embeddings.py

I have only used Milvus vector databse , which has this hierarchy of database->collection. not sure about other vector databases

remove .DS_Store from llmware_data\sample_files

Can you remove the .DS_Store file from the llmware_data\sample_files directories.
This is a file for mac directory instructions and chokes several examples when run on Windows platform.

I found 3 of them

  1. llmware_data\sample_files.DS_Store
  2. llmware_data\sample_files\Agreements.DS_Store
  3. llmware_data\sample_files\Invoices.DS_Store

Thanks,

John

How to interpret fact_check and comparaison stats ?

Hello,

I just ran dragon_rag_benchmark_tests_llmware.py, on llmware/dragon-red-pajama-7b-v0
I'm not sure how to interpret Fact Check stats and comparison stats.
->For some cases, Gold and LLM answers are equivalent but stats are low :

"12. llm_response - Delta Inc. and ABC Company
12. gold_answer - ABC Company and Delta Inc.
12. time_taken - 0.16
12. comparison_stats - {'percent_display': '66.7%', 'confirmed_words': ['delta', 'company'], 'unconfirmed_words': ['abc'], 'verified_token_match_ratio': 0.6666666666666666, 'key_point_list': [{'key_point': ' Delta Inc. and ABC Company', 'entry': 0, 'verified_match': 0.6666666666666666}]}
12. source - 0 {'text': 'Company 8675 River Run Road Marlington CT 09392 INVOICE TO Delta Inc 8723 Wilton Boulevard Los Angeles CA HEBE HERACLES\tLASER ', 'match_score': 0.75, 'source': 'NA', 'page_num': 'NA'}"

->For some cases Gold and LLM answers are not equivalent but stats are very high :

"54. llm_response - Section 18(a), which is governed by the laws of the State of Delaware.
54. gold_answer - Section 19
54. time_taken - 0.42
54. comparison_stats - {'percent_display': '100.0%', 'confirmed_words': ['section', '18a', 'governed', 'laws', 'state', 'delaware'], 'unconfirmed_words': [], 'verified_token_match_ratio': 1.0, 'key_point_list': [{'key_point': ' Section 18(a), which is governed by the laws of the State of Delaware.', 'entry': 0, 'verified_match': 1.0}]}
54. source - 0 {'text': 'and interpreted under the laws of the State of Massachusetts except with respect to Section 18(a) of this Agreement which ', 'match_score': 1.0, 'source': 'NA', 'page_num': 'NA'}"

"107. llm_response - Q2 of calendar 2024.
107. gold_answer - Not Found.
107. time_taken - 0.2
107. fact_check - 0 {'fact': '2024', 'status': 'Confirmed', 'text': ' ... Outlook NVIDIA??s outlook for the third quarter of fiscal 2024 is as follows:Revenue is expected to be $16.00 billion, ... ', 'page_num': 'NA', 'source': 'NA'}
107. comparison_stats - {'percent_display': '100.0%', 'confirmed_words': ['q2', 'calendar', '2024'], 'unconfirmed_words': [], 'verified_token_match_ratio': 1.0, 'key_point_list': [{'key_point': ' Q2 of calendar 2024.', 'entry': 0, 'verified_match': 1.0}]}
107. source - 0 {'text': 'a secondgeneration version with HBM3e memory expected to ship in Q2 of calendar 2024 ', 'match_score': 1.0, 'source': 'NA', 'page_num': 'NA'}

"
Also, i'm not sure to understand fact_check, In answer 107..
Maybe I'm missing something..

Local LLM could not connect

Hi, thank you for the wonderful this code. I have downloaded the model from huggingface but when i try to load from prompt load , I could not be able to load
Can you pls help me. I don't want to load model thru huggingface app key

Query about other LLM

Hello everyone !
I don't have chatgpt 4 api key
can I use other then chatgpt like. I want to use open source LLM like makersuit from google ?
I want to contribute in your project
Thanks

Install on Ubuntu 23.10

Howdy. This looks like a great program. I wish I could try and see, but I'm on ubuntu 23.10, and there's no easy way for me to install anything under python 3.11. I tried before contacting you - I tried hard - but I just couldn't find a way to install it. Is it absolutely necessary not to use python 3.11? I have that.

Thank you.

Vector DB: add support for Redis

Expand Vector DB support to include Redis.

Milvus and Pinecone implementations in the embeddings.py can be used as a guide.

Scope includes:
Updating LLMWareConfig, EmbeddingHandler
Creating an Embedding class specific to Redis
Test scripts and example code

Vector DB: Add support for Weaviate

Expand Vector DB support to include Weaviate.

Milvus and Pinecone implementations in the embeddings.py can be used as a guide.

Scope includes:
Updating LLMWareConfig, EmbeddingHandler
Creating an Embedding class specific to Weaviate
Test scripts and example code

Vector DB: Add support for Neo4j

Expand Vector DB support to include Neo4j.

Milvus and Pinecone implementations in the embeddings.py can be used as a guide.

Scope includes:
Updating LLMWareConfig, EmbeddingHandler
Creating an Embedding class specific to Neo4j
Test scripts and example code

Vector DB: Add support for Chroma

Expand Vector DB support to include Chroma.

Milvus and Pinecone implementations in the embeddings.py can be used as a guide.

Scope includes:
Updating LLMWareConfig, EmbeddingHandler
Creating an Embedding class specific to Chroma
Test scripts and example code

flash-attn is missing from v0.1.12 ?

Hi Darren,
after watching your YouTube demo this afternoon (https://www.youtube.com/watch?v=JNcwAkbsObE),
I tried to run dragon_rag_benchmark_tests_llmware.py script for model=llmware/dragon-deci-7b-v0 on my Ubuntu machine (with the latest __version__ = '0.1.12'),
like to report 2 issues:

  1. flash-attn pkg is missing from setup.py
  2. got error: torch.cuda.OutOfMemoryError: CUDA out of memory as my GPU has only 8188MiB RAM, but the model itself is 14.1G big. Then I tried model=llmware/dragon-deci-6b-v0, response is slower but no CUDA out-of-memory error.

Question: will llmware release quantized model to reduce memory footprint?
It would be great if llmware can consume Ollama.ai models (e.g. Mistral-7B model is around 4GB)

Thanks
Wen

Can't decode character in setup.py during pip install

I'm getting the following issue when trying to install on Python 3.9 and 3.10 with version 0.1.4 in pip

`pip install llmware
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Collecting llmware
Downloading llmware-0.1.4.tar.gz (608 kB)
---------------------------------------- 608.1/608.1 kB 2.9 MB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [8 lines of output]
Traceback (most recent call last):
File "", line 2, in
File "", line 34, in
File "C:\test\Local\Temp\pip-install-xvcskndt\llmware_f9aa6b83f25441099b7901721dfab793\setup.py", line 61, in
long_description = readme_file.read()
File "C:\test\anaconda3\envs\llmware\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 9174: character maps to
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.`

Directories not found under llmware_data on windows 11

I did a clean install of llmware 1.12 and there are some directories that are not created under llmware_data.
I am running python 3.11 with vs code.

Under examples\Getting_Started

  • getting_started_with_rag.py
  • Creating library 'Agreements'...
    Traceback (most recent call last):
    File "d:\home\john\Projects\llmware-main\examples\Getting_Started\getting_started_with_rag.py", line 55, in
    end_to_end_rag(model_name, vector_db="faiss")
    File "d:\home\john\Projects\llmware-main\examples\Getting_Started\getting_started_with_rag.py", line 18, in end_to_end_rag
    library.add_files(os.path.join(sample_files_path,"Agreements"))
    File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\library.py", line 357, in add_files
    parsing_results = Parser(library=self).ingest(input_folder_path,dupe_check=True)
    ^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\parsers.py", line 98, in init
    os.mkdir(parser_tmp_work_folder)
    FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\Users\jehol\llmware_data\tmp\parser_tmp\'

I created the directory llmware\tmp and reran the example and I got the following error

Generating CSV report...
Traceback (most recent call last):
File "d:\home\john\Projects\llmware-main\examples\Getting_Started\getting_started_with_rag.py", line 55, in
end_to_end_rag(model_name, vector_db="faiss")
File "d:\home\john\Projects\llmware-main\examples\Getting_Started\getting_started_with_rag.py", line 42, in end_to_end_rag
report_data = prompter.send_to_human_for_review()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\prompts.py", line 1028, in send_to_human_for_review
output = HumanInTheLoop(prompt=self).export_current_interaction_to_csv(output_path=output_path,report_name=output_fn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\prompts.py", line 1882, in export_current_interaction_to_csv
output = PromptState(self.prompt).generate_interaction_report_current_state(output_path=output_path,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\resources.py", line 1072, in generate_interaction_report_current_state
with open(report_fp, 'w', encoding='utf-8', newline='') as csvfile:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\jehol\llmware_data\prompt_history\interaction_report_2023-12-21_084950.csv'

i create the directory llmware_data\prompt_history manually re-ran the example and it completed successfully.

John

markdown file support

is library.add_files currently supporting md files?
with my folder of pdfs and markdown files it only displays the pdfs in library output

ERROR:root:error: to use prompt_with_source, there must be a loaded source - try '.add_sources' first

What is causing the below issue, I am not finding the method '.add_sources' in prompt object,
I am trying the following script, llmware/examples/Getting_Started$ python working_without_a_database.py
Analyzing disease-Sample file 3.pdf

/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(41)analyze_contracts_on_the_fly()
-> source = prompter.add_source_document(contracts_path, contract, query="Diseases")
(Pdb) c
ERROR:root:error: to use prompt_with_source, there must be a loaded source - try '.add_sources' first
Traceback (most recent call last):
File "/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py", line 317, in
analyze_contracts_on_the_fly(model_name)
File "/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py", line 48, in analyze_contracts_on_the_fly
print("LLM Response: " + response["llm_response"])
~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'llm_response'
(privategpt) appuser@ip-10-50-2-248:~/llama/RAG/llmware/examples/Getting_Started$ python working_without_a_database.py

Loading the llmware sample files...
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.

Analyzing contracts with prompt: 'What is the Diseases in the document?'
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(34)analyze_contracts_on_the_fly()
-> if contract != ".DS_Store":
(Pdb) n
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(64)analyze_contracts_on_the_fly()
-> prompter.save_state()
(Pdb) n
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(32)analyze_contracts_on_the_fly()
-> for i, contract in enumerate(os.listdir(contracts_path)):
(Pdb) n
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(33)analyze_contracts_on_the_fly()
-> import pdb;pdb.set_trace()
(Pdb) n
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(34)analyze_contracts_on_the_fly()
-> if contract != ".DS_Store":
(Pdb) n
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(36)analyze_contracts_on_the_fly()
-> print (f"\n > Analyzing {contract}")
(Pdb) n

Analyzing disease-Sample file 3.pdf
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(41)analyze_contracts_on_the_fly()
-> source = prompter.add_source_document(contracts_path, contract, query="Diseases")
(Pdb) n
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(46)analyze_contracts_on_the_fly()
-> responses = prompter.prompt_with_source(prompt_text, prompt_name="number_or_none")
(Pdb) n
ERROR:root:error: to use prompt_with_source, there must be a loaded source - try '.add_sources' first
/home/appuser/llama/RAG/llmware/examples/Getting_Started/working_without_a_database.py(47)analyze_contracts_on_the_fly()
-> import pdb;pdb.set_trace()
(Pdb)

segfault running rag.py

After watching the video I wanted to give it a go.

But was greeted with a segfault :(

 python examples/rag.py

 > Creating library 'Agreements'...
[1]    20130 segmentation fault  python examples/rag.py

I happens somewhere in the library.add_files(os.path.join(sample_files_path,"Agreements")) line.
tested with Python 3.9.18

NoSQL DB: Add support for Cassandra

Add support for Cassandra as the NoSQL storage for bloks, metadata and auditability.

Scope of work:
Update DBManager, CollectionRetrieval, CollectionWriter, LLMWareConfig
Test scripts, and example code

NoSQL DB: add support for DynamoDB

Add support for DynamoDB as the NoSQL storage for bloks, metadata and auditability.

Scope of work:
Update DBManager, CollectionRetrieval, CollectionWriter, LLMWareConfig
Test scripts, and example code

issue in installing the library in windows 10

ERROR: Command errored out with exit status 1:
command: 'C:\Users\Oxidi\Desktop\gripenv\grip\Scripts\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Oxidi\AppData\Local\Temp\pip-install-wem13w6j\llmware_6ec9b6a58481432da47e8b764fdae30f\setup.py'"'"'; file='"'"'C:\Users\Oxidi\AppData\Local\Temp\pip-install-wem13w6j\llmware_6ec9b6a58481432da47e8b764fdae30f\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Oxidi\AppData\Local\Temp\pip-pip-egg-info-a2fj_bmk'
cwd: C:\Users\Oxidi\AppData\Local\Temp\pip-install-wem13w6j\llmware_6ec9b6a58481432da47e8b764fdae30f
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Oxidi\AppData\Local\Temp\pip-install-wem13w6j\llmware_6ec9b6a58481432da47e8b764fdae30f\setup.py", line 61, in
long_description = readme_file.read()
File "C:\Users\Oxidi\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 8949: character maps to

Example 3 - Retrieval - perform_retrieval_with_document_filters - EmbeddingModelNotFoundException

Line 229 in examples/retrieval.py
perform_retrieval_with_document_filters(library=library, doc_filter_text="Agreement", query_text='Agreement')

This throws

llmware/retrieval.py", line 611, in semantic_query_with_document_filter
raise EmbeddingModelNotFoundException(self.library_name)
llmware.exceptions.EmbeddingModelNotFoundException: Embedding model for 'retrieval_tests' could not be located

All I can tell is that the embedding model is in 'library', which is being passed, AND the embedding model is passed directly in 'perform_retrieval_with_document_filters()', line 111, like this:

query = Query(library,from_sentence_transformer=True,embedding_model_name=embedding_model_name, embedding_model=embedding_model) 

After which 'query' is used to call the function, line 115:

semantic_results = query.semantic_query_with_document_filter(query_text, doc_filter, result_count=3)

And it errors there.

I think it has something to do with lines 92-122 in llmware/retrieval.py, inside Query. It has to do with embedding_record and a flag being set with matched_lib_model. Is embedding_record triggering that flag set to True or not? That flag in line 116 activates code that loads the embedding_model if it's not already set by calling load_embedding_model().

That's as far as I got along the possibility that the error is due to embedding_model not being set in Query when it should (I don't really know if it should. On to the next lead..)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I directly passed in the embedding model and assigned it to self inside llmware/retrieval.py Query.semantic_query_with_document_filter() so that it did not error, and the bit of code it hit instead tried to call embedding() on the embedding model, and I got this error:

AttributeError: 'SentenceTransformer' object has no attribute 'embedding'

So, this if-else block is either expecting an embedding model that has the 'embedding' attribute, or there's not supposed to be any embedding model, in which case the block is skipped along with it's error (that's the error that's the subject of all this), but either way, it throws some error. Another possibility is that a different embedding model that does have an 'embedding' attribute is expected to be passed into that function, but that doesn't seem plausible, because a SentenceTransformer is what's created for this series of example calls in examples/retrieval.py, lines 220-222:

embedding_model_name = "all-MiniLM-L6-v1"
print (f"Loading embedding model: '{embedding_model_name}'")
embedding_model = SentenceTransformer(embedding_model_name)

Change the hard (==) versions of required libraries to >=

Please consider changing the way how the dependencies are pinned. E.g. it is now impossible to find a consistent versions set using poetry:

-> poetry add llmware

Using version ^0.1.11 for llmware

Updating dependencies
Resolving dependencies... (9.0s)

Because pandas (2.1.1) depends on numpy (>=1.26.0)
 and llmware (0.1.11) depends on numpy (1.23.2), pandas (2.1.1) is incompatible with llmware (0.1.11).
And because llmware (0.1.11) depends on pandas (2.1.1), llmware is forbidden.
So, because no versions of llmware match >0.1.11,<0.2.0
 and basic-rag depends on llmware (^0.1.11), version solving failed.

Example scripts using llmware

We would love the communities help in building out our set of examples. These can be anything from a comprehensive end to end RAG scenario to a discrete capability your using in the library.

For developers looking for ways to contribute to llmware, this is a great first issue to get started.

gpt-3.5-turbo-1106 and gpt-4-1106-preview support

Hi, sorry if this isn't the right place, however I can't seem to get the two new OpenAI models working. I get the following error:

Starting prompt with sources using model: gpt-3.5-turbo-1106
ERROR:root:error: OpenAI model inference produced error - This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?

Starting prompt with sources using model: gpt-4-1106-preview
ERROR:root:error: OpenAI model inference produced error - This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?

The other models (gpt-4 etc) from OpenAI are working just these two don't and wanted to see performance / output. I checked the models.py file and they're listed there.

Awesome project by the way, exactly what I was looking for.

error while running Prompts\fact_checking.py

I encountered an error while running Prompts\fact_checking.py on windows 11
i did a clean installed of llmware 1.12 and ran the examples.

Prompts\fact_checking.py
Traceback (most recent call last):
File "d:\home\john\Projects\llmware-main\examples\Prompts\fact_checking.py", line 76, in
contract_analysis_with_fact_checking(hf_model_list[0])
File "d:\home\john\Projects\llmware-main\examples\Prompts\fact_checking.py", line 31, in contract_analysis_with_fact_checking
source = prompter.add_source_document(contracts_path, contract, query=research["topic"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\prompts.py", line 400, in add_source_document
output = Parser().parse_one(input_fp,input_fn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\parsers.py", line 1870, in parse_one
ParserState().save_parser_output(self.parser_job_id, output)
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\resources.py", line 708, in save_parser_output
for entry_dict in parser_output:
TypeError: 'NoneType' object is not iterable

john

Assigning a "base_url"

Hello Team. Love the library. I am working with the Prompt().load_model() function.

I can assign an api_key but it doesn't allow me to assign a "Bare_url" to use that key.

Would appreciate any help.

problem with libzip4

I wanted to try your software but I've found a problem during first execution. I work on a Ubuntu 20.
apt install -y libxml2 libpng-dev libmongoc-dev libzip4 tesseract-ocr poppler-utils

E: Unable to locate package libzip4

So i wanted toimport your libraries but I 've found constantly problems with libzip4 library. In example, in parsers.py
Traceback (most recent call last):
File "parsers.py", line 67, in
_mod = cdll.LoadLibrary(_path_office)
File "/usr/lib/python3.10/ctypes/init.py", line 452, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.10/ctypes/init.py", line 374, in init
self._handle = _dlopen(self._name, mode)
OSError: libzip.so.4: cannot open shared object file: No such file or directory

Googling I couldn't find a solution to install properly libzip4

Thank you

Add docstrings

Obviously this would be pretty big for a single issue but that fact that most methods don't seem to have docstrings is troubling. The tutorials you have are very helpful but they're not a full replacement for actual docstrings, type annotations, etc. which make it much easier to build using llmware. Happy to contribute as well, but that would require knowing what docstring format y'all prefer and other style guide standards.

llmware/llmware/libgraph_llmware.so' (no such file)

/Users/bcm/.pyenv/versions/anaconda3-2022.05/envs/llmware/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 50399 --file /Users/bcm/gh/llmware/examples/getting_started.py 
Connected to pydev debugger (build 231.9225.15)
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/bcm/gh/llmware/llmware/library.py", line 24, in <module>
    from llmware.util import Utilities, Graph
  File "/Users/bcm/gh/llmware/llmware/util.py", line 1888, in <module>
    _mod_utility = cdll.LoadLibrary(_path_graph)
  File "/Users/bcm/.pyenv/versions/anaconda3-2022.05/envs/llmware/lib/python3.10/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/Users/bcm/.pyenv/versions/anaconda3-2022.05/envs/llmware/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/bcm/gh/llmware/llmware/libgraph_llmware.so, 0x0006): tried: '/Users/bcm/gh/llmware/llmware/libgraph_llmware.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/bcm/gh/llmware/llmware/libgraph_llmware.so' (no such file), '/Users/bcm/gh/llmware/llmware/libgraph_llmware.so' (no such file)
python-BaseException

Cloned directory and ran pip install -e ., then the getting started example. I cleared out my python 3.10 pyenv installation and created a new one from 3.10.13. No fix.

/Users/bcm/.pyenv/versions/llmware/bin/python /Users/bcm/gh/llmware/examples/getting_started.py 
Traceback (most recent call last):
  File "/Users/bcm/gh/llmware/examples/getting_started.py", line 9, in <module>
    from llmware.library import Library
  File "/Users/bcm/gh/llmware/llmware/library.py", line 24, in <module>
    from llmware.util import Utilities, Graph
  File "/Users/bcm/gh/llmware/llmware/util.py", line 1888, in <module>
    _mod_utility = cdll.LoadLibrary(_path_graph)
  File "/Users/bcm/.pyenv/versions/3.10.13/lib/python3.10/ctypes/__init__.py", line 452, in LoadLibrary
    return self._dlltype(name)
  File "/Users/bcm/.pyenv/versions/3.10.13/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/bcm/gh/llmware/llmware/libgraph_llmware.so, 0x0006): tried: '/Users/bcm/gh/llmware/llmware/libgraph_llmware.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/bcm/gh/llmware/llmware/libgraph_llmware.so' (no such file), '/Users/bcm/gh/llmware/llmware/libgraph_llmware.so' (no such file)

Issue while ingesting JSON files

I'm facing an issue whenever I try to create library for JSON files. The error reads as follows:

ERROR:root:error: to use prompt_with_source, there must be a loaded source - try '.add_sources' first
Traceback (most recent call last):
File "/home/user/Documents/LLMware/examples/Getting_Started/getting_started_with_rag.py", line 70, in
end_to_end_rag(model_name, vector_db="faiss")
File "/home/user/Documents/LLMware/examples/Getting_Started/getting_started_with_rag.py", line 49, in end_to_end_rag
print ("\n > LLM response\n" + response["llm_response"])
KeyError: 'llm_response'

Any leads in solving them will be helpful.

error encountered running docs2vecs_with_milvus-rag.py

I encountered an error while running docs2vecs_with_milvus-rag.py
The problem is there is no response from the model and the llm_response key is not available in the dictionary.

Contract Name: 1 Amphitrite EXECUTIVE EMPLOYMENT AGREEMENT.pdf
ERROR:root:error: to use prompt_with_source, there must be a loaded source - try '.add_sources' first
Traceback (most recent call last):
File "d:\home\john\Projects\llmware-main\examples\Embedding\docs2vecs_with_milvus-rag.py", line 92, in
rag(user_selected_name)
File "d:\home\john\Projects\llmware-main\examples\Embedding\docs2vecs_with_milvus-rag.py", line 82, in rag
print("\nupdate: llm answer - ", resp["llm_response"])
~~~~^^^^^^^^^^^^^^^^
KeyError: 'llm_response'

I added this check for llm_response at line 81 in docs2vecs_with_milvus-rag.py on my system and it ran without errors.

for resp in response:
if 'llm_response' in resp:
print("\nupdate: llm answer - ", resp["llm_response"])
else:
print("\nupdate: llm answer - No Response")

John

Windows support

Hi. Tried to install it on Windows - no luck so far. When do you intend to add Windows support?

Directory llmware_data\query_history missing encountered when running Retrieval\query_state.py

I encountered this error after a clean install of llmware 1.12 on windows 11
the problem is the directory llmware_data\query_history was not created.

Traceback (most recent call last):
File "d:\home\john\Projects\llmware-main\examples\Retrieval\query_state.py", line 60, in
query_state_and_export(lib)
File "d:\home\john\Projects\llmware-main\examples\Retrieval\query_state.py", line 41, in query_state_and_export
query.save_query_state()
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\retrieval.py", line 236, in save_query_state
QueryState(self).save_state()
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\resources.py", line 1224, in save_state
outfile = open(fp, "w", encoding='utf-8')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\jehol\llmware_data\query_history\query_7457a169-7318-404b-a005-3387b8a17268.jsonl'

I created directory llmware_data\query_history and re ran query_state.py
query_state.py ran successfully

John

Issues with Table Extraction Accuracy in Sample

Problem Description

When using the sample provided by the llmware project, I've encountered issues with the accuracy of table extractions. Specifically, not all tables are being extracted correctly.
As an example given in the sample, Annual_Report_2003.pdf.

Steps to Reproduce

Run the sample extraction process as in examples. Set query parameter to be empty string.
Review the output and compare it to the expected tables within the documents. Only one table, to be exact, part of the table spreading from page 44-46, got correctly extracted.

Expected Outcome

All tables within the sample documents should be identified and extracted accurately. In this file, tables that are supposed to be extracted are given below as screenshot,
Screenshot 2023-12-07 at 11 26 35 AM
Screenshot 2023-12-07 at 11 26 53 AM
Screenshot 2023-12-07 at 11 27 06 AM
Screenshot 2023-12-07 at 11 27 20 AM
Screenshot 2023-12-07 at 11 27 35 AM
Screenshot 2023-12-07 at 11 27 46 AM
Screenshot 2023-12-07 at 11 27 59 AM
Screenshot 2023-12-07 at 11 28 13 AM

Actual Outcome

Only one csv outputs.
Please refer to the outcome table_0.csv.
All other table contents, though extracted in json file, is labeled as text.

Potential Impact

This issue may lead to incomplete or inaccurate data capture, which can affect the integrity of data analysis and further processing steps.

Request for Assistance

I would appreciate any guidance on how to resolve this issue or any suggested workarounds. Additionally, if there are any plans to improve the table extraction feature in the near future, information on that would also be helpful.

set' object has no attribute 'items'


AttributeError Traceback (most recent call last)
Cell In[1], line 63
59 if name == "main":
61 model = "llmware/bling-1b-0.1"
---> 63 contract_analysis_on_laptop(model)

Cell In[1], line 36
33 print("\nAnalyzing contract: ", str(i+1), contract)
35 print("LLM Responses:")
---> 36 for key, value in query_list.items():
37
38 # contract is parsed, text-chunked, and then filtered by topic key
39 source = prompter.add_source_document(contracts_path, contract, query=key)
41 # calling the LLM with 'source' information from the contract automatically packaged into the prompt

AttributeError: 'set' object has no attribute 'items'

"""This example demonstrats doing an analysis across contracts entirely on on a laptop
using local models
"""

import os
import re
from llmware.prompts import Prompt, HumanInTheLoop
from llmware.setup import Setup
from llmware.configs import LLMWareConfig

def contract_analysis_on_laptop (model_name, from_hf=False):

# Load the llmware sample files
print (f"\n > Loading the llmware sample files...")
contracts_path = ("/home/ubuntu/Documents/ags/")
# query list
query_list = {"what is tunisia oblications of contacts?"}

print (f"\n > Loading model {model_name}...")
# Note: Some newer models use local custom code in their HF repos which is not trusted by default
#  For now, you can pass in a dummy api_key and we'll set the right config to trust that code
#  This will likely be changing in the future
if from_hf:
    # local cpu open source model
    prompter = Prompt().load_model(model_name,from_hf=True)
else:
    # e.g., 'gpt-4'
    prompter = Prompt().load_model(model_name)

for i, contract in enumerate(os.listdir(contracts_path)):

    print("\nAnalyzing contract: ", str(i+1), contract)

    print("LLM Responses:")
    for key, value in query_list.items():

        # contract is parsed, text-chunked, and then filtered by topic key
        source = prompter.add_source_document(contracts_path, contract, query=key)

        # calling the LLM with 'source' information from the contract automatically packaged into the prompt
        responses = prompter.prompt_with_source(value, prompt_name="just_the_facts", temperature=0.3)

        for r, response in enumerate(responses):
            print(key, ":", re.sub("[\n]"," ", response["llm_response"]).strip())

        # We're done with this contract, clear the source from the prompt
        prompter.clear_source_materials()

# Save jsonl report to jsonl to /prompt_history folder
print("\nPrompt state saved at: ", os.path.join(LLMWareConfig.get_prompt_path(),prompter.prompt_id))
prompter.save_state()

#Save csv report that includes the model, response, prompt, and evidence for human-in-the-loop review
csv_output = HumanInTheLoop(prompter).export_current_interaction_to_csv()
print("csv output - ", csv_output)

if name == "main":

model = "llmware/bling-1b-0.1"

contract_analysis_on_laptop(model)

Issue loading PDF files on windows 11

I am having problems with loading some of my PDF files on Windows 11 Pro.

Your examples seem to work fine for parsing PDF files, but when I use some of my own PDF files, I get the error below.
The file is 50 pages with tables and graphics.

Traceback (most recent call last):
File "d:\home\john\Projects\llmware-Project\LLMWareCreateLib.py", line 29, in
library.add_files(os.path.join(sample_files_path,File_Dir))
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\library.py", line 357, in add_files parsing_results = Parser(library=self).ingest(input_folder_path,dupe_check=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\parsers.py", line 358, in ingest
self.parse_pdf(self.pdf_work_folder, save_history=False)
File "C:\Users\jehol\AppData\Local\Programs\Python\Python311\Lib\site-packages\llmware\parsers.py", line 719, in parse_pdf pages_created = pdf_handler(account_name, library_name, fp_c, collection_db_path_c, image_fp_c,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: exception: access violation reading 0x0000023068F20360
PS D:\home\john\Projects\llmware-Project>

Can you help me work through this? Let me know if I can provide more information.

Thanks,
John

Vector DB: Add support for Qdrant

Expand Vector DB support to include Qdrant.

Milvus and Pinecone implementations in the embeddings.py can be used as a guide.

Scope includes:
Updating LLMWareConfig, EmbeddingHandler
Creating an Embedding class specific to Qdrant
Test scripts and example code

EmbeddingHandler gets stuck trying to create embeddings for images

Hi Team,

When I try to create embeddigns for some pdf docuements, the program got stuck after some time. After some investigations, it appears that all teh blocks which were pending ( and where application got stuck), had content_type : "image" in the mongodb block document. Perhaps not trying to embed non text blocks should work , trying to do this in code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.