Skip to content
Closed
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
25 changes: 15 additions & 10 deletions apps/website/scripts/check-models-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ import { join } from 'node:path'
import { workshopModels } from '@/config/workshop-browse-content'
import { getRouterWorkshopModelDetail } from '@/config/workshop-router-content'
import { auditExampleGallery } from './models-gallery-audit'
import { auditMediaLabels, auditModelPage } from './models-html-audit'
import {
auditMediaLabels,
auditModelDefinition,
auditModelPage
} from './models-html-audit'

const DIST = join(process.cwd(), 'dist')

function examplesOf(slug: string) {
function detailOf(slug: string) {
const detail = getRouterWorkshopModelDetail(slug)
if (!detail) throw new Error(`Missing model record: ${slug}`)
return detail.examples
return detail
}

const pagedModels = workshopModels.flatMap(({ href, name, slug }) =>
href === undefined ? [] : [{ href, name, slug }]
const pagedModels = workshopModels.flatMap(({ href, slug }) =>
href === undefined ? [] : [{ href, detail: detailOf(slug) }]
)

const errors = pagedModels.flatMap((model) => {
const html = readFileSync(join(DIST, model.href, 'index.html'), 'utf-8')
const errors = pagedModels.flatMap(({ href, detail }) => {
const html = readFileSync(join(DIST, href, 'index.html'), 'utf-8')
return [
...auditModelPage(html, model.name),
...auditModelPage(html, detail.name),
...auditModelDefinition(html, detail),
...auditMediaLabels(html),
...auditExampleGallery(html, examplesOf(model.slug).length)
].map((error) => `${model.href}: ${error}`)
...auditExampleGallery(html, detail.examples.length)
].map((error) => `${href}: ${error}`)
})

if (errors.length > 0) {
Expand Down
86 changes: 85 additions & 1 deletion apps/website/scripts/models-html-audit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { describe, expect, it } from 'vitest'

import { auditMediaLabels, auditModelPage } from './models-html-audit'
import type { RouterWorkshopModel } from '@/config/models-catalogue'

import {
auditMediaLabels,
auditModelDefinition,
auditModelPage
} from './models-html-audit'

const showcase = '<h1>Grok Imagine in <span>ComfyUI</span></h1>'
const related = (cards: string) =>
Expand Down Expand Up @@ -51,6 +57,84 @@ describe(auditModelPage, () => {
})
})

describe(auditModelDefinition, () => {
const model: RouterWorkshopModel = {
slug: 'bfl--flux-pro-fill--edit-images',
name: 'FLUX Pro Fill',
provider: 'Black Forest Labs',
task: 'image-to-image',
modality: 'image',
workflowCount: 0,
capabilities: [],
routerId: 'bfl/flux-pro-fill'
}
const sentence =
'FLUX Pro Fill is an image-to-image model from Black Forest Labs. You can call it through the Comfy Router API as bfl/flux-pro-fill.'
const definition = (text: string) =>
`<p class="text-sm" data-testid="model-definition">\n ${text}\n</p>`
const facts = (rows: string) =>
`<dl class="grid" data-testid="model-facts"><!--[-->${rows}<!--]--></dl>`
const routerRow = (routerId: string) =>
`<dt class="a">Router model ID</dt><dd class="b">${routerId}</dd>`
const wrongDefinition = (found: string) =>
`expected the definition ${JSON.stringify(sentence)}, found ${JSON.stringify(found)}`
const missingRouterRow =
'expected a "Router model ID" row reading bfl/flux-pro-fill'

it.for([
{
name: 'the sentence and the Router id row',
html:
definition(sentence) +
facts(`<dt>Provider</dt><dd>BFL</dd>${routerRow(model.routerId)}`),
errors: []
},
{
name: 'only the Router clause',
html:
definition(
'You can call it through the Comfy Router API as bfl/flux-pro-fill.'
) + facts(routerRow(model.routerId)),
errors: [
wrongDefinition(
'You can call it through the Comfy Router API as bfl/flux-pro-fill.'
)
]
},
{
name: 'a tampered first sentence',
html:
definition(sentence.replace('an image', 'a image')) +
facts(routerRow(model.routerId)),
errors: [wrongDefinition(sentence.replace('an image', 'a image'))]
},
{
name: 'an empty sentence and no facts',
html: definition('') + facts(''),
errors: [wrongDefinition(''), missingRouterRow]
},
{
name: 'the sentence only inside a template',
html: `<template>${definition(sentence)}${facts(routerRow(model.routerId))}</template>`,
errors: [wrongDefinition(''), missingRouterRow]
},
{
name: "another model's Router id",
html:
definition(sentence.replace('bfl/flux-pro-fill', 'bfl/flux-2-pro')) +
facts(routerRow('bfl/flux-2-pro')),
errors: [
wrongDefinition(
sentence.replace('bfl/flux-pro-fill', 'bfl/flux-2-pro')
),
missingRouterRow
]
}
])('$name', ({ html, errors }) => {
expect(auditModelDefinition(html, model)).toEqual(errors)
})
})

describe(auditMediaLabels, () => {
it.for([
{
Expand Down
32 changes: 32 additions & 0 deletions apps/website/scripts/models-html-audit.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { RouterWorkshopModel } from '@/config/models-catalogue'
import { modelDefinition } from '@/lib/workshop/model-definition'

const ENTITIES: Record<string, string> = {
'&amp;': '&',
'&lt;': '<',
Expand Down Expand Up @@ -39,6 +42,35 @@ export function auditModelPage(html: string, modelName: string): string[] {
return errors
}

function innerOf(html: string, tag: string, testId: string) {
return new RegExp(
`<${tag}\\b[^>]*data-testid="${testId}"[^>]*>([\\s\\S]*?)</${tag}>`
).exec(html)?.[1]
}

export function auditModelDefinition(
html: string,
model: RouterWorkshopModel
): string[] {
const { routerId } = model
const live = withoutHiddenMarkup(html)
const errors: string[] = []
const definition = textOf(innerOf(live, 'p', 'model-definition') ?? '')
const expected = modelDefinition(model)
if (definition !== expected)
errors.push(
`expected the definition ${JSON.stringify(expected)}, found ${JSON.stringify(definition)}`
)
const facts = innerOf(live, 'dl', 'model-facts') ?? ''
const routerRow =
/<dt\b[^>]*>\s*Router model ID\s*<\/dt>\s*<dd\b[^>]*>([\s\S]*?)<\/dd>/.exec(
facts
)?.[1]
if (routerRow === undefined || textOf(routerRow) !== routerId)
errors.push(`expected a "Router model ID" row reading ${routerId}`)
return errors
}

const PLACEHOLDER_LABEL = /^(?:Output|Sample \d+)$/

function attributeOf(tag: string, name: string): string | undefined {
Expand Down
28 changes: 28 additions & 0 deletions apps/website/src/components/workshop/ModelPage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ArrowRight } from '@lucide/vue'
import { cn } from '@comfyorg/tailwind-utils'
import { computed } from 'vue'

import { catalogSearch, useCaseFor } from '@/config/models-catalogue'
Expand All @@ -10,6 +11,7 @@ import type {
} from '@/config/models-catalogue'
import { formForContract } from '@/config/workshop-contract'
import { t } from '@/i18n/translations'
import { modelDefinition, modelFacts } from '@/lib/workshop/model-definition'
import CatalogueBackLink from './CatalogueBackLink.vue'
import ModelPrice from './ModelPrice.vue'
import ModelDetail from './ModelDetail.vue'
Expand Down Expand Up @@ -43,6 +45,8 @@ const model = computed(() =>
: page.model
)
const modelUseCase = computed(() => useCaseFor(page.model))
const definition = computed(() => modelDefinition(page.model))
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved
const facts = computed(() => modelFacts(page.model))
const pillClass =
'inline-flex h-7 items-center rounded-full border border-transparency-white-t20 px-3 text-xs leading-none text-primary-comfy-canvas transition-colors hover:border-primary-comfy-yellow hover:text-primary-comfy-yellow'
const restTags = computed(() =>
Expand Down Expand Up @@ -85,12 +89,36 @@ const restTags = computed(() =>
<h1 class="text-3xl font-bold text-primary-comfy-canvas lg:text-4xl">
{{ page.model.name }}
</h1>
<p
class="text-sm/relaxed text-primary-warm-gray"
data-testid="model-definition"
>
{{ definition }}
</p>
<p
v-if="page.model.summary"
class="text-sm/relaxed text-primary-warm-gray"
>
{{ page.model.summary }}
</p>
<dl
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved
class="m-0 grid grid-cols-[8rem_minmax(0,1fr)] items-baseline gap-x-3 gap-y-1 text-sm/relaxed"
data-testid="model-facts"
>
<template v-for="fact in facts" :key="fact.term">
Comment thread
MaanilVerma marked this conversation as resolved.
Resolved
<dt class="text-primary-warm-gray">{{ fact.term }}</dt>
<dd
:class="
cn(
'm-0 min-w-0 wrap-break-word text-primary-warm-white',
fact.mono && 'font-mono text-xs/relaxed'
)
"
>
{{ fact.value }}
</dd>
</template>
</dl>
</div>

<div class="flex flex-col gap-4 lg:items-end">
Expand Down
Loading
Loading