Skip to main content

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


Download files

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

Source Distribution

free_apis_llm_cascade-0.3.2.tar.gz (50.5 kB view details)

Uploaded Source

Built Distribution

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

free_apis_llm_cascade-0.3.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

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

Hashes for free_apis_llm_cascade-0.3.2.tar.gz
Algorithm Hash digest
SHA256 20d281879bf270a1dfae5852e592e9375fbf304c7e2160de687e70e379a0db03
MD5 bf83690935c6719016e35df1634a6447
BLAKE2b-256 1f5ea38ceb7c89121d2a47f900637a043f667331cace2ee2d84d886b03ed698f

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file free_apis_llm_cascade-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for free_apis_llm_cascade-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 56f8accac10e72c4741bddd4120c963ef7d7e8353fe2a274b1df7f4d72a9f5f7
MD5 a05c1edb04cec8707435cbd494cd3b83
BLAKE2b-256 a58c697f051dc4b2ae0e0d7fd18d884b3ff65dc3228e78f7aa1f59d1465c425d

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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