Skip to content

Commit d6408f2

Browse files
committed
fix: prefer highest weight public task model
1 parent 9e45cd9 commit d6408f2

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

frontend/src/utils/common.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -656,20 +656,26 @@ export function getFileExtension(filename: string): string {
656656
}
657657

658658
export function selectPreferredTaskModel(models: DomainModel[], subscription?: DomainSubscriptionResp | null): string {
659-
const accessibleModels = models.filter((model) => canUseModelBySubscription(model, subscription))
660-
const preferredModels = accessibleModels.filter((model) => (
661-
model.id
662-
&& model.owner?.type === ConstsOwnerType.OwnerTypePublic
663-
&& model.access_level === "basic"
664-
&& model.is_free === true
665-
))
666-
667-
if (preferredModels.length === 0) {
659+
const preferredModel = models
660+
.filter((model) => (
661+
model.id
662+
&& model.owner?.type === ConstsOwnerType.OwnerTypePublic
663+
&& canUseModelBySubscription(model, subscription)
664+
))
665+
.sort((left, right) => {
666+
const weightDiff = (right.weight || 0) - (left.weight || 0)
667+
if (weightDiff !== 0) {
668+
return weightDiff
669+
}
670+
671+
return (left.model || "").localeCompare(right.model || "")
672+
})[0]
673+
674+
if (!preferredModel?.id) {
668675
return ""
669676
}
670677

671-
const randomIndex = Math.floor(Math.random() * preferredModels.length)
672-
return preferredModels[randomIndex]?.id || ""
678+
return preferredModel.id
673679
}
674680

675681

0 commit comments

Comments
 (0)