Skip to content

Commit e887046

Browse files
authored
feat: add AiModelSelector FormKit component (#37)
* feat(ui): add AiModelSelector FormKit component Add AiModelSelector component for selecting AI models in FormKit Schema. - New AiModelSelector.vue component with search, grouping by provider, filter props (modelType, providerName, providerType, enabled, available, requiredFeatures), and v-model binding - Add ai-model-selector.ts with helper utilities (type labels, feature labels, unavailability reason labels) - Register AiModelSelector as a global component in plugin entry - Configure @formkit/themes UnoCSS preset for formkit-disabled: variant - Document component usage in dev/dev.md for SDK consumers * feat(ui): improve AiModelSelector group layout and FormKit validation - Remove icons from child model items, keep icons only on group headers - Add validation and validationMessages props, forwarded to the hidden FormKit field so validation participates in parent form state - Display validation error messages below the component * fix: adopt AiModelSelector in console model pickers * chore: update ui pnpm lockfile
1 parent 0708366 commit e887046

9 files changed

Lines changed: 812 additions & 77 deletions

File tree

dev/dev.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,82 @@ GenerateTextRequest request = GenerateTextRequest.builder()
668668
```
669669

670670
如果公开字段与已知 provider 原生键冲突,请优先使用公开字段。例如推理能力使用 `reasoning`,确定性采样使用 `seed`,不要同时在 `providerOptions` 中传入含义相同的原生键。
671+
672+
## 前端:AiModelSelector 模型选择器组件
673+
674+
`AiModelSelector` 是本插件提供的前端 Vue 组件,注册为全局组件名 `AiModelSelector`。其他插件可以在插件设置页的 FormKit Schema 中直接使用,让用户在 UI 上选择一个已配置的 AI 模型。
675+
676+
**保存的值**:选中后保存的是 `AiModel` 资源的 `metadata.name`,即上文 `modelName` 格式。可直接传给 `AiModelService.languageModel(modelName)``embeddingModel(modelName)` 使用。
677+
678+
### 在 FormKit Schema 中使用(推荐)
679+
680+
在插件设置页的 `configMaps` schema 中,通过 `$cmp` 方式引用:
681+
682+
```yaml
683+
formSchema:
684+
- $cmp: AiModelSelector
685+
props:
686+
name: languageModelName
687+
label: 语言模型
688+
help: 选择用于文章生成的语言模型
689+
```
690+
691+
带筛选条件(只显示语言模型):
692+
693+
```yaml
694+
formSchema:
695+
- $cmp: AiModelSelector
696+
props:
697+
name: languageModelName
698+
label: 语言模型
699+
modelType: LANGUAGE
700+
clearable: true
701+
placeholder: 请选择语言模型
702+
703+
- $cmp: AiModelSelector
704+
props:
705+
name: embeddingModelName
706+
label: 嵌入模型
707+
modelType: EMBEDDING
708+
```
709+
710+
### 全部可用 Props
711+
712+
| Prop | 类型 | 默认值 | 说明 |
713+
| --- | --- | --- | --- |
714+
| `name` | `string` | - | 对应 FormKit 表单字段名,决定保存到 ConfigMap 的 key |
715+
| `label` | `string` | - | 字段标签文字 |
716+
| `help` | `string` | - | 字段说明文字 |
717+
| `modelValue` | `string` | - | 当前选中的模型名,供 `v-model` 绑定 |
718+
| `modelType` | `string` | - | 筛选模型类型,可选值如 `LANGUAGE`、`EMBEDDING` |
719+
| `providerName` | `string` | - | 只显示指定 `AiProvider.metadata.name` 下的模型 |
720+
| `providerType` | `string` | - | 只显示指定供应方类型下的模型 |
721+
| `enabled` | `boolean` | - | 若为 `true`,只显示已启用的模型 |
722+
| `available` | `boolean` | `true` | 若为 `true`,只显示可用模型 |
723+
| `requiredFeatures` | `string \| string[]` | - | 只显示具备指定 feature 的模型 |
724+
| `placeholder` | `string` | `请选择模型` | 未选中时的占位文字 |
725+
| `searchPlaceholder` | `string` | `搜索...` | 搜索框占位文字 |
726+
| `clearable` | `boolean` | `true` | 是否显示清除按钮 |
727+
| `disabled` | `boolean` | `false` | 是否禁用 |
728+
| `fullWidth` | `boolean` | `false` | 是否让选择器占满容器宽度 |
729+
730+
### 在 Vue 组件中使用
731+
732+
```vue
733+
<template>
734+
<AiModelSelector
735+
v-model="selectedModel"
736+
label="语言模型"
737+
model-type="LANGUAGE"
738+
help="用于文章摘要生成"
739+
/>
740+
</template>
741+
742+
<script setup lang="ts">
743+
import { ref } from 'vue'
744+
745+
const selectedModel = ref<string>()
746+
</script>
747+
```
748+
749+
直接在 Vue 模板中使用时,无需传 `name` prop,通过 `v-model` 双向绑定即可。

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"vue-router": "5.0.6"
3838
},
3939
"devDependencies": {
40+
"@formkit/themes": "^2.0.0",
4041
"@halo-dev/ui-plugin-bundler-kit": "^2.24.0",
4142
"@iconify-json/ri": "^1.2.10",
4243
"@rsbuild/core": "^2.0.6",

ui/pnpm-lock.yaml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)