Skip to main content

llama-index packs trulens_eval_packs integration

Project description

TruLens-Eval Llama-Pack

TruLens

The best way to support TruLens is to give us a ⭐ on GitHub and join our slack community!

TruLens provides three Llamma Packs for LLM app observability:

  • The first is the TruLensRAGTriadPack (context relevance, groundedness, answer relevance). This triad holds the key to detecting hallucination.

  • Second, is the TruLensHarmlessPack including moderation and safety evaluations like criminality, violence and more.

  • Last is the TruLensHelpfulPack, including evaluations like conciseness and language match.

No matter which TruLens LlamaPack you choose, all three provide evaluation and tracking for your LlamaIndex app with TruLens, an open-source LLM observability library from TruEra.

CLI Usage

You can download llamapacks directly using llamaindex-cli, which comes installed with the llama-index python package:

llamaindex-cli download-llamapack TruLensRAGTriadPack --download-dir ./trulens_pack

You can then inspect the files at ./trulens_pack and use them as a template for your own project.

Code Usage

You can download each pack to a ./trulens_pack directory:

from llama_index.core.llama_pack import download_llama_pack

# download and install dependencies
TruLensRAGTriadPack = download_llama_pack(
    "TruLensRAGTriadPack", "./trulens_pack"
)

From here, you can use the pack, or inspect and modify the pack in ./trulens_pack.

Then, you can set up the pack like so:

import os

os.environ["OPENAI_API_KEY"] = "sk-..."

from tqdm.auto import tqdm
from llama_index.core.node_parser import SentenceSplitter
from llama_index.readers.web import SimpleWebPageReader

documents = SimpleWebPageReader(html_to_text=True).load_data(
    ["http://paulgraham.com/worked.html"]
)

splitter = SentenceSplitter()
nodes = splitter.get_nodes_from_documents(documents)

trulens_ragtriad_pack = TruLensRAGTriadPack(
    nodes=nodes, app_id="Query Engine v1: RAG Triad Evals"
)

Then run your queries and evaluate!

queries = [
    "What did Paul Graham do growing up?",
    "When and how did Paul Graham's mother die?",
    "What, in Paul Graham's opinion, is the most distinctive thing about YC?",
    "When and how did Paul Graham meet Jessica Livingston?",
    "What is Bel, and when and where was it written?",
]
for query in tqdm(queries):
    print("Query")
    print("=====")
    print(query)
    print()
    response = trulens_ragtriad_pack.run(query)
    print("Response")
    print("========")
    print(response)

You can access the internals of the LlamaPack, including your TruLens session and your query engine, via the get_modules method.

modules = trulens_ragtriad_pack.get_modules()
tru = modules["session"]
index = modules["index"]
query_engine = modules["query_engine"]
tru_query_engine = modules["tru_query_engine"]
tru.get_leaderboard(app_ids=["Query Engine v1: RAG Triad Evals"])

Resources

There is a more complete notebook demo available in the llama-hub repo.

Check out the TruLens documentation for more information!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

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

File details

Details for the file llama_index_packs_trulens_eval_packs-0.4.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_packs_trulens_eval_packs-0.4.1.tar.gz
Algorithm Hash digest
SHA256 f817c5a747181498b1c31e890950cfcb62f72ecd19a565c058c35fdb960f57ea
MD5 088eada330e865884b7291928d396b3a
BLAKE2b-256 1fd6db46202bcd378230adb83702ab8044acc0a84165569e904175420f94507f

See more details on using hashes here.

File details

Details for the file llama_index_packs_trulens_eval_packs-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_packs_trulens_eval_packs-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 117054ca1f2ba42b09246462bb71ee48f5457fcb4aef501810903cd86881aa6e
MD5 d1c9480ba66b69e03f37b00ffb8d30d3
BLAKE2b-256 ec4b25b3d43b03bfb516ae2057d51303873ddca54d3810cc989847a6d598506f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page