AI配置增加字段适配处理
This commit is contained in:
@@ -204,4 +204,14 @@ export function countByProvider(provider: string) {
|
||||
method: 'get',
|
||||
params: { provider }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 测试后更新AI配置
|
||||
export function updateAiConfigFromTest(data: any) {
|
||||
return request({
|
||||
url: '/aiConfig/updateFromTest',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ export interface AiConfig {
|
||||
apiBaseUrl: string
|
||||
apiToken: string
|
||||
apiVersion?: string
|
||||
clientId?: string
|
||||
clientSecret?: string
|
||||
grantType?: string
|
||||
modelName?: string
|
||||
botId?: string
|
||||
workflowId?: string
|
||||
@@ -66,6 +69,9 @@ export interface AiConfigCreateRequest {
|
||||
apiBaseUrl: string
|
||||
apiToken: string
|
||||
apiVersion?: string
|
||||
clientId?: string
|
||||
clientSecret?: string
|
||||
grantType?: string
|
||||
modelName?: string
|
||||
botId?: string
|
||||
workflowId?: string
|
||||
@@ -108,6 +114,9 @@ export interface AiConfigUpdateRequest {
|
||||
apiBaseUrl?: string
|
||||
apiToken?: string
|
||||
apiVersion?: string
|
||||
clientId?: string
|
||||
clientSecret?: string
|
||||
grantType?: string
|
||||
modelName?: string
|
||||
botId?: string
|
||||
workflowId?: string
|
||||
|
||||
@@ -288,6 +288,34 @@
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="8">
|
||||
<el-form-item label="Client ID">
|
||||
<el-input v-model="formData.clientId" placeholder="OAuth客户端ID" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="Client Secret">
|
||||
<el-input
|
||||
v-model="formData.clientSecret"
|
||||
type="password"
|
||||
show-password
|
||||
placeholder="OAuth客户端密钥"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="Grant Type">
|
||||
<el-select v-model="formData.grantType" placeholder="授权类型" clearable style="width: 100%">
|
||||
<el-option label="client_credentials" value="client_credentials" />
|
||||
<el-option label="authorization_code" value="authorization_code" />
|
||||
<el-option label="password" value="password" />
|
||||
<el-option label="refresh_token" value="refresh_token" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20" v-if="formData.configType === 'coze'">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="Bot ID">
|
||||
@@ -514,6 +542,9 @@
|
||||
<el-descriptions-item label="环境">{{ getEnvironmentLabel(viewData.environment || '') }}</el-descriptions-item>
|
||||
<el-descriptions-item label="API完整URL">{{ viewData.apiBaseUrl }}</el-descriptions-item>
|
||||
<el-descriptions-item label="API令牌">{{ viewData.apiToken }}</el-descriptions-item>
|
||||
<el-descriptions-item label="Client ID">{{ viewData.clientId || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="Client Secret">{{ viewData.clientSecret ? '******' : '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="Grant Type">{{ viewData.grantType || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="模型名称">{{ viewData.modelName || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="优先级">{{ viewData.priority || 0 }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
@@ -634,6 +665,13 @@
|
||||
<el-form-item>
|
||||
<el-button @click="handleFormatResponse">格式化响应</el-button>
|
||||
<el-button @click="handleCopyResponse">复制响应</el-button>
|
||||
<el-button
|
||||
v-if="testResponse.status === 200"
|
||||
type="success"
|
||||
@click="handleSaveTestConfig"
|
||||
>
|
||||
保存测试配置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
@@ -659,7 +697,8 @@ import {
|
||||
unsetDefaultConfig,
|
||||
countEnabledConfigs,
|
||||
countDisabledConfigs,
|
||||
countDefaultConfigs
|
||||
countDefaultConfigs,
|
||||
updateAiConfigFromTest
|
||||
} from '@/api/aiconfig'
|
||||
import type { AiConfig, AiConfigPageRequest } from '@/types/aiconfig'
|
||||
import {
|
||||
@@ -711,6 +750,9 @@ const formData = reactive({
|
||||
apiBaseUrl: '',
|
||||
apiToken: '',
|
||||
apiVersion: '',
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
grantType: '',
|
||||
modelName: '',
|
||||
botId: '',
|
||||
workflowId: '',
|
||||
@@ -1045,6 +1087,9 @@ const handleDialogClose = () => {
|
||||
apiBaseUrl: '',
|
||||
apiToken: '',
|
||||
apiVersion: '',
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
grantType: '',
|
||||
modelName: '',
|
||||
botId: '',
|
||||
workflowId: '',
|
||||
@@ -1411,6 +1456,83 @@ const handleCopyResponse = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 保存测试配置
|
||||
const handleSaveTestConfig = async () => {
|
||||
if (!testConfig.value) {
|
||||
ElMessage.error('测试配置不存在')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 解析请求头
|
||||
let headers: any = {}
|
||||
try {
|
||||
headers = JSON.parse(testRequest.headers)
|
||||
} catch (e) {
|
||||
ElMessage.error('请求头格式错误,无法解析')
|
||||
return
|
||||
}
|
||||
|
||||
// 解析请求体
|
||||
let body: any = {}
|
||||
try {
|
||||
body = JSON.parse(testRequest.body)
|
||||
} catch (e) {
|
||||
ElMessage.error('请求体格式错误,无法解析')
|
||||
return
|
||||
}
|
||||
|
||||
// 提取API Token(从Authorization头中)
|
||||
let apiToken = testConfig.value.apiToken
|
||||
if (headers.Authorization) {
|
||||
// 移除 "Bearer " 前缀
|
||||
apiToken = headers.Authorization.replace(/^Bearer\s+/i, '')
|
||||
delete headers.Authorization // 从自定义头中移除,因为已经保存到apiToken字段
|
||||
}
|
||||
|
||||
// 提取Bot ID和Workflow ID(从请求体中)
|
||||
const botId = body.bot_id || testConfig.value.botId
|
||||
const workflowId = body.workflow_id || testConfig.value.workflowId
|
||||
const supportStream = body.stream !== undefined ? (body.stream ? 1 : 0) : testConfig.value.supportStream
|
||||
|
||||
// 移除已经提取的字段,剩余的作为自定义参数
|
||||
const customParamsBody = { ...body }
|
||||
delete customParamsBody.bot_id
|
||||
delete customParamsBody.workflow_id
|
||||
delete customParamsBody.stream
|
||||
delete customParamsBody.user_id
|
||||
delete customParamsBody.additional_messages
|
||||
|
||||
// 构建更新请求
|
||||
const updateData = {
|
||||
id: testConfig.value.id,
|
||||
apiBaseUrl: testRequest.url,
|
||||
apiToken: apiToken,
|
||||
botId: botId,
|
||||
workflowId: workflowId,
|
||||
customHeaders: Object.keys(headers).length > 0 ? JSON.stringify(headers) : '',
|
||||
customParams: Object.keys(customParamsBody).length > 0 ? JSON.stringify(customParamsBody) : '',
|
||||
supportStream: supportStream
|
||||
}
|
||||
|
||||
// 调用更新接口
|
||||
const res = await updateAiConfigFromTest(updateData)
|
||||
|
||||
if (res.code === 200) {
|
||||
ElMessage.success('测试配置已保存')
|
||||
// 更新testConfig
|
||||
testConfig.value = res.data
|
||||
// 刷新列表
|
||||
await fetchData()
|
||||
} else {
|
||||
ElMessage.error(res.message || '保存失败')
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('保存测试配置失败:', error)
|
||||
ElMessage.error('保存失败: ' + (error.message || error))
|
||||
}
|
||||
}
|
||||
|
||||
// 重置测试
|
||||
const handleResetTest = () => {
|
||||
if (testConfig.value) {
|
||||
|
||||
Reference in New Issue
Block a user