Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/publish-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish SDK

on:
workflow_dispatch:
inputs:
bump:
description: "Semver bump for the release"
type: choice
options: [patch, minor, major]
default: patch
schedule:
# Daily data release, after the hourly model syncs have merged.
- cron: "23 5 * * *"

concurrency: publish-sdk

jobs:
publish:
if: github.repository == 'anomalyco/models.dev'
runs-on: ubuntu-latest
permissions:
contents: write # push sdk-v* tags on manual releases
id-token: write # npm trusted publishing (OIDC) + provenance
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: dev

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org

- name: Install dependencies
run: bun install

- name: Validate models
run: bun validate

- name: SDK tests
run: bun run test
working-directory: packages/sdk

- name: Publish
id: publish
run: >
bun script/publish.ts
--bump=${{ inputs.bump || 'patch' }}
${{ github.event_name == 'schedule' && '--if-changed' || '' }}
working-directory: packages/sdk

- name: Tag release
if: github.event_name == 'workflow_dispatch' && steps.publish.outputs.version != ''
run: |
git tag "sdk-v${{ steps.publish.outputs.version }}"
git push origin "sdk-v${{ steps.publish.outputs.version }}"
4 changes: 4 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:

- name: Run validation script
run: bun validate

- name: SDK tests
run: bun run test
working-directory: packages/sdk
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist
.sync/
node_modules
.opencode/package-lock.json
packages/sdk/src/snapshot.js
72 changes: 68 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "models.dev",
"name": "@models.dev/core",
"version": "0.0.0",
"private": true,
"$schema": "https://json.schemastore.org/package.json",
"type": "module",
"dependencies": {
Expand Down
8 changes: 5 additions & 3 deletions packages/core/script/generate-ollama-cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ function modelFileName(modelName: string): string {
return modelName + ".toml";
}

type OllamaModel = Omit<Model, "id"> & {
limit: Model["limit"] & { output?: number };
type OllamaModel = Omit<Model, "id" | "description" | "release_date" | "limit"> & {
description?: Model["description"];
release_date?: Model["release_date"];
limit: Omit<Model["limit"], "output"> & { output?: number };
};

type ComparableModel = Pick<Model,
Expand All @@ -47,7 +49,7 @@ type ComparableModel = Pick<Model,
limit: Pick<Model["limit"], "context">;
};

function normalizeForComparison(model: Omit<Model, "id">): ComparableModel {
function normalizeForComparison(model: OllamaModel | Omit<Model, "id">): ComparableModel {
return {
name: model.name,
attachment: model.attachment,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./schema.js";
export * from "./generate.js";
export * from "./describe.js";
export * from "./family.js";
6 changes: 5 additions & 1 deletion packages/core/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ const ModelBase = z.object({
.optional(),
});

function refineModel<T extends z.ZodTypeAny>(schema: T) {
function refineModel<
Output extends z.infer<typeof ModelShape> | z.infer<typeof AuthoredModelShape>,
Def extends z.ZodTypeDef,
Input,
>(schema: z.ZodType<Output, Def, Input>) {
return schema
.refine(
(data) => {
Expand Down
18 changes: 11 additions & 7 deletions packages/core/src/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,10 @@ function sortReasoningValues(values: Array<string | null>) {
export function formatToml(model: z.infer<typeof SyncedAuthoredModel>) {
const lines: string[] = [];

if (model.base_model !== undefined) lines.push(`base_model = ${quote(model.base_model)}`);
if (model.base_model_omit !== undefined) {
if ("base_model" in model && model.base_model !== undefined) {
lines.push(`base_model = ${quote(model.base_model)}`);
}
if ("base_model_omit" in model && model.base_model_omit !== undefined) {
lines.push(`base_model_omit = [${model.base_model_omit.map(quote).join(", ")}]`);
}
if (model.name !== undefined) lines.push(`name = ${quote(model.name)}`);
Expand Down Expand Up @@ -781,8 +783,8 @@ export function formatToml(model: z.infer<typeof SyncedAuthoredModel>) {

if (model.cost !== undefined) {
lines.push("", "[cost]");
lines.push(`input = ${formatNumber(model.cost.input)}`);
lines.push(`output = ${formatNumber(model.cost.output)}`);
if (model.cost.input !== undefined) lines.push(`input = ${formatNumber(model.cost.input)}`);
if (model.cost.output !== undefined) lines.push(`output = ${formatNumber(model.cost.output)}`);
if (model.cost.reasoning !== undefined) {
lines.push(`reasoning = ${formatNumber(model.cost.reasoning)}`);
}
Expand All @@ -801,9 +803,11 @@ export function formatToml(model: z.infer<typeof SyncedAuthoredModel>) {

for (const tier of model.cost.tiers ?? []) {
lines.push("", "[[cost.tiers]]");
lines.push(`tier = { type = ${quote(tier.tier.type ?? "context")}, size = ${formatInteger(tier.tier.size)} }`);
lines.push(`input = ${formatNumber(tier.input)}`);
lines.push(`output = ${formatNumber(tier.output)}`);
if (tier.tier?.size !== undefined) {
lines.push(`tier = { type = ${quote(tier.tier.type ?? "context")}, size = ${formatInteger(tier.tier.size)} }`);
}
if (tier.input !== undefined) lines.push(`input = ${formatNumber(tier.input)}`);
if (tier.output !== undefined) lines.push(`output = ${formatNumber(tier.output)}`);
if (tier.reasoning !== undefined) lines.push(`reasoning = ${formatNumber(tier.reasoning)}`);
if (tier.cache_read !== undefined) lines.push(`cache_read = ${formatNumber(tier.cache_read)}`);
if (tier.cache_write !== undefined) lines.push(`cache_write = ${formatNumber(tier.cache_write)}`);
Expand Down
Loading
Loading