Skip to content
Merged
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
59 changes: 59 additions & 0 deletions .github/workflows/catalog-listing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish Inference catalog listing

# The catalog listing (catalog/listing.yaml + catalog/screenshots) is
# presentation only: a change never implies a release. On main it replaces the
# listing of the entry the catalog already records and requests a publication.

on:
push:
branches: [main]
paths:
- catalog/listing.yaml
- catalog/screenshots/**
- hack/catalog-listing.ts
- .github/workflows/catalog-listing.yml
workflow_dispatch:

permissions:
contents: read

# Shares the writer with the release publisher: one read/merge/PUT at a time.
concurrency:
group: inference-catalog-publish
cancel-in-progress: false

jobs:
listing:
if: github.repository == 'appthrust/inference'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
with:
bun-version: 1.4.1
- name: Validate the listing
run: bun hack/publish-entry.ts validate-listing
- name: Submit the listing
id: catalog
env:
CLOUD_API_URL: ${{ vars.CLOUD_API_URL || 'https://api.appthrust.com' }}
CLOUD_CATALOG_ADMIN_TOKEN: ${{ secrets.CLOUD_CATALOG_ADMIN_TOKEN }}
run: bun hack/publish-entry.ts listing
- name: Mint the Cloud workflow dispatch token
if: steps.catalog.outputs.state == 'snapshot'
id: cloud-token
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2
with:
app-id: ${{ secrets.APPTHRUST_GITHUB_ACTIONS_APP_ID }}
private-key: ${{ secrets.APPTHRUST_GITHUB_ACTIONS_APP_PRIVATE_KEY }}
owner: appthrust
repositories: cloud
- name: Dispatch Cloud catalog publication
if: steps.catalog.outputs.state == 'snapshot'
env:
GH_TOKEN: ${{ steps.cloud-token.outputs.token }}
SNAPSHOT_ID: ${{ steps.catalog.outputs.snapshot_id }}
run: gh api -X POST repos/appthrust/cloud/dispatches -f event_type=catalog-publish -f "client_payload[snapshot_id]=$SNAPSHOT_ID"
90 changes: 90 additions & 0 deletions catalog/listing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
locales:
en:
title: Inference
tagline: Generate chat replies on a GPU inside your Project, called with the same requests your apps already send to OpenAI-compatible APIs.
overview: |
Inference serves chat completions from Qwen2.5-0.5B-Instruct, a small instruction-tuned model, on a GPU inside your Project. It is for teams that want their own apps to generate text without sending prompts to an outside AI service.

Apps call it the way they call any OpenAI-compatible API: POST /v1/chat/completions returns a reply, streamed piece by piece when the request asks for streaming, and GET /v1/models returns the model name together with its prompt budget. The model field can be left out; Inference fills it in.

When AI Gateway is installed in the same Project, it can route chat requests to Inference as a Project-local provider under the Project AI policy. A request may use up to 3,072 prompt tokens, with 1,024 tokens kept for the reply. Up to four completions run at the same time, and a request stops after 120 seconds.

Inference needs a GPU node. Each branch uses one NVIDIA GPU, so production plus staging uses two; the install dialog shows the count before anything starts. The model ships inside the app and runs without internet access, so prompts and replies are processed inside the Project. Inference has no screen of its own: you install, update and remove it from the Marketplace.
ja:
title: Inference
tagline: OpenAI 互換の API と同じ呼び出し方で、プロジェクト内の GPU を使ったチャット応答をアプリから生成できます。
overview: |
Inference は、指示応答向けの小型モデル Qwen2.5-0.5B-Instruct を使い、プロジェクト内の GPU でチャット応答を返すアプリです。プロンプトを外部の AI サービスに送らずに、自分たちのアプリで文章を生成したいチーム向けです。

アプリからは、OpenAI 互換の API と同じ方法で呼び出します。POST /v1/chat/completions で応答を受け取り、ストリーミングを指定すると少しずつ返ってきます。GET /v1/models では、モデル名とプロンプトに使えるトークン数が分かります。リクエストで model を省略しても、Inference が補います。

同じプロジェクトに AI Gateway を入れている場合は、プロジェクトの AI ポリシーに沿って、AI Gateway がチャットのリクエストをプロジェクト内のプロバイダーとして Inference に振り分けられます。1 回のリクエストで使えるプロンプトは 3,072 トークンまでで、応答用に 1,024 トークンを確保しています。同時に処理する応答は 4 件までで、1 件あたり 120 秒で打ち切られます。

Inference には GPU ノードが必要です。ブランチごとに NVIDIA GPU を 1 基使うため、本番とステージングの両方を動かすと 2 基になります。必要な数はインストール前のダイアログに表示されます。モデルはアプリに同梱されていてインターネットに接続せずに動くので、プロンプトと応答はプロジェクトの中で処理されます。Inference に専用の画面はなく、インストール・更新・削除はマーケットプレイスから行います。
highlights:
- screenshot: marketplace-detail
locales:
en:
title: OpenAI-compatible chat API
body: Existing code for OpenAI-compatible APIs works with /v1/chat/completions and /v1/models. Replies can be streamed, and the model name can be omitted.
ja:
title: OpenAI 互換のチャット API
body: OpenAI 互換の API 向けに書いたコードを、そのまま /v1/chat/completions と /v1/models に向けられます。応答はストリーミングでも受け取れ、モデル名は省略できます。
- screenshot: install-gpu
locales:
en:
title: See the GPU count before installing
body: The install dialog lists the NVIDIA GPUs each branch needs and the total, so you know what the Project must provide before the app starts.
ja:
title: 必要な GPU をインストール前に確認
body: インストールのダイアログに、ブランチごとに必要な NVIDIA GPU の数と合計が表示されます。アプリを動かす前に、プロジェクトに用意すべき数が分かります。
- screenshot: install-production-only
locales:
en:
title: One GPU with production only
body: Staging runs as a separate copy with its own GPU. Choose production only to run a single copy on one GPU.
ja:
title: 本番だけなら GPU は 1 基
body: ステージングは専用の GPU を使う別のコピーとして動きます。「本番のみ」を選ぶと、1 基の GPU で 1 つだけ動かせます。
- screenshot: version-select
locales:
en:
title: Pin a version or follow updates
body: Pick the version at install time and either keep it pinned or let new versions in the same release line install automatically.
ja:
title: バージョンは固定も自動更新も選べます
body: インストール時にバージョンを選び、そのまま固定するか、同じリリースラインの新しいバージョンを自動で入れるかを決められます。
- screenshot: catalog-card
locales:
en:
title: Stays inside the Project
body: The model ships with the app and runs without internet access. With AI Gateway installed, chat requests can be routed to Inference under the Project AI policy.
ja:
title: プロジェクトの中で完結
body: モデルはアプリに同梱されており、インターネットに接続せずに動きます。AI Gateway を入れていれば、プロジェクトの AI ポリシーに沿ってチャットのリクエストを Inference に振り分けられます。
screenshots:
- name: marketplace-detail
file: marketplace-detail.webp
alt:
en: "Dashboard Marketplace page for Inference: the Assist badge, the description of OpenAI-compatible chat completions with Qwen2.5-0.5B-Instruct that requires a GPU, an Install button, and versions 0.1.0 and 0.2.0 (default)."
ja: "ダッシュボードのマーケットプレイスにある Inference のページ。Assist のバッジ、Qwen2.5-0.5B-Instruct による OpenAI 互換のチャット応答で GPU が必要という説明、インストールボタン、バージョン 0.1.0 と 0.2.0(既定)が並んでいます。"
- name: install-gpu
file: install-gpu.webp
alt:
en: "Install dialog for Inference with version 0.2.0, pinned updates and production plus staging selected; the accelerator table shows 1 NVIDIA GPU for production, 1 for staging, 2 in total."
ja: "Inference のインストールダイアログ。バージョン 0.2.0、バージョンを固定、本番とステージングを選んだ状態で、アクセラレータ欄に本番 1 NVIDIA GPU、ステージング 1 NVIDIA GPU、合計 2 NVIDIA GPU と表示されています。"
- name: install-production-only
file: install-production-only.webp
alt:
en: "The same install dialog with production only selected; the accelerator table now shows 1 NVIDIA GPU for production and 1 in total."
ja: "同じインストールダイアログで「本番のみ」を選んだ状態。アクセラレータ欄は本番 1 NVIDIA GPU、合計 1 NVIDIA GPU に変わっています。"
- name: version-select
file: version-select.webp
alt:
en: "Version menu open in the install dialog, listing 0.1.0 and 0.2.0 (recommended) with 0.2.0 checked, above the pinned-version and branch options."
ja: "インストールダイアログでバージョンの一覧を開いた状態。0.1.0 と 0.2.0(推奨)が並び、0.2.0 にチェックが付いています。下にはバージョン固定とブランチの選択肢があります。"
- name: catalog-card
file: catalog-card.webp
alt:
en: "Catalog section of the Marketplace: AI Gateway and Embedding marked as installed, and the Inference card showing version 0.2.0, follow or pin updates, and an Install button."
ja: "マーケットプレイスのカタログ欄。AI Gateway と Embedding はインストール済みで、Inference のカードにはバージョン 0.2.0、更新方法(自動で更新 / バージョンを固定)、インストールボタンが表示されています。"
Binary file added catalog/screenshots/catalog-card.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added catalog/screenshots/install-gpu.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added catalog/screenshots/install-production-only.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added catalog/screenshots/marketplace-detail.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added catalog/screenshots/version-select.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/appthrust/inference
go 1.26.0

require (
github.com/appthrust/appserver-go v0.1.0
github.com/appthrust/appserver-go v0.3.0
github.com/stretchr/testify v1.11.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/appthrust/appserver-go v0.1.0 h1:MYpkwwm4wqa+YcKe1AwywcRe9xuUtTooK4+o7Z5Jbqo=
github.com/appthrust/appserver-go v0.1.0/go.mod h1:0KSf9RQZ6OxBcE0lxYzzjKF37nfwbKps3wXUGlE0oFo=
github.com/appthrust/appserver-go v0.3.0 h1:zxOz0hkspZSXjLq3KWGDLkZIz42Jag6wqRujZ8lTru0=
github.com/appthrust/appserver-go v0.3.0/go.mod h1:0KSf9RQZ6OxBcE0lxYzzjKF37nfwbKps3wXUGlE0oFo=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
Expand Down
130 changes: 130 additions & 0 deletions hack/catalog-listing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { describe, expect, test } from 'bun:test'
import { createHash } from 'node:crypto'
import { mkdtemp, mkdir, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
import { imageDimensions, loadListing, uploadMedia, validateListing, type Listing } from './catalog-listing'
import { renderEntry, renderListingUpdate, type CatalogEntry } from './publish-entry'

/** Minimal valid PNG: 8-byte signature + IHDR chunk; dimensions only, no pixel data. */
function png(width: number, height: number): Uint8Array {
const bytes = new Uint8Array(33)
bytes.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], 0)
const view = new DataView(bytes.buffer)
view.setUint32(8, 13)
bytes.set([0x49, 0x48, 0x44, 0x52], 12)
view.setUint32(16, width)
view.setUint32(20, height)
return bytes
}

