Skip to main content

A unified library for interacting with various AI APIs through a standardized interface.

Project description

SwitchAI

SwitchAI is a lightweight and flexible library that provides a standardized interface for interacting with various AI APIs like OpenAI, Anthropic, Mistral, and more. With SwitchAI, you can easily switch between AI providers or use multiple APIs simultaneously, all with a simple and consistent interface.

Installation

Install with pip:

pip install switchai  

Getting Started

To use SwitchAI, you will need API keys for the AI providers you intend to interact with. You can set these keys either as environment variables or pass them as configuration to the SwitchAI client.

If you choose to use environment variables, ensure you follow the naming conventions for each provider as outlined in the documentation.

Example Usage

Chat

from switchai import SwitchAI

# Initialize the client with the desired AI model
client = SwitchAI(provider="openai", model_name="gpt-4o")

# Send a message and receive a response
response = client.chat(
    messages=[
        {"role": "user", "content": "Hello, how are you?"}
    ]
)

# Print the response
print(response)

Text Embedding

from switchai import SwitchAI

# Initialize the client with the chosen embedding model
client = SwitchAI(provider="google", model_name="models/text-embedding-004")

# Generate embeddings for a list of text inputs
response = client.embed(
    input=[
        "I am feeling great today!",
        "I am feeling sad today."
    ]
)

# Print the response
print(response)

Speech to text

from switchai import SwitchAI

# Initialize the client with the desired speech-to-text model
client = SwitchAI(provider="deepgram", model_name="nova-2")

# Transcribe an audio file
response = client.transcribe(
    audio_path="path/to/audio/file.wav"
)

# Print the response
print(response)

Documentation

For full documentation, visit SwitchAI Documentation.

Contributing

Contributions are always welcome! If you'd like to help enhance SwitchAI, feel free to make a contribution.

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

switchai-0.2.3.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

switchai-0.2.3-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file switchai-0.2.3.tar.gz.

File metadata

  • Download URL: switchai-0.2.3.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for switchai-0.2.3.tar.gz
Algorithm Hash digest
SHA256 53a5312c7db6b38012f2e214c99621f4a940ce808d9c7063e6ff69064b3319b7
MD5 af8db69b1a83d51e17de03b728a6cae1
BLAKE2b-256 0432358d260a960bebf9d1486e3f073bed7bccb7a78eda1fea4df066e15fdb30

See more details on using hashes here.

File details

Details for the file switchai-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: switchai-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for switchai-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 46321ddc2832dfc833d0d62d17ae9e84a953c51ef3a2f3dc884f9f7d75ab6c58
MD5 0c7b4f6a68b8804509a9f3126f9bb278
BLAKE2b-256 ca794c925a58efeb5f64bd095f29762f3ef4f1d06a70ba51e78f11758365bec6

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