File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed
Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -656,20 +656,26 @@ export function getFileExtension(filename: string): string {
656656}
657657
658658export 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
You can’t perform that action at this time.
0 commit comments