-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathuseAiModelOptions.ts
More file actions
50 lines (41 loc) · 1.43 KB
/
useAiModelOptions.ts
File metadata and controls
50 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { type SelectOption } from 'twenty-ui/input';
import { isAutoSelectModelId } from 'twenty-shared/utils';
import { useWorkspaceAiModelAvailability } from '@/ai/hooks/useWorkspaceAiModelAvailability';
import { aiModelsState } from '@/client-config/states/aiModelsState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
export const useAiModelOptions = (): SelectOption<string>[] => {
const aiModels = useAtomStateValue(aiModelsState);
const { isModelEnabled } = useWorkspaceAiModelAvailability();
return aiModels
.filter(
(model) => !model.isDeprecated && isModelEnabled(model.modelId, model),
)
.map((model) => ({
value: model.modelId,
label: isAutoSelectModelId(model.modelId)
? model.label
: model.modelFamilyLabel
? `${model.label} (${model.modelFamilyLabel})`
: model.label,
}))
.sort((a, b) => a.label.localeCompare(b.label));
};
export const useAiModelLabel = (
modelId: string | undefined,
includeProvider = true,
): string => {
const aiModels = useAtomStateValue(aiModelsState);
if (!modelId) {
return '';
}
const model = aiModels.find((m) => m.modelId === modelId);
if (!model) {
return modelId;
}
if (isAutoSelectModelId(model.modelId) || !includeProvider) {
return model.label;
}
return model.modelFamilyLabel
? `${model.label} (${model.modelFamilyLabel})`
: model.label;
};