Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data-agent-frontend/src/services/modelConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface ModelConfig {
proxyPort?: number;
proxyUsername?: string;
proxyPassword?: string;
chatApiProtocol?: string; // Chat模型接口协议: CHAT_COMPLETIONS(默认)或 RESPONSES
}

export interface ModelCheckReady {
Expand Down
30 changes: 27 additions & 3 deletions data-agent-frontend/src/views/ModelConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,30 @@

<el-form-item
v-if="formData.modelType === 'CHAT'"
label="Completions路径"
label="接口协议"
prop="chatApiProtocol"
>
<el-select v-model="formData.chatApiProtocol" style="width: 100%">
<el-option label="Chat Completions(默认)" value="CHAT_COMPLETIONS" />
<el-option label="Responses API" value="RESPONSES" />
</el-select>
<div class="form-tip">
部分模型服务商仅支持 Responses API 格式,此时请选择 Responses API
</div>
</el-form-item>

<el-form-item
v-if="formData.modelType === 'CHAT'"
:label="formData.chatApiProtocol === 'RESPONSES' ? 'Responses路径' : 'Completions路径'"
prop="completionsPath"
>
<el-input
v-model="formData.completionsPath"
placeholder="附加到base-url的路径。留空则使用默认值/v1/chat/completions"
:placeholder="
formData.chatApiProtocol === 'RESPONSES'
? '附加到base-url的路径。留空则使用默认值/v1/responses'
: '附加到base-url的路径。留空则使用默认值/v1/chat/completions'
"
/>
</el-form-item>

Expand Down Expand Up @@ -374,6 +392,7 @@
proxyPort: 7890, // 给个常用的默认端口
proxyUsername: '',
proxyPassword: '',
chatApiProtocol: 'CHAT_COMPLETIONS',
});

// 提供商与API地址的映射
Expand Down Expand Up @@ -493,13 +512,18 @@
completionsPath: '',
embeddingsPath: '',
isActive: false,
chatApiProtocol: 'CHAT_COMPLETIONS',
};
dialogVisible.value = true;
};

const handleEdit = (config: ModelConfig) => {
isEditMode.value = true;
formData.value = { ...config };
// 历史数据的 chatApiProtocol 可能为空(该字段为后续版本新增),回填默认协议避免下拉框空白
formData.value = {
...config,
chatApiProtocol: config.chatApiProtocol || 'CHAT_COMPLETIONS',
};
dialogVisible.value = true;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import com.alibaba.cloud.ai.dataagent.dto.ModelConfigDTO;
import com.alibaba.cloud.ai.dataagent.entity.ModelConfig;
import com.alibaba.cloud.ai.dataagent.enums.ChatApiProtocol;
import com.alibaba.cloud.ai.dataagent.enums.ModelType;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

Expand Down Expand Up @@ -48,6 +50,7 @@ public static ModelConfigDTO toDTO(ModelConfig entity) {
.proxyPort(entity.getProxyPort())
.proxyUsername(entity.getProxyUsername())
.proxyPassword(entity.getProxyPassword())
.chatApiProtocol(entity.getChatApiProtocol())
.build();
}

Expand All @@ -74,6 +77,10 @@ public static ModelConfig toEntity(ModelConfigDTO dto) {
entity.setProxyPort(dto.getProxyPort());
entity.setProxyUsername(dto.getProxyUsername());
entity.setProxyPassword(dto.getProxyPassword());
// chatApiProtocol 为空时回填默认协议:INSERT 显式写入 NULL 会绕过数据库列的 DEFAULT 值,
// 统一在转换层兜底,保证新增数据与列默认值口径一致
entity.setChatApiProtocol(StringUtils.hasText(dto.getChatApiProtocol()) ? dto.getChatApiProtocol()
: ChatApiProtocol.CHAT_COMPLETIONS.getCode());
// 默认值处理
entity.setIsActive(false);
entity.setIsDeleted(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ public class ModelConfigDTO {

private String proxyPassword;

// Chat 模型接口协议:CHAT_COMPLETIONS(默认)或 RESPONSES,仅 modelType=CHAT 时生效
private String chatApiProtocol;

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ public class ModelConfig {

private String proxyPassword;

// Chat 模型接口协议:CHAT_COMPLETIONS(默认)或 RESPONSES,仅 modelType=CHAT 时生效
private String chatApiProtocol;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.ai.dataagent.enums;

import lombok.Getter;

/**
* Chat 模型接口协议枚举。 CHAT_COMPLETIONS:标准 OpenAI Chat Completions 格式(默认,/v1/chat/completions);
* RESPONSES:OpenAI Responses API 格式(/v1/responses),用于仅支持该协议的模型服务商。
*/
@Getter
public enum ChatApiProtocol {

/**
* 标准 Chat Completions 协议(默认)
*/
CHAT_COMPLETIONS("CHAT_COMPLETIONS"),

/**
* OpenAI Responses API 协议
*/
RESPONSES("RESPONSES");

private final String code;

ChatApiProtocol(String code) {
this.code = code;
}

/**
* 根据代码解析枚举(忽略大小写)。 非法值直接抛异常拦截在保存入口:若不拦截,拼写错误的协议值会在 DynamicModelFactory 静默落入默认的 Chat
* Completions 分支,用户配置悄悄失效且难以排查。
*/
public static ChatApiProtocol fromCode(String code) {
for (ChatApiProtocol protocol : values()) {
if (protocol.getCode().equalsIgnoreCase(code)) {
return protocol;
}
}
throw new IllegalArgumentException("不支持的 Chat 接口协议: " + code + ",仅支持 CHAT_COMPLETIONS 或 RESPONSES");
}

}
Loading