({
defaultModelId,
models,
modelIdKey,
serviceName,
serviceUrl,
apiConfiguration,
setApiConfigurationField,
organizationAllowList,
errorMessage,
simplifySettings,
hidePricing,
label,
valueTransform,
displayTransform,
onModelChange,
}: ModelPickerProps)
| 70 | } |
| 71 | |
| 72 | export const ModelPicker = ({ |
| 73 | defaultModelId, |
| 74 | models, |
| 75 | modelIdKey, |
| 76 | serviceName, |
| 77 | serviceUrl, |
| 78 | apiConfiguration, |
| 79 | setApiConfigurationField, |
| 80 | organizationAllowList, |
| 81 | errorMessage, |
| 82 | simplifySettings, |
| 83 | hidePricing, |
| 84 | label, |
| 85 | valueTransform, |
| 86 | displayTransform, |
| 87 | onModelChange, |
| 88 | }: ModelPickerProps) => { |
| 89 | const { t } = useAppTranslation() |
| 90 | |
| 91 | const [open, setOpen] = useState(false) |
| 92 | const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false) |
| 93 | const isInitialized = useRef(false) |
| 94 | const searchInputRef = useRef<HTMLInputElement>(null) |
| 95 | const selectTimeoutRef = useRef<NodeJS.Timeout | null>(null) |
| 96 | const closeTimeoutRef = useRef<NodeJS.Timeout | null>(null) |
| 97 | |
| 98 | const { id: selectedModelId, info: selectedModelInfo } = useSelectedModel(apiConfiguration) |
| 99 | |
| 100 | // Get the display value for the current selection |
| 101 | // If displayTransform is provided, use it to convert the stored value to a display string |
| 102 | const displayValue = useMemo(() => { |
| 103 | if (displayTransform) { |
| 104 | const storedValue = apiConfiguration[modelIdKey] |
| 105 | return storedValue ? displayTransform(storedValue) : undefined |
| 106 | } |
| 107 | return selectedModelId |
| 108 | }, [displayTransform, apiConfiguration, modelIdKey, selectedModelId]) |
| 109 | |
| 110 | const activeProvider = |
| 111 | apiConfiguration.apiProvider && isRetiredProvider(apiConfiguration.apiProvider) |
| 112 | ? undefined |
| 113 | : apiConfiguration.apiProvider |
| 114 | |
| 115 | const modelIds = useMemo(() => { |
| 116 | const filteredModels = filterModels(models, activeProvider, organizationAllowList) |
| 117 | |
| 118 | // Include the currently selected model even if deprecated (so users can see what they have selected) |
| 119 | // But filter out other deprecated models from being newly selectable |
| 120 | const availableModels = Object.entries(filteredModels ?? {}) |
| 121 | .filter(([modelId, modelInfo]) => { |
| 122 | // Always include the currently selected model |
| 123 | if (modelId === selectedModelId) return true |
| 124 | // Filter out deprecated models that aren't currently selected |
| 125 | return !modelInfo.deprecated |
| 126 | }) |
| 127 | .reduce( |
| 128 | (acc, [modelId, modelInfo]) => { |
| 129 | acc[modelId] = modelInfo |
nothing calls this directly
no test coverage detected