Feat: Extract the common parts of groupImage2TextOptions and groupOptionsByModelType #5063 (#5074)

### What problem does this PR solve?

Feat: Extract the common parts of groupImage2TextOptions and
groupOptionsByModelType #5063

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu 2025-02-18 15:13:55 +08:00 committed by GitHub
parent a2b8ba472f
commit 375e727f9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ import {
IFactory,
IMyLlmValue,
IThirdOAIModelCollection as IThirdAiModelCollection,
IThirdOAIModel,
IThirdOAIModelCollection,
} from '@/interfaces/database/llm';
import {
@ -55,6 +56,24 @@ export const useSelectLlmOptions = () => {
return embeddingModelOptions;
};
function buildLlmOptionsWithIcon(x: IThirdOAIModel) {
return {
label: (
<Flex align="center" gap={6}>
<LlmIcon
name={getLLMIconName(x.fid, x.llm_name)}
width={26}
height={26}
size={'small'}
/>
<span>{x.llm_name}</span>
</Flex>
),
value: `${x.llm_name}@${x.fid}`,
disabled: !x.available,
};
}
export const useSelectLlmOptionsByModelType = () => {
const llmInfo: IThirdOAIModelCollection = useFetchLlmList();
@ -73,21 +92,7 @@ export const useSelectLlmOptionsByModelType = () => {
(x.tags && x.tags.includes(modelTag))) &&
x.available,
)
.map((x) => ({
label: (
<Flex align="center" gap={6}>
<LlmIcon
name={getLLMIconName(x.fid, x.llm_name)}
width={26}
height={26}
size={'small'}
/>
<span>{x.llm_name}</span>
</Flex>
),
value: `${x.llm_name}@${x.fid}`,
disabled: !x.available,
})),
.map(buildLlmOptionsWithIcon),
};
})
.filter((x) => x.options.length > 0);
@ -107,21 +112,7 @@ export const useSelectLlmOptionsByModelType = () => {
(modelType ? x.model_type.includes(modelType) : true) &&
x.available,
)
.map((x) => ({
label: (
<Flex align="center" gap={6}>
<LlmIcon
name={getLLMIconName(x.fid, x.llm_name)}
width={26}
height={26}
size={'small'}
/>
<span>{x.llm_name}</span>
</Flex>
),
value: `${x.llm_name}@${x.fid}`,
disabled: !x.available,
})),
.map(buildLlmOptionsWithIcon),
};
})
.filter((x) => x.options.length > 0);