langrade
langrade is a Python library for grading and retrieving documents based on their relevance to a given question. It supports multiple LLM providers including OpenAI, Anthropic (Claude), and VertexAI (Gemini).
Installation
You can install Langrade using pip
pip install langrade
Usage
Here's a quick example of how to use Langrade with different providers
from langrade import document_grader, create_retriever
# Initialize the grader with OpenAI
provider = "openai"
api_key = "your_openai_api_key_here"
model = "gpt-4o-mini-2024-07-18" # optional
grader = document_grader(provider, api_key, model)
# Or with Anthropic (Claude)
provider = "anthropic"
api_key = "your_anthropic_api_key_here"
model = "claude-3-5-haiku-20241022" # optional
grader = document_grader(provider, api_key, model)
# Or with Google (Gemini)
provider = "vertexai"
credentials = {
"project_id": "your_project_id",
"location": "your_location", # optional, defaults to asia-northeast1
# ... other service account credentials
}
model = "gemini-1.5-flash" # optional
grader = document_grader(provider, credentials, model)
# Prepare the retriever (uses OpenAI embeddings)
urls = [
"https://lilianweng.github.io/posts/2023-06-23-agent/",
"https://lilianweng.github.io/posts/2023-03-15-prompt-engineering/",
"https://lilianweng.github.io/posts/2023-10-25-adv-attack-llm/",
]
retriever = create_retriever(urls, openai_api_key)
# Retrieve and grade a document
question = "What is AI?"
docs = retriever.get_relevant_documents(question)
doc_txt = docs[0].page_content
result = grader.grade_document(doc_txt, question)
print(f"Relevance: {result.binary_score}") # 'yes' or 'no'
print(f"Reasoning: {result.reasoning}")
Features
-
Document grading based on relevance to a question
-
Support for multiple LLM providers
- OpenAI (GPT models)
- Anthropic (Claude models)
- Google (Gemini models)
-
Document retrieval from web URLs
-
Flexible configuration options for each provider
Requirements
-
Python 3.9+
-
API key for chosen provider
- OpenAI API key for OpenAI
- Anthropic API key for Claude
- Google Cloud service account credentials for Gemini
Environment Setup
-
For local development:
- Copy .env.example to .env
- Fill in your API keys and configuration
# OpenAI Configuration
OPENAI_API_KEY=your-api-key-here
OPENAI_MODEL=gpt-3.5-turbo-0125
# Google Cloud Platform Configuration
GCP_PROJECT_ID=your-project-id
GCP_LOCATION=asia-northeast1
GOOGLE_APPLICATION_CREDENTIALS=path-to-credentials.json
GEMINI_MODEL=gemini-2.0-flash-exp
# Anthropic (Claude) Configuration
ANTHROPIC_API_KEY=your-api-key-here
CLAUDE_MODEL=claude-3-5-haiku-20241022
# Default Engine Configuration
DEFAULT_ENGINE_TYPE=openai
Running Tests
To run all tests
poetry run test
Metadata
Release files for langrade 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langrade-0.1.5.tar.gz | 5.4 kB | Without provenance | Details for langrade-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langrade-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for langrade-0.1.5-py3-none-any.whl |
Total release size: 12.5 kB
Release files / langrade-0.1.5.tar.gz
| Download URL | langrade-0.1.5.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0f19b1a2d437ae0ff2078da936675c92fef9f7b1ff6f82b56318ccf0b711161
|
|
BLAKE2b-256 checksum How to use checksums |
ae49c979af8626c7afd9943bc31f527effe24bf71d728d714a5e8936fa9dcce5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.9 Darwin/23.5.0
|
Release files / langrade-0.1.5-py3-none-any.whl
| Download URL | langrade-0.1.5-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
465097e3d9a0b80d95858cd35cf74c89bf9d819c288f011707c3aa3ec68b536d
|
|
BLAKE2b-256 checksum How to use checksums |
e71fef3f2388e0a7de7040f6a9f663ca8fafd70332c21b384473d5d634ca3b38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.9 Darwin/23.5.0
|
Security for langrade 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.