feat: 增强智能体模型调用兼容能力

- 增加模型流式开关和 HTTP 传输策略配置

- 使用 AgentScope 执行基础连接、流式与 VLM 双阶段验证

- 固定多模态校验图片并统一验证状态展示
This commit is contained in:
2026-07-17 19:57:06 +08:00
parent ba21f861f4
commit 791649c7d5
22 changed files with 1492 additions and 107 deletions

View File

@@ -0,0 +1,63 @@
import { describe, expect, it } from 'vitest';
import {
getVerifyButtonText,
resolveModelVerificationFeedback,
} from '../model-verification';
describe('model verification helpers', () => {
it('双阶段通过时返回成功状态', () => {
expect(
resolveModelVerificationFeedback(
{
data: { status: 'PASSED' },
errorCode: 0,
},
'chatModel',
),
).toEqual({
dimension: undefined,
message: '验证成功',
status: 'success',
});
});
it('基础连接通过但流式失败时返回警告状态', () => {
const feedback = resolveModelVerificationFeedback(
{
data: {
message: '连接成功,流式响应不可用,可关闭智能体的模型流式响应。',
status: 'PARTIAL',
},
errorCode: 0,
},
'chatModel',
);
expect(feedback.status).toBe('warning');
expect(feedback.message).toContain('流式响应不可用');
expect(getVerifyButtonText('warning')).toBe('流式不可用');
});
it('向量模型验证保留维度结果', () => {
expect(
resolveModelVerificationFeedback(
{ data: { dimension: 1024 }, errorCode: 0 },
'embeddingModel',
),
).toEqual({
dimension: 1024,
message: '验证成功向量维度1024',
status: 'success',
});
});
it('接口失败时返回错误状态', () => {
expect(
resolveModelVerificationFeedback(
{ errorCode: 1, message: '密钥无效' },
'chatModel',
),
).toEqual({ message: '密钥无效', status: 'error' });
});
});

View File

@@ -0,0 +1,75 @@
import type { ModelVerificationData } from '#/api/ai/llm';
export type VerifyButtonStatus =
| 'error'
| 'idle'
| 'loading'
| 'success'
| 'warning';
export interface ModelVerificationFeedback {
dimension?: number;
message: string;
status: 'error' | 'success' | 'warning';
}
interface ModelVerificationResponse {
data?: ModelVerificationData;
errorCode: number;
message?: string;
}
const STREAMING_UNAVAILABLE_MESSAGE =
'连接成功,流式响应不可用,可关闭智能体的模型流式响应。';
export function resolveModelVerificationFeedback(
response: ModelVerificationResponse,
modelType: string,
): ModelVerificationFeedback {
if (response.errorCode !== 0) {
return {
message: response.message || '验证失败',
status: 'error',
};
}
if (response.data?.status === 'PARTIAL') {
return {
message: response.data.message || STREAMING_UNAVAILABLE_MESSAGE,
status: 'warning',
};
}
if (response.data?.status === 'FAILED') {
return {
message: response.data.message || '验证失败',
status: 'error',
};
}
const dimension = response.data?.dimension;
return {
dimension,
message:
modelType === 'embeddingModel' && dimension
? `验证成功,向量维度:${dimension}`
: response.data?.message || '验证成功',
status: 'success',
};
}
export function getVerifyButtonText(status: VerifyButtonStatus): string {
if (status === 'loading') {
return '验证中';
}
if (status === 'success') {
return '验证成功';
}
if (status === 'warning') {
return '流式不可用';
}
if (status === 'error') {
return '验证失败';
}
return '验证配置';
}