Free API-based LLM Cascading
Project description
Free API-based LLM Cascade Library
A Python library for cascading LLM (Large Language Model) API calls, allowing you to leverage multiple providers for enhanced language processing capabilities.
Features
- Supports multiple LLM providers (e.g., Groq, Google AI, SambaNova, OpenRouter).
- Easy-to-use interface for making API calls.
- Cosine similarity calculations for comparing responses.
- Environment variable management for sensitive API keys.
Installation
To install the library, you can use pip:
pip install free-apis-llm-cascade
Environment Variables
Before using the library, you need to set up your API keys. Create a .env file in the root directory of your project and populate it with your API keys as follows:
.env
GROQ_API_KEY=your_groq_api_key_here
GOOGLE_API_KEY=your_google_api_key_here
SAMBANOVA_API_KEY=your_sambanova_api_key_here
OPENROUTER_API_KEY=your_openrouter_api_key_here
Make sure to replace the placeholder values with your actual API keys.
Usage
Here’s a quick example of how to use the LLMCascade class:
from free_apis_llm_cascade.cascade import LLMCascade
import asyncio
async def main():
# Instantiate the LLMCascade class
llm_cascade = LLMCascade()
# Prepare your messages, vendors, and models to test the cascade with as well as the cosine similarity threshold
messages=[{ "role": "user", "content": "What is the capital of California?" }]
vendors = ["sambanova", "openrouter", "groq", "groq"] # these are the vendors for the models below
models = ["Meta-Llama-3.2-1B-Instruct", "meta-llama/llama-3.2-3b-instruct:free", "llama3-8b-8192", "llama-3.3-70b-versatile"] # these are the actual models that will be run
# call the llm cascade function
output, num_models_run = await llm_cascade.cascade_three_or_more_llm(vendors, models, messages, 0.7) # cosine threshold = 0.7 here
print(40*"-")
print(f"Final result: {output}")
print(f"Models run up to: {models[num_models_run-1]}")
# Run the main function
if name == "main":
asyncio.run(main())
The three functions that are usable in this library currently are:
get_single_model_result(self, vendor, model, messages)
cosine_sim_two_llm_basic(self, vendors, models, input)
cascade_three_or_more_llm(self, vendors, models, input, cos_sim_threshold)
Contributing
Contributions are welcome! If you have suggestions for improvements or find bugs, please open an issue or submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE.txt file for details.
Useful reference
This GitHub repo stores information about what free LLM APIs are available. We currently only support Groq, Google AI Studio, SambaNova, and OpenRouter, but may expand to others soon.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file free_apis_llm_cascade-0.3.2.tar.gz.
File metadata
- Download URL: free_apis_llm_cascade-0.3.2.tar.gz
- Upload date:
- Size: 50.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20d281879bf270a1dfae5852e592e9375fbf304c7e2160de687e70e379a0db03
|
|
| MD5 |
bf83690935c6719016e35df1634a6447
|
|
| BLAKE2b-256 |
1f5ea38ceb7c89121d2a47f900637a043f667331cace2ee2d84d886b03ed698f
|
Provenance
The following attestation bundles were made for free_apis_llm_cascade-0.3.2.tar.gz:
Publisher:
publish.yml on h-michaelson20/open-source-free-cascader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
free_apis_llm_cascade-0.3.2.tar.gz -
Subject digest:
20d281879bf270a1dfae5852e592e9375fbf304c7e2160de687e70e379a0db03 - Sigstore transparency entry: 171345257
- Sigstore integration time:
-
Permalink:
h-michaelson20/open-source-free-cascader@f997f7c5807a921da2d96d353be7df390e6b6a8c -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/h-michaelson20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f997f7c5807a921da2d96d353be7df390e6b6a8c -
Trigger Event:
release
-
Statement type:
File details
Details for the file free_apis_llm_cascade-0.3.2-py3-none-any.whl.
File metadata
- Download URL: free_apis_llm_cascade-0.3.2-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56f8accac10e72c4741bddd4120c963ef7d7e8353fe2a274b1df7f4d72a9f5f7
|
|
| MD5 |
a05c1edb04cec8707435cbd494cd3b83
|
|
| BLAKE2b-256 |
a58c697f051dc4b2ae0e0d7fd18d884b3ff65dc3228e78f7aa1f59d1465c425d
|
Provenance
The following attestation bundles were made for free_apis_llm_cascade-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on h-michaelson20/open-source-free-cascader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
free_apis_llm_cascade-0.3.2-py3-none-any.whl -
Subject digest:
56f8accac10e72c4741bddd4120c963ef7d7e8353fe2a274b1df7f4d72a9f5f7 - Sigstore transparency entry: 171345258
- Sigstore integration time:
-
Permalink:
h-michaelson20/open-source-free-cascader@f997f7c5807a921da2d96d353be7df390e6b6a8c -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/h-michaelson20
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f997f7c5807a921da2d96d353be7df390e6b6a8c -
Trigger Event:
release
-
Statement type: