feat(ConfigManager): use input when fetch AI models failed for better UX
This commit is contained in:
@ -14,6 +14,8 @@
|
|||||||
const showModal = ref(false)
|
const showModal = ref(false)
|
||||||
const loadingAiModels = ref(false)
|
const loadingAiModels = ref(false)
|
||||||
const aiModelOptions = ref<string[]>([])
|
const aiModelOptions = ref<string[]>([])
|
||||||
|
/** If loading AI models failed, use a plain input to improve UX */
|
||||||
|
const isLoadAiModelsFailed = ref(false)
|
||||||
|
|
||||||
const aiProviderOptions = computed(() => [
|
const aiProviderOptions = computed(() => [
|
||||||
{
|
{
|
||||||
@ -48,19 +50,24 @@
|
|||||||
`Found ${result.data.length} AI models for provider ${config.value.ai.provider}`,
|
`Found ${result.data.length} AI models for provider ${config.value.ai.provider}`,
|
||||||
)
|
)
|
||||||
aiModelOptions.value = result.data.map((m) => m.id)
|
aiModelOptions.value = result.data.map((m) => m.id)
|
||||||
// Auto-select the current model
|
isLoadAiModelsFailed.value = false
|
||||||
if (config.value.ai.model && !aiModelOptions.value.includes(config.value.ai.model)) {
|
|
||||||
aiModelOptions.value.unshift(config.value.ai.model)
|
if (aiModelOptions.value.length) {
|
||||||
|
// Auto-select the current model
|
||||||
|
if (
|
||||||
|
config.value.ai.model &&
|
||||||
|
!aiModelOptions.value.includes(config.value.ai.model)
|
||||||
|
) {
|
||||||
|
aiModelOptions.value.unshift(config.value.ai.model)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Fetch AI models failed`, error)
|
console.error(`Fetch AI models failed`, error)
|
||||||
if (config.value.ai.model) {
|
isLoadAiModelsFailed.value = true
|
||||||
aiModelOptions.value = [config.value.ai.model]
|
aiModelOptions.value = []
|
||||||
} else {
|
} finally {
|
||||||
aiModelOptions.value = []
|
loadingAiModels.value = false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
loadingAiModels.value = false
|
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
function createAndSelectAiModel(model: string) {
|
function createAndSelectAiModel(model: string) {
|
||||||
@ -124,6 +131,7 @@
|
|||||||
</UFormField>
|
</UFormField>
|
||||||
<UFormField :label="$t('settings.ai.model')" required>
|
<UFormField :label="$t('settings.ai.model')" required>
|
||||||
<UInputMenu
|
<UInputMenu
|
||||||
|
v-if="aiModelOptions.length && !isLoadAiModelsFailed"
|
||||||
v-model="config.ai.model"
|
v-model="config.ai.model"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
:items="aiModelOptions"
|
:items="aiModelOptions"
|
||||||
@ -132,6 +140,12 @@
|
|||||||
create-item
|
create-item
|
||||||
@create="createAndSelectAiModel"
|
@create="createAndSelectAiModel"
|
||||||
/>
|
/>
|
||||||
|
<UInput
|
||||||
|
v-else
|
||||||
|
v-model="config.ai.model"
|
||||||
|
class="w-full"
|
||||||
|
:placeholder="$t('settings.ai.model')"
|
||||||
|
/>
|
||||||
</UFormField>
|
</UFormField>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user