增加 语法检验
This commit is contained in:
parent
faa846abdc
commit
2f9744d5a8
@ -4,6 +4,9 @@
|
|||||||
<v-btn class="mt-3 mb-3" color="primary" @click="to('/tools/create')"
|
<v-btn class="mt-3 mb-3" color="primary" @click="to('/tools/create')"
|
||||||
>创建工具</v-btn
|
>创建工具</v-btn
|
||||||
>
|
>
|
||||||
|
<v-btn class="mt-3 mb-3 ml-3" color="primary" @click="to('/tools/validate')"
|
||||||
|
>工具语法检查</v-btn
|
||||||
|
>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<v-row>
|
<v-row>
|
||||||
@ -23,9 +26,9 @@
|
|||||||
<p>主页地址: {{ tool.data?.homepage_url }}</p>
|
<p>主页地址: {{ tool.data?.homepage_url }}</p>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<!-- <v-btn color="primary" @click="editAssistant(assistant)"
|
<v-btn color="primary" @click="updateToolData(tool.id ?? 0)"
|
||||||
>编辑</v-btn
|
>更新数据</v-btn
|
||||||
> -->
|
>
|
||||||
<v-btn color="error" @click="deleteTool(tool.id ?? 0)">
|
<v-btn color="error" @click="deleteTool(tool.id ?? 0)">
|
||||||
删除
|
删除
|
||||||
</v-btn>
|
</v-btn>
|
||||||
@ -60,6 +63,19 @@
|
|||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
|
|
||||||
|
<v-dialog v-model="toolUpdate.show" max-width="290" persistent>
|
||||||
|
<v-card>
|
||||||
|
<v-card-title class="headline">{{ toolUpdate.title }}</v-card-title>
|
||||||
|
<v-card-text>{{ toolUpdate.message }}</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="green darken-1" @click="toolUpdate.show = false"
|
||||||
|
>关闭</v-btn
|
||||||
|
>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@ -82,6 +98,11 @@ const failedDialog = ref({
|
|||||||
show: false,
|
show: false,
|
||||||
message: "创建失败",
|
message: "创建失败",
|
||||||
});
|
});
|
||||||
|
const toolUpdate = ref({
|
||||||
|
show: false,
|
||||||
|
title: "",
|
||||||
|
message: "",
|
||||||
|
});
|
||||||
const selectedId = ref(0);
|
const selectedId = ref(0);
|
||||||
|
|
||||||
function deleteTool(id: number) {
|
function deleteTool(id: number) {
|
||||||
@ -101,6 +122,26 @@ function deleteId() {
|
|||||||
dialog.value = false;
|
dialog.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateToolData(toolId: number) {
|
||||||
|
api.Tool.apiV1ToolsIdUpdatePost(toolId)
|
||||||
|
.then(() => {
|
||||||
|
toolUpdate.value.title = "更新成功";
|
||||||
|
toolUpdate.value.message = "工具数据已更新";
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(e.response.data.error);
|
||||||
|
|
||||||
|
toolUpdate.value.title = "更新失败";
|
||||||
|
toolUpdate.value.message =
|
||||||
|
"工具数据更新失败,请打开开发者工具查看详细信息。";
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
toolUpdate.value.show = true;
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function to(path: string) {
|
function to(path: string) {
|
||||||
router.push(path);
|
router.push(path);
|
||||||
}
|
}
|
||||||
|
83
src/pages/tools/validate.vue
Normal file
83
src/pages/tools/validate.vue
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<template>
|
||||||
|
<h3>验证语法</h3>
|
||||||
|
<p>目前处于测试阶段,不一定准确,但是能保证你添加成功。</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- input -->
|
||||||
|
<v-textarea v-model="input" label="你的 JSON 数据"></v-textarea>
|
||||||
|
|
||||||
|
<v-btn color="primary" class="mt-3 mb-3" @click="validate()">验证</v-btn>
|
||||||
|
<div v-show="checked">
|
||||||
|
<p v-show="error" class="text-danger">错误:{{ errorReason }}</p>
|
||||||
|
<p v-show="!error" class="text-success">正确</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { RagNewInternalSchemaToolDiscoveryInput } from '@/api'
|
||||||
|
import { api } from '@/plugins/api'
|
||||||
|
|
||||||
|
const exampleJSON = {
|
||||||
|
"name": "My Functions",
|
||||||
|
"description": "My Functions",
|
||||||
|
"homepage_url": "https://ivampiresp.com/test",
|
||||||
|
"callback_url": "https://ivampiresp.com/files/tool_test/index.php",
|
||||||
|
"functions": [
|
||||||
|
{
|
||||||
|
"name": "get_current_time",
|
||||||
|
"description": "当你想知道现在的时间时非常有用。",
|
||||||
|
"parameters": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "get_current_weather",
|
||||||
|
"description": "当你想查询指定城市的天气时非常有用。",
|
||||||
|
"parameters": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"location": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"location"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const input = ref("")
|
||||||
|
const checked = ref(false)
|
||||||
|
const error = ref(false)
|
||||||
|
const errorReason = ref("")
|
||||||
|
|
||||||
|
// unmashal
|
||||||
|
input.value = JSON.stringify(exampleJSON, null, 4)
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
checked.value = true
|
||||||
|
// 如果能解析为 json
|
||||||
|
try {
|
||||||
|
JSON.parse(input.value)
|
||||||
|
} catch (e) {
|
||||||
|
error.value = true
|
||||||
|
errorReason.value = "JSON 格式错误"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 强制类型转换
|
||||||
|
const data: RagNewInternalSchemaToolDiscoveryInput = JSON.parse(input.value)
|
||||||
|
|
||||||
|
|
||||||
|
api.Tool.apiV1ToolsSyntaxPost(data).then((res) => {
|
||||||
|
error.value = false
|
||||||
|
errorReason.value = ""
|
||||||
|
}).catch((e) => {
|
||||||
|
error.value = true
|
||||||
|
errorReason.value = e.response.data.error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
1
src/typed-router.d.ts
vendored
1
src/typed-router.d.ts
vendored
@ -29,5 +29,6 @@ declare module 'vue-router/auto-routes' {
|
|||||||
'/ping/': RouteRecordInfo<'/ping/', '/ping', Record<never, never>, Record<never, never>>,
|
'/ping/': RouteRecordInfo<'/ping/', '/ping', Record<never, never>, Record<never, never>>,
|
||||||
'/tools/': RouteRecordInfo<'/tools/', '/tools', Record<never, never>, Record<never, never>>,
|
'/tools/': RouteRecordInfo<'/tools/', '/tools', Record<never, never>, Record<never, never>>,
|
||||||
'/tools/create': RouteRecordInfo<'/tools/create', '/tools/create', Record<never, never>, Record<never, never>>,
|
'/tools/create': RouteRecordInfo<'/tools/create', '/tools/create', Record<never, never>, Record<never, never>>,
|
||||||
|
'/tools/validate': RouteRecordInfo<'/tools/validate', '/tools/validate', Record<never, never>, Record<never, never>>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user