Skip to main content

Dagster integration with Not Diamond

Project description

Dagster resource for 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.

Installation

pip install dagster-contrib-notdiamond

Configuration

Make sure you have followed the steps in the Quickstart docs, and added a Not Diamond API key to your environment.

Usage

Define a resource for Not Diamond, then create the asset or ops:

from dagster import (
    AssetExecutionContext,
    Definitions,
    EnvVar,
    GraphDefinition,
    OpExecutionContext,
    asset,
    define_asset_job,
    op,
)
from dagster_contrib_notdiamond import NotDiamondResource

@op
def notdiamond_op(context: OpExecutionContext, notdiamond: NotDiamondResource):
    with notdiamond.get_client(context) as client:
        session_id, best_llm = client.model_select(
            models=["openai/gpt-4o", "openai/gpt-4o-mini"],
            messages=[{"role": "user", "content": "Say this is a test"}]
        )
    return session_id, str(best_llm)

notdiamond_op_job = GraphDefinition(name="notdiamond_op_job", node_defs=[notdiamond_op]).to_job()

# Or if creating an asset:
@asset(compute_kind="NotDiamond")
def notdiamond_asset(context: AssetExecutionContext, notdiamond: NotDiamondResource) -> Tuple[str, str]:
    with notdiamond.get_client(context) as client:
        session_id, best_llm = client.model_select(
            model=["openai/gpt-4o", "openai/gpt-4o-mini"],
            messages=[{"role": "user", "content": "Say this is a test"}]
        )
    return session_id, str(best_llm)

notdiamond_asset_job = define_asset_job(name="notdiamond_asset_job", selection="notdiamond_asset")

defs = Definitions(
    assets=[notdiamond_asset],
    jobs=[notdiamond_asset_job, notdiamond_op_job],
    resources={
        "notdiamond": NotDiamondResource(api_key=EnvVar("NOTDIAMOND_API_KEY")),
    },
)

Please refer to example_job/example_notdiamond.py for an example script.

Support

Visit the documentation for Not Diamond or send a message to support@notdiamond.ai

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

dagster_contrib_notdiamond-0.0.1.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file dagster_contrib_notdiamond-0.0.1.tar.gz.

File metadata

File hashes

Hashes for dagster_contrib_notdiamond-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bb4309b012001e29acbdc790023281349317241c080a73dbaa3ad719a7cef3ee
MD5 9576265f974aab3f25b9916c81518616
BLAKE2b-256 19c79841ee4afd8f4da0c302a3f4edfd053a2cc97ac2e50e78c2ee292740074d

See more details on using hashes here.

File details

Details for the file dagster_contrib_notdiamond-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dagster_contrib_notdiamond-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1216e3958dceddd8001238db602dddd836ee525ae28444d04fdaf95f2382fc25
MD5 37925eed465d81901a033bb365da0901
BLAKE2b-256 e98183d1863a7dcc518b8ddf9d544d9da00688b32954a3e6b714b3de31f8e419

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