Skip to main content

A flexible evaluation framework for content using LLMs

Project description

LinguaLens (LSADA)

PyPI version

LinguaLens (formerly LSADA - Language Services and Data Analysis) is a flexible Python framework for evaluating content quality using Large Language Models (LLMs).

It provides a structured way to:

  • Define evaluation tasks with specific metrics and weighting.
  • Use different LLM providers (currently OpenAI, Cloudverse supported).
  • Generate prompts tailored to your evaluation criteria.
  • Parse LLM responses to extract scores and justifications.
  • Aggregate results from multiple evaluations for robustness.

Installation

You can install LinguaLens directly from PyPI:

pip install python-lingualens

Quick Start Example

  1. Set your LLM API Key: Make sure you have your API key (e.g., for OpenAI) set as an environment variable:

    export OPENAI_API_KEY="your_api_key_here"
    # On Windows (Command Prompt)
    # set OPENAI_API_KEY=your_api_key_here
    # On Windows (PowerShell)
    # $env:OPENAI_API_KEY="your_api_key_here"
    
  2. Run the basic usage script: Navigate to the examples directory and run the script:

    cd examples
    python 1_basic_usage.py
    

    This script demonstrates:

    • Initializing an OpenAI client.
    • Initializing the Evaluator for a specific task (conversation_evaluation).
    • Evaluating sample content.
    • Printing the detailed results, including the overall score, individual metric scores, and justifications.
    # examples/1_basic_usage.py (Simplified Snippet)
    import os
    import logging
    from lingualens import Evaluator, LLMManager
    
    logging.basicConfig(level=logging.INFO)
    
    api_key = os.getenv("OPENAI_API_KEY")
    task_type = "conversation_evaluation"
    content_to_evaluate = "... (your content here) ..."
    
    if not api_key:
        logging.error("OPENAI_API_KEY not set.")
    else:
        try:
            llm_client = LLMManager.initialize_client(vendor="openai", api_key=api_key)
            evaluator = Evaluator(task_type=task_type, include_justification=True)
            result = evaluator.evaluate(content=content_to_evaluate, llm_client=llm_client)
    
            print("\n----- Evaluation Results -----")
            print(f"Task Type: {result.get('metadata', {}).get('task_type')}")
            print(f"Total Weighted Score: {result.get('total_weighted_score')}")
            # ... (print detailed scores and justifications) ...
    
        except Exception as e:
            logging.error(f"An error occurred: {e}", exc_info=True)
    

Core Components

  • Evaluator: The main class to orchestrate the evaluation.
  • LLMManager: Manages and initializes clients for different LLM vendors.
  • TaskManager: Handles task definitions, metrics, and can auto-identify tasks.
  • PromptGenerator: Creates detailed prompts for the LLM based on configuration.
  • LLMResponseParser: Extracts structured data from LLM responses.
  • MetricsCalculator: Aggregates scores and performs calculations.
  • ConfigManager: Loads configurations from pool

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

python_lingualens-1.0.1.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

python_lingualens-1.0.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file python_lingualens-1.0.1.tar.gz.

File metadata

  • Download URL: python_lingualens-1.0.1.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for python_lingualens-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9211135fe8e7149a4b96b012cbebc6b64f143e52ed21bd5e7b1fad53b85898e1
MD5 8eceb298dbecf3fc370ee5ad15feab5c
BLAKE2b-256 0922dbeb5b890927927c9c448192a718dce6a5a3080b2310bd3135334ea3e084

See more details on using hashes here.

File details

Details for the file python_lingualens-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_lingualens-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30e5bdae0050d789f63c9ecde2ab6330eed11b52ab8832975c769935b37d53a5
MD5 8af175c8ace25899f1794b0eedf7ad1c
BLAKE2b-256 f8bc1ffb36d47a95836d71bc9752d5dd201a02b00bbf2396bf11008af5249681

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