rebuild(llm): add audited model connectivity tests
This commit is contained in:
@@ -22,12 +22,15 @@ const primaryId = ref<number | null>(null);
|
||||
const fallbackId = ref<number | null>(null);
|
||||
const errorMessage = ref("");
|
||||
const deleteConfirmation = ref<number | null>(null);
|
||||
const testingId = ref<number | null>(null);
|
||||
const testMessage = ref("");
|
||||
const form = reactive({ display_name: "", base_url: "", model_identifier: "", api_key: "" });
|
||||
const editing = computed(() => models.value.find((item) => item.id === editingId.value) ?? null);
|
||||
|
||||
function resetForm(): void {
|
||||
editingId.value = null;
|
||||
Object.assign(form, { display_name: "", base_url: "", model_identifier: "", api_key: "" });
|
||||
testMessage.value = "";
|
||||
}
|
||||
|
||||
function edit(model: ModelItem): void {
|
||||
@@ -111,6 +114,23 @@ async function remove(model: ModelItem): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function testConnection(model: ModelItem): Promise<void> {
|
||||
testingId.value = model.id;
|
||||
testMessage.value = "";
|
||||
errorMessage.value = "";
|
||||
try {
|
||||
const result = await api.post<{ message: string; duration_ms: number }>(
|
||||
`/admin/models/${model.id}/test`,
|
||||
);
|
||||
testMessage.value = `${result.message} · ${result.duration_ms} ms`;
|
||||
ui.showToast(`${model.display_name} 连接成功`);
|
||||
} catch (error) {
|
||||
errorMessage.value = error instanceof Error ? error.message : "模型连接测试失败。";
|
||||
} finally {
|
||||
testingId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
@@ -134,8 +154,9 @@ onMounted(load);
|
||||
<div class="field"><label for="model-url">服务地址</label><input id="model-url" v-model="form.base_url" class="input" type="url" required /></div>
|
||||
<div class="field"><label for="model-identifier">模型标识</label><input id="model-identifier" v-model="form.model_identifier" class="input" required /></div>
|
||||
<div class="field"><label for="model-key">密钥</label><input id="model-key" v-model="form.api_key" class="input" type="password" autocomplete="off" :placeholder="editing ? '留空则保持原密钥' : '请输入密钥'" /></div>
|
||||
<p v-if="testMessage" class="up" role="status">{{ testMessage }}</p>
|
||||
<p v-if="errorMessage" class="field-error" role="alert">{{ errorMessage }}</p>
|
||||
<div class="form-actions"><button v-if="editing && !editing.is_primary && !editing.is_fallback" class="btn" type="button" @click="remove(editing)">{{ deleteConfirmation === editing.id ? "确认删除" : "删除" }}</button><button class="btn btn-primary" type="submit">{{ editing ? "保存修改" : "添加模型" }}</button></div>
|
||||
<div class="form-actions"><button v-if="editing" class="btn" type="button" :disabled="testingId === editing.id" @click="testConnection(editing)">{{ testingId === editing.id ? "测试中" : "测试连接" }}</button><button v-if="editing && !editing.is_primary && !editing.is_fallback" class="btn" type="button" @click="remove(editing)">{{ deleteConfirmation === editing.id ? "确认删除" : "删除" }}</button><button class="btn btn-primary" type="submit">{{ editing ? "保存修改" : "添加模型" }}</button></div>
|
||||
</form>
|
||||
</section>
|
||||
<section class="card">
|
||||
|
||||
Reference in New Issue
Block a user