function webpVP8X(width: number, height: number): Uint8Array {
const bytes = new Uint8Array(30)
bytes.set([0x52, 0x49, 0x46, 0x46], 0)
bytes.set([0x57, 0x45, 0x42, 0x50], 8)
bytes.set([0x56, 0x50, 0x38, 0x58], 12)
const w = width - 1, h = height - 1
bytes.set([w & 0xff, (w >> 8) & 0xff, (w >> 16) & 0xff], 24)
bytes.set([h & 0xff, (h >> 8) & 0xff, (h >> 16) & 0xff], 27)
return bytes
}

const listing: Listing = {
locales: {
en: { tagline: 'People, groups and profiles.', overview: 'Who is who.\n\nSearch and browse.' },
ja: { tagline: 'この組織のメンバー、グループ、プロフィール。', overview: '誰が誰か。' },
},
highlights: [{ locales: { en: { title: 'Search' }, ja: { title: '検索' } }, screenshot: 'people' }],
screenshots: [{
name: 'people', digest: `sha256:${'a'.repeat(64)}`, mediaType: 'image/png', size: 33, width: 1280, height: 800,
alt: { en: 'People list', ja: 'メンバー一覧' },
}],
}

describe('imageDimensions', () => {
test('reads PNG IHDR and WebP VP8X', () => {
expect(imageDimensions(png(1280, 800))).toEqual({ mediaType: 'image/png', width: 1280, height: 800 })
expect(imageDimensions(webpVP8X(1440, 900))).toEqual({ mediaType: 'image/webp', width: 1440, height: 900 })
expect(() => imageDimensions(new Uint8Array(40))).toThrow('PNG or WebP')
})
})

describe('validateListing', () => {
test('accepts the sample and enforces the contract', () => {
expect(() => validateListing(listing)).not.toThrow()
expect(() => validateListing({ locales: { ja: { tagline: 'x' } } })).toThrow('requires the "en" locale')
expect(() => validateListing({ ...listing, highlights: [{ locales: { en: { title: 'x' } }, screenshot: 'missing' }] }))
.toThrow('unknown screenshot "missing"')
expect(() => validateListing({ ...listing, screenshots: [{ ...listing.screenshots![0], size: 600_000 }] })).toThrow('bytes')
expect(() => validateListing({ ...listing, screenshots: [{ ...listing.screenshots![0], alt: { ja: 'x' } }] })).toThrow('requires the "en" locale')
expect(() => validateListing({ locales: { en: { tagline: 'x'.repeat(201) } } })).toThrow('exceeds 200')
})
})

describe('loadListing', () => {
test('resolves screenshot files to digests, sizes and dimensions', async () => {
const dir = await mkdtemp(join(tmpdir(), 'listing-'))
await mkdir(join(dir, 'screenshots'))
const image = png(1200, 750)
await writeFile(join(dir, 'screenshots', 'people.png'), image)
await writeFile(join(dir, 'listing.yaml'), [
'locales:', ' en: { tagline: People, groups and profiles. }', ' ja: { tagline: メンバー一覧 }',
'highlights:', ' - screenshot: people', ' locales: { en: { title: Search }, ja: { title: 検索 } }',
'screenshots:', ' - name: people', ' file: people.png', ' alt: { en: People list, ja: メンバー一覧 }',
].join('\n'))
const { listing: loaded, media } = await loadListing(pathToFileURL(`${dir}/`))
const digest = `sha256:${createHash('sha256').update(image).digest('hex')}`
expect(media).toHaveLength(1)
expect(media[0].bytes).toEqual(image)
expect(loaded.screenshots).toEqual([{ name: 'people', digest, mediaType: 'image/png', size: 33, width: 1200, height: 750, alt: { en: 'People list', ja: 'メンバー一覧' } }])
expect(loaded.highlights?.[0].screenshot).toBe('people')
})

test('rejects paths escaping catalog/screenshots', async () => {
const dir = await mkdtemp(join(tmpdir(), 'listing-'))
await writeFile(join(dir, 'listing.yaml'), 'locales: { en: { tagline: x } }\nscreenshots: [{ name: a, file: ../x.png, alt: { en: a } }]\n')
await expect(loadListing(pathToFileURL(`${dir}/`))).rejects.toThrow('relative path')
})
})

describe('uploadMedia', () => {
test('PUTs each blob by hex digest and checks the stored descriptor', async () => {
const image = png(10, 10)
const digest = `sha256:${createHash('sha256').update(image).digest('hex')}`
const calls: Array<{ url: string; type: string }> = []
const fetcher = async (url: string, init: RequestInit): Promise<Response> => {
calls.push({ url, type: (init.headers as Record<string, string>)['content-type'] })
return Response.json({ digest, mediaType: 'image/png', size: 33 })
}
await uploadMedia([{ ...listing.screenshots![0], digest, bytes: image }], 'https://api.example', 'token', fetcher)
expect(calls).toEqual([{ url: `https://api.example/api/v1/catalog/media/${digest.slice(7)}`, type: 'image/png' }])
const mismatch = async (): Promise<Response> => Response.json({ digest, mediaType: 'image/png', size: 1 })
await expect(uploadMedia([{ ...listing.screenshots![0], digest, bytes: image }], 'https://api.example', 'token', mismatch))
.rejects.toThrow('does not match')
})
})

describe('listing in entries', () => {
const template = [
'apiVersion: appthrust.io/v1alpha1', 'kind: ApplicationStackDefinition', 'metadata: { name: inference }',
'spec:', ' display: { title: Directory, description: People., category: collaborate, iconRef: { name: inference } }',
' versions: []', ' updatePolicy: { default: pinned, allowed: [pinned, follow] }',
].join('\n')
const digest = `sha256:${'b'.repeat(64)}`

test('renderEntry carries the authored listing and otherwise preserves the stored one', () => {
const first = renderEntry(template, '0.2.0', digest, undefined, listing)
expect(first.listing).toEqual(listing)
const next = renderEntry(template, '0.2.1', `sha256:${'c'.repeat(64)}`, first)
expect(next.listing).toEqual(listing)
expect(renderEntry(template, '0.2.0', digest).listing).toBeUndefined()
})

test('renderListingUpdate replaces only the listing', () => {
const current: CatalogEntry = { ...renderEntry(template, '0.2.0', digest), publishedAt: '2026-11-01T00:00:00Z' }
const updated = renderListingUpdate(current, listing)
expect(updated).toEqual({ ...current, listing })
expect(() => renderListingUpdate({ ...current, slug: 'other' }, listing)).toThrow('slug inference')
})
})
Loading