Skip to content

Commit

Permalink
More clearly show task types + common names with actual model name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Nov 12, 2024
1 parent 66bb8a0 commit 91bc8a7
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions AiServer/wwwroot/mjs/components/MediaProviders.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const SelectModels = {
<label :for="'chk-' + key"
:class="{'opacity-50': !isModelSelectable(model)}"
class="font-medium text-gray-900">
{{ key }}
{{model.commonNames}}
</label>
<div class="flex gap-x-2 text-xs text-gray-500">
<span>{{ getSupportedTasks(model) }}</span>
Expand All @@ -66,6 +66,9 @@ const SelectModels = {
Not Available
</span>
</div>
<div class="text-xs text-gray-500">
<span>{{ key }}</span>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -102,15 +105,34 @@ const SelectModels = {
})

const transformModelData = (data, providerId = "ComfyUI") => {
return data.results.reduce((acc, entry) => {
// First pass: Map through all entries to collect commonNames
const mappedEntries = data.results.map(entry => {
// Create a copy to avoid mutating the original entry
const mappedEntry = { ...entry }
// Initialize commonNames with the entry's id
mappedEntry.commonNames = entry.id
return mappedEntry
})

// Second pass: Reduce to final structure while merging commonNames
return mappedEntries.reduce((acc, entry) => {
if (entry.apiModels && entry.apiModels[providerId]) {
const modelName = entry.apiModels[providerId]
// Only update if there's no existing entry OR if current entry has supportedTasks
// and existing entry doesn't have supportedTasks
if (!acc[modelName] ||
(entry.supportedTasks?.[providerId] &&
!acc[modelName].supportedTasks?.[providerId])) {

if (!acc[modelName]) {
// First occurrence of this model
acc[modelName] = entry
} else {
// Model exists, update commonNames and check for supportedTasks
acc[modelName].commonNames += `, ${entry.id}`

// Replace entire entry if current one has supportedTasks and existing one doesn't
if (entry.supportedTasks?.[providerId] &&
!acc[modelName].supportedTasks?.[providerId]) {
const existingCommonNames = acc[modelName].commonNames
acc[modelName] = entry
acc[modelName].commonNames = existingCommonNames
}
}
}
return acc
Expand Down

0 comments on commit 91bc8a7

Please sign in to comment.