-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for AI model routing with Not Diamond. (#23)
* initial * rename to dagster-contrib-notdiamond * feedback from colton * forgot to save pyproject * test run * Docs and example job * fixing expected user_agent param * make ruff * add setuptools configuration --------- Co-authored-by: Colton Padden <[email protected]>
- Loading branch information
Showing
13 changed files
with
3,439 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
.github/workflows/quality-check-dagster-contrib-notdiamond.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: quality-check-dagster-contrib-notdiamond | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
paths: | ||
- 'libraries/dagster-contrib-notdiamond/**' | ||
|
||
jobs: | ||
check: | ||
uses: ./.github/workflows/template-quality-check.yml | ||
with: | ||
working_directory: ./libraries/dagster-contrib-notdiamond |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: build-and-release-dagster-contrib-notdiamond | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'dagster_contrib_notdiamond-*.*.*' | ||
|
||
jobs: | ||
build-and-release-dagster-contrib-notdiamond: | ||
uses: ./.github/workflows/template-release.yml | ||
with: | ||
library_name: dagster-contrib-notdiamond | ||
working_directory: ./libraries/dagster-contrib-notdiamond | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Changelog | ||
--- | ||
|
||
## [0.1.0] - Initial Release, 2024-10-30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
install: | ||
uv sync | ||
|
||
build: | ||
uv build | ||
|
||
test: | ||
uv run pytest | ||
|
||
ruff: | ||
uv run ruff check --fix . | ||
uv run ruff format . | ||
|
||
check: | ||
uv run pyright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# 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 | ||
|
||
```bash | ||
pip install dagster-contrib-notdiamond | ||
``` | ||
|
||
## Configuration | ||
|
||
Make sure you have followed the steps in the [Quickstart docs][quickstart], and added a Not Diamond API key to your environment. | ||
|
||
## Usage | ||
|
||
Define a resource for Not Diamond, then create the asset or ops: | ||
|
||
```python | ||
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][docs] or send a message to [[email protected]][mailto] | ||
|
||
[docs]: https://docs.notdiamond.ai | ||
[mailto]: mailto:[email protected] | ||
[quickstart]: https://docs.notdiamond.ai/docs/quickstart |
4 changes: 4 additions & 0 deletions
4
libraries/dagster-contrib-notdiamond/dagster_contrib_notdiamond/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from dagster_contrib_notdiamond.resources import ( | ||
NotDiamondResource as NotDiamondResource, | ||
with_usage_metadata as with_usage_metadata, | ||
) |
1 change: 1 addition & 0 deletions
1
libraries/dagster-contrib-notdiamond/dagster_contrib_notdiamond/py.typed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
partial |
Oops, something went wrong.