Skip to main content

Not Diamond Python SDK

Project description

Getting started with Not Diamond

Not Diamond is an AI model router that automatically determines which LLM is best-suited to respond to any query, improving LLM output quality by combining multiple LLMs into a meta-model that learns when to call each LLM.

Key features

Installation

Python: Requires Python 3.10+. It’s recommended that you create and activate a virtualenv prior to installing the package. For this example, we'll be installing the optional additional create dependencies, which you can learn more about here.

pip install notdiamond[create]

Setting up

Create a .env file with your Not Diamond API key and the API keys of the models you want to route between:

NOTDIAMOND_API_KEY = "YOUR_NOTDIAMOND_API_KEY"
OPENAI_API_KEY = "YOUR_OPENAI_API_KEY"
ANTHROPIC_API_KEY = "YOUR_ANTHROPIC_API_KEY"

Sending your first Not Diamond API request

Create a new file in the same directory as your .env file and copy and run the code below (you can toggle between Python and TypeScript in the top left of the code block):

from notdiamond import NotDiamond

# Define the Not Diamond routing client
client = NotDiamond()

# The best LLM is determined by Not Diamond based on the messages and specified models
result, session_id, provider = client.chat.completions.create(
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Concisely explain merge sort."}  # Adjust as desired
    ],
    model=['openai/gpt-3.5-turbo', 'openai/gpt-4o', 'anthropic/claude-3-5-sonnet-20240620']
)

print("ND session ID: ", session_id)  # A unique ID of Not Diamond's recommendation
print("LLM called: ", provider.model)  # The LLM routed to
print("LLM output: ", result.content)  # The LLM response

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

notdiamond-0.3.3.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

notdiamond-0.3.3-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file notdiamond-0.3.3.tar.gz.

File metadata

  • Download URL: notdiamond-0.3.3.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Linux/6.10.1-arch1-1

File hashes

Hashes for notdiamond-0.3.3.tar.gz
Algorithm Hash digest
SHA256 08d1e0e6f0811498a42b31499956b1548cd9ad9db472ab6b668e7f50d167dba2
MD5 97ff017e2f06d27a6710d1b3cbabce1c
BLAKE2b-256 434fd4564fd889056a04edf1320db5bf9da178a1f28f99da52f268a3066ff7e8

See more details on using hashes here.

File details

Details for the file notdiamond-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: notdiamond-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 27.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.7 Linux/6.10.1-arch1-1

File hashes

Hashes for notdiamond-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 00c6c7e2e88372bf856dc131e0185cb95c99b2eebd3f0660072a0025553ba06e
MD5 f177a27034935291f3c14df4d30c69e0
BLAKE2b-256 9cbe90f6ed8837340661fb3d84d8ad13f059c3c55db53e1dc3b63d3c23d9b926

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page