mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
perf: select matching model IDs without sorting (#20334)
Co-authored-by: Orca Worker <orca-worker@localhost>
This commit is contained in:
@@ -48,6 +48,15 @@ describe('applyNativeChatReportedSessionOptions', () => {
|
||||
})
|
||||
|
||||
describe('matchNativeChatCatalogModelId', () => {
|
||||
it('prefers the longest contained id and keeps catalog order for ties', () => {
|
||||
const catalog = {
|
||||
...CLAUDE_SESSION_OPTION_CATALOG,
|
||||
models: ['a', 'abc', 'xyz'].map((id) => ({ id, label: id, options: [] }))
|
||||
}
|
||||
expect(matchNativeChatCatalogModelId(catalog, 'provider-xyz-abc')).toBe('abc')
|
||||
expect(catalog.models.map((model) => model.id)).toEqual(['a', 'abc', 'xyz'])
|
||||
})
|
||||
|
||||
it('matches exact ids, labels, and provider-id containment', () => {
|
||||
expect(matchNativeChatCatalogModelId(CLAUDE_SESSION_OPTION_CATALOG, 'sonnet')).toBe('sonnet')
|
||||
expect(matchNativeChatCatalogModelId(CLAUDE_SESSION_OPTION_CATALOG, 'Sonnet 5')).toBe('sonnet')
|
||||
|
||||
@@ -167,8 +167,14 @@ export function matchNativeChatCatalogModelId(
|
||||
if (byLabel) {
|
||||
return byLabel.id
|
||||
}
|
||||
const containing = [...catalog.models]
|
||||
.sort((left, right) => right.id.length - left.id.length)
|
||||
.find((model) => normalized.includes(model.id.toLowerCase()))
|
||||
return containing?.id ?? null
|
||||
let containingId: string | null = null
|
||||
for (const model of catalog.models) {
|
||||
if (
|
||||
(containingId === null || model.id.length > containingId.length) &&
|
||||
normalized.includes(model.id.toLowerCase())
|
||||
) {
|
||||
containingId = model.id
|
||||
}
|
||||
}
|
||||
return containingId
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user