<h1 align="center">
Nadir
<br>
</h1>
<div align="center">
<img src="https://iili.io/2LWOIhx.md.png" width="25%" height="25%">
</div>
<p align="center">
<b>No Overhead, Just Output</b> <br />
<b>AI-Driven LLM Selection • Complexity Analysis • Cost-Efficient Compression • Multi-Provider Support</b> <br />
</p>
---
[](https://opensource.org/licenses/MIT)


---
## 🔍 **Overview**
**Nadir** is an intelligent **LLM selection framework** that dynamically chooses the best AI model for a given prompt based on:
- 🚀 **Complexity Analysis**: Evaluates text structure, difficulty, and token usage.
- ⚡ **Multi-Provider Support**: Works with OpenAI, Anthropic, Gemini, and Hugging Face models.
- 💰 **Cost & Speed Optimization**: Balances model **accuracy, response time, and pricing**.
- 🔄 **Adaptive Compression**: Reduces token usage via **truncation, keyword extraction, or AI-powered compression**.
---
## Why Choose Nadir?
- **Dynamic Model Selection**: Automatically choose the best LLM for any given task based on complexity and cost thresholds.
- **Cost Optimization**: Minimize token usage and costs with intelligent prompt compression.
- **Multi-Provider Support**: Seamless integration with OpenAI, Anthropic, Google Gemini, and Hugging Face.
- **Extensible Design**: Add your own complexity analyzers, compression strategies, or new providers effortlessly.
- **Rich Insights**: Generate detailed metrics on token usage, costs, and model performance.
<img width="857" alt="Image" src="https://github.com/user-attachments/assets/2c25a21c-eb16-48b8-a205-df82ffc77cdc" />
---
## Installation
Install Nadir using pip:
```bash
pip install nadir
```
---
## Set Up Environment Variables
Create a .env file to store your API keys:
```
# .env file
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
GEMINI_API_KEY=your_google_ai_key
HUGGINGFACE_API_KEY=your_huggingface_api_key
```
## 🚀 Usage
### 🔹 Select the Best LLM for a Prompt
```python
from src.nadir.llm_selector.selector.auto import AutoSelector
nadir = AutoSelector()
prompt = "Explain quantum entanglement in simple terms."
response = nadir.generate_response(prompt)
print(response)
```
### 🔹 Get Complexity Analysis & Recommended Model
```python
complexity_details = nadir.get_complexity_details("What is the speed of light in vacuum?")
print(complexity_details)
```
### 🔹 List Available Models
```python
models = nadir.list_available_models()
print(models)
```
## ⚙️ Advanced Usage: Using GeminiComplexityAnalyzer and Compression
### 🔹 Analyzing Code Complexity and Selecting the Best LLM
```python
from src.nadir.complexity.gemini import GeminiComplexityAnalyzer
from src.nadir.llm_selector.selector.auto import AutoSelector
# Initialize the Gemini-based complexity analyzer
complexity_analyzer = GeminiComplexityAnalyzer()
# Sample Python code
code_snippet = """
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
"""
# Get detailed complexity metrics
complexity_details = complexity_analyzer.get_complexity_details(code_snippet)
print("Complexity Details:", complexity_details)
# Initialize Nadir and dynamically select the best model
nadir = AutoSelector(complexity_analyzer=complexity_analyzer)
selected_model = nadir.select_model(code_snippet)
print("Selected Model:", selected_model.name)
```
### 🔹 Compressing Long Prompts Before Model Selection
```python
from src.nadir.compression import GeminiCompressor
from src.nadir.llm_selector.selector.auto import AutoSelector
# Initialize Gemini-based prompt compression
compressor = GeminiCompressor()
# A very long prompt
long_prompt = """
Machine learning models require extensive preprocessing and feature engineering.
However, feature selection techniques vary widely based on the type of data.
For example, in text-based datasets, TF-IDF, word embeddings, and transformers
play a significant role, whereas in tabular data, methods like PCA, correlation
analysis, and decision tree-based feature selection are preferred.
"""
# Compress the prompt
compressed_prompt = compressor.compress(long_prompt, method="auto", max_tokens=100)
print("Compressed Prompt:", compressed_prompt)
# Use Nadir to select the best model for the compressed prompt
nadir = AutoSelector()
selected_model = nadir.select_model(compressed_prompt)
print("Selected Model:", selected_model.name)
```
### 🔹 Combining Compression & Complexity Analysis
```python
from src.nadir.compression import GeminiCompressor
from src.nadir.complexity.gemini import GeminiComplexityAnalyzer
from src.nadir.llm_selector.selector.auto import AutoSelector
# Initialize complexity analyzer and compressor
complexity_analyzer = GeminiComplexityAnalyzer()
compressor = GeminiCompressor()
# A long, complex prompt
long_prompt = """
Deep learning models often suffer from overfitting when trained on small datasets.
To combat this, techniques such as dropout, batch normalization, and L2 regularization
are widely used. Furthermore, transfer learning from pre-trained models has become
a popular method for reducing the need for large labeled datasets.
"""
# Step 1: Compress the prompt
compressed_prompt = compressor.compress(long_prompt, method="auto", max_tokens=80)
print("Compressed Prompt:", compressed_prompt)
# Step 2: Analyze complexity
complexity_details = complexity_analyzer.get_complexity_details(compressed_prompt)
print("Complexity Details:", complexity_details)
# Step 3: Select the best model
nadir = AutoSelector(complexity_analyzer=complexity_analyzer)
selected_model = nadir.select_model(compressed_prompt, complexity_details)
print("Selected Model:", selected_model.name)
```
---
## ⚙️ How It Works
### 1️⃣ Complexity Analysis
Uses `GeminiComplexityAnalyzer` to evaluate **token usage**, **linguistic difficulty**, and **structural complexity**.
Assigns a **complexity score** (0-100).
### 2️⃣ Intelligent Model Selection
Compares **complexity scor**e with **pre-configured LLM models**.
Chooses **the best trade-off between cost, accuracy, and speed**.
### 3️⃣ Efficient Response Generation
**Compresses long prompts** when necessary.
Calls **the selected model** and **tracks token usage & cost**.
---
## Community & Support
## 🛠 Development & Contributions
### 💡 We welcome contributions! Follow these steps:
### 1️⃣ Fork the Repository
```
git clone https://github.com/your-username/Nadir.git
cd Nadir
```
### 2️⃣ Create a Feature Branch
```
git checkout -b feature-improvement
```
### 3️⃣ Make Changes & Run Tests
```
pytest tests/
```
### 4️⃣ Commit & Push Changes
```
git add .
git commit -m "Added a new complexity metric"
git push origin feature-improvement
```
### 5️⃣ Submit a Pull Request
Open a PR on GitHub 🚀
Join the conversation and get support in our **[Discord Community](https://discord.gg/nadir)**. You can also find examples, documentation, and updates on our **[Website](https://nadir.ai)**.
---
## 📢 Connect with Us
💬 Have questions or suggestions? **Create an Issue** or **Start a Discussion** on GitHub.
🔥 Happy coding with **Nadir!** 🚀
Raw data
{
"_id": null,
"home_page": "https://github.com/doramirdor/nadir",
"name": "nadir-llm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "LLM, model selection, prompt, complexity",
"author": "Dor Amir",
"author_email": "Dor Amir <amirdor@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/d8/4b/0694cee518d06c11325a6ce96bf5fbead92ebbaf952cee0da15fdaeac524/nadir_llm-0.1.0.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">\n Nadir\n <br>\n</h1>\n\n<div align=\"center\">\n<img src=\"https://iili.io/2LWOIhx.md.png\" width=\"25%\" height=\"25%\">\n</div>\n\n<p align=\"center\">\n <b>No Overhead, Just Output</b> <br />\n <b>AI-Driven LLM Selection \u2022 Complexity Analysis \u2022 Cost-Efficient Compression \u2022 Multi-Provider Support</b> <br />\n</p>\n\n---\n\n[](https://opensource.org/licenses/MIT)\n\n\n\n---\n\n## \ud83d\udd0d **Overview**\n\n**Nadir** is an intelligent **LLM selection framework** that dynamically chooses the best AI model for a given prompt based on:\n\n- \ud83d\ude80 **Complexity Analysis**: Evaluates text structure, difficulty, and token usage.\n- \u26a1 **Multi-Provider Support**: Works with OpenAI, Anthropic, Gemini, and Hugging Face models.\n- \ud83d\udcb0 **Cost & Speed Optimization**: Balances model **accuracy, response time, and pricing**.\n- \ud83d\udd04 **Adaptive Compression**: Reduces token usage via **truncation, keyword extraction, or AI-powered compression**.\n\n---\n\n## Why Choose Nadir?\n\n- **Dynamic Model Selection**: Automatically choose the best LLM for any given task based on complexity and cost thresholds.\n- **Cost Optimization**: Minimize token usage and costs with intelligent prompt compression.\n- **Multi-Provider Support**: Seamless integration with OpenAI, Anthropic, Google Gemini, and Hugging Face.\n- **Extensible Design**: Add your own complexity analyzers, compression strategies, or new providers effortlessly.\n- **Rich Insights**: Generate detailed metrics on token usage, costs, and model performance.\n\n<img width=\"857\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/2c25a21c-eb16-48b8-a205-df82ffc77cdc\" />\n---\n\n## Installation\n\nInstall Nadir using pip:\n\n```bash\npip install nadir\n```\n\n---\n\n## Set Up Environment Variables\n\nCreate a .env file to store your API keys:\n\n```\n# .env file\nOPENAI_API_KEY=your_openai_api_key\nANTHROPIC_API_KEY=your_anthropic_api_key\nGEMINI_API_KEY=your_google_ai_key\nHUGGINGFACE_API_KEY=your_huggingface_api_key\n\n```\n\n## \ud83d\ude80 Usage\n\n### \ud83d\udd39 Select the Best LLM for a Prompt\n\n```python\nfrom src.nadir.llm_selector.selector.auto import AutoSelector\n\nnadir = AutoSelector()\nprompt = \"Explain quantum entanglement in simple terms.\"\nresponse = nadir.generate_response(prompt)\n\nprint(response)\n```\n\n### \ud83d\udd39 Get Complexity Analysis & Recommended Model\n\n```python\ncomplexity_details = nadir.get_complexity_details(\"What is the speed of light in vacuum?\")\nprint(complexity_details)\n```\n\n### \ud83d\udd39 List Available Models\n\n```python\nmodels = nadir.list_available_models()\nprint(models)\n```\n\n## \u2699\ufe0f Advanced Usage: Using GeminiComplexityAnalyzer and Compression\n\n### \ud83d\udd39 Analyzing Code Complexity and Selecting the Best LLM\n\n```python\nfrom src.nadir.complexity.gemini import GeminiComplexityAnalyzer\nfrom src.nadir.llm_selector.selector.auto import AutoSelector\n\n# Initialize the Gemini-based complexity analyzer\ncomplexity_analyzer = GeminiComplexityAnalyzer()\n\n# Sample Python code\ncode_snippet = \"\"\"\ndef factorial(n):\n if n == 0:\n return 1\n else:\n return n * factorial(n-1)\n\"\"\"\n\n# Get detailed complexity metrics\ncomplexity_details = complexity_analyzer.get_complexity_details(code_snippet)\nprint(\"Complexity Details:\", complexity_details)\n\n# Initialize Nadir and dynamically select the best model\nnadir = AutoSelector(complexity_analyzer=complexity_analyzer)\nselected_model = nadir.select_model(code_snippet)\nprint(\"Selected Model:\", selected_model.name)\n\n\n```\n\n### \ud83d\udd39 Compressing Long Prompts Before Model Selection\n\n```python\nfrom src.nadir.compression import GeminiCompressor\nfrom src.nadir.llm_selector.selector.auto import AutoSelector\n\n# Initialize Gemini-based prompt compression\ncompressor = GeminiCompressor()\n\n# A very long prompt\nlong_prompt = \"\"\"\nMachine learning models require extensive preprocessing and feature engineering.\nHowever, feature selection techniques vary widely based on the type of data.\nFor example, in text-based datasets, TF-IDF, word embeddings, and transformers\nplay a significant role, whereas in tabular data, methods like PCA, correlation\nanalysis, and decision tree-based feature selection are preferred.\n\"\"\"\n\n# Compress the prompt\ncompressed_prompt = compressor.compress(long_prompt, method=\"auto\", max_tokens=100)\nprint(\"Compressed Prompt:\", compressed_prompt)\n\n# Use Nadir to select the best model for the compressed prompt\nnadir = AutoSelector()\nselected_model = nadir.select_model(compressed_prompt)\nprint(\"Selected Model:\", selected_model.name)\n```\n\n### \ud83d\udd39 Combining Compression & Complexity Analysis\n\n```python\nfrom src.nadir.compression import GeminiCompressor\nfrom src.nadir.complexity.gemini import GeminiComplexityAnalyzer\nfrom src.nadir.llm_selector.selector.auto import AutoSelector\n\n# Initialize complexity analyzer and compressor\ncomplexity_analyzer = GeminiComplexityAnalyzer()\ncompressor = GeminiCompressor()\n\n# A long, complex prompt\nlong_prompt = \"\"\"\nDeep learning models often suffer from overfitting when trained on small datasets.\nTo combat this, techniques such as dropout, batch normalization, and L2 regularization\nare widely used. Furthermore, transfer learning from pre-trained models has become\na popular method for reducing the need for large labeled datasets.\n\"\"\"\n\n# Step 1: Compress the prompt\ncompressed_prompt = compressor.compress(long_prompt, method=\"auto\", max_tokens=80)\nprint(\"Compressed Prompt:\", compressed_prompt)\n\n# Step 2: Analyze complexity\ncomplexity_details = complexity_analyzer.get_complexity_details(compressed_prompt)\nprint(\"Complexity Details:\", complexity_details)\n\n# Step 3: Select the best model\nnadir = AutoSelector(complexity_analyzer=complexity_analyzer)\nselected_model = nadir.select_model(compressed_prompt, complexity_details)\nprint(\"Selected Model:\", selected_model.name)\n\n```\n\n---\n\n## \u2699\ufe0f How It Works\n\n### 1\ufe0f\u20e3 Complexity Analysis\n\nUses `GeminiComplexityAnalyzer` to evaluate **token usage**, **linguistic difficulty**, and **structural complexity**.\nAssigns a **complexity score** (0-100).\n\n### 2\ufe0f\u20e3 Intelligent Model Selection\n\nCompares **complexity scor**e with **pre-configured LLM models**.\nChooses **the best trade-off between cost, accuracy, and speed**.\n\n### 3\ufe0f\u20e3 Efficient Response Generation\n\n**Compresses long prompts** when necessary.\nCalls **the selected model** and **tracks token usage & cost**.\n\n---\n\n## Community & Support\n\n## \ud83d\udee0 Development & Contributions\n\n### \ud83d\udca1 We welcome contributions! Follow these steps:\n\n### 1\ufe0f\u20e3 Fork the Repository\n\n```\ngit clone https://github.com/your-username/Nadir.git\ncd Nadir\n```\n### 2\ufe0f\u20e3 Create a Feature Branch\n```\ngit checkout -b feature-improvement\n```\n### 3\ufe0f\u20e3 Make Changes & Run Tests\n```\npytest tests/\n```\n### 4\ufe0f\u20e3 Commit & Push Changes\n```\ngit add .\ngit commit -m \"Added a new complexity metric\"\ngit push origin feature-improvement\n```\n### 5\ufe0f\u20e3 Submit a Pull Request\nOpen a PR on GitHub \ud83d\ude80\n\n\nJoin the conversation and get support in our **[Discord Community](https://discord.gg/nadir)**. You can also find examples, documentation, and updates on our **[Website](https://nadir.ai)**.\n\n---\n\n## \ud83d\udce2 Connect with Us\n\ud83d\udcac Have questions or suggestions? **Create an Issue** or **Start a Discussion** on GitHub.\n\n\ud83d\udd25 Happy coding with **Nadir!** \ud83d\ude80\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Dynamic LLM Model Selector based on Prompt Complexity",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/doramirdor/nadir"
},
"split_keywords": [
"llm",
" model selection",
" prompt",
" complexity"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6ab2777ca7dee582a768cf745c4994145a3b4358dab4278eaf8be88c0b3bf31e",
"md5": "99ed6efa7aedd7ab90e39334d214f5c3",
"sha256": "e827e28aa435e43ca9f85d5fc0c95cd4e4d8c1646fb676d913e519aeebbaba2f"
},
"downloads": -1,
"filename": "nadir_llm-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "99ed6efa7aedd7ab90e39334d214f5c3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 41099,
"upload_time": "2025-02-08T17:28:10",
"upload_time_iso_8601": "2025-02-08T17:28:10.290945Z",
"url": "https://files.pythonhosted.org/packages/6a/b2/777ca7dee582a768cf745c4994145a3b4358dab4278eaf8be88c0b3bf31e/nadir_llm-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "d84b0694cee518d06c11325a6ce96bf5fbead92ebbaf952cee0da15fdaeac524",
"md5": "afa11191b1eee2da660c0b8a895946df",
"sha256": "86b95d34042dffb82c219125bd8d37fa926eabac46f06b408004a11e43381642"
},
"downloads": -1,
"filename": "nadir_llm-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "afa11191b1eee2da660c0b8a895946df",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 31440,
"upload_time": "2025-02-08T17:28:12",
"upload_time_iso_8601": "2025-02-08T17:28:12.399392Z",
"url": "https://files.pythonhosted.org/packages/d8/4b/0694cee518d06c11325a6ce96bf5fbead92ebbaf952cee0da15fdaeac524/nadir_llm-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-08 17:28:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "doramirdor",
"github_project": "nadir",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "anthropic",
"specs": [
[
">=",
"0.20.0"
]
]
},
{
"name": "openai",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "transformers",
"specs": [
[
">=",
"4.35.0"
]
]
},
{
"name": "accelerate",
"specs": [
[
">=",
"0.20.0"
]
]
},
{
"name": "tiktoken",
"specs": [
[
">=",
"0.5.0"
]
]
},
{
"name": "torch",
"specs": [
[
">=",
"2.0.0"
]
]
},
{
"name": "google-generativeai",
"specs": [
[
">=",
"0.8.0"
]
]
},
{
"name": "litellm",
"specs": []
},
{
"name": "numpy",
"specs": [
[
">=",
"1.22.0"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"2.0.0"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
">=",
"1.2.0"
]
]
},
{
"name": "pydantic",
"specs": [
[
">=",
"2.0.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "pytest",
"specs": [
[
">=",
"7.0.0"
]
]
},
{
"name": "mypy",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "black",
"specs": [
[
">=",
"23.0.0"
]
]
},
{
"name": "flake8",
"specs": [
[
">=",
"6.0.0"
]
]
},
{
"name": "py-spy",
"specs": [
[
">=",
"0.3.14"
]
]
},
{
"name": "matplotlib",
"specs": [
[
">=",
"3.7.0"
]
]
},
{
"name": "seaborn",
"specs": [
[
">=",
"0.12.0"
]
]
}
],
"lcname": "nadir-llm"
}