fix: 修复智能体聊天图片能力判断
This commit is contained in:
@@ -2,6 +2,13 @@ import type { AgentInfo } from '../agents/types';
|
||||
|
||||
import { api } from '#/api/request';
|
||||
|
||||
export type AgentChatAgentOption = Pick<
|
||||
AgentInfo,
|
||||
'avatar' | 'description' | 'id' | 'interactionConfigJson' | 'name'
|
||||
> & {
|
||||
supportImage?: boolean | null;
|
||||
};
|
||||
|
||||
export interface RequestResult<T = any> {
|
||||
data: T;
|
||||
errorCode: number;
|
||||
@@ -74,9 +81,12 @@ export interface AgentChatCapabilityPayload {
|
||||
}
|
||||
|
||||
export function getPublishedAgents() {
|
||||
return api.get<RequestResult<AgentInfo[]>>('/api/v1/agent/session/options', {
|
||||
return api.get<RequestResult<AgentChatAgentOption[]>>(
|
||||
'/api/v1/agent/session/options',
|
||||
{
|
||||
params: { publishedOnly: true },
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function generateAgentSessionId() {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
AGENT_CHAT_ATTACHMENT_ACCEPT,
|
||||
AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE,
|
||||
AGENT_IMAGE_UNSUPPORTED_MESSAGE,
|
||||
supportsAgentImageInput,
|
||||
} from './imageCapability';
|
||||
|
||||
describe('agent chat image capability', () => {
|
||||
it('仅允许明确启用图片能力的发布模型', () => {
|
||||
expect(supportsAgentImageInput(true)).toBe(true);
|
||||
expect(supportsAgentImageInput(false)).toBe(false);
|
||||
expect(supportsAgentImageInput(null)).toBe(false);
|
||||
expect(supportsAgentImageInput(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('附件选择器同时展示文档和图片格式', () => {
|
||||
expect(AGENT_CHAT_ATTACHMENT_ACCEPT).toContain('.pdf');
|
||||
expect(AGENT_CHAT_ATTACHMENT_ACCEPT).toContain('.png');
|
||||
expect(AGENT_CHAT_ATTACHMENT_ACCEPT).toContain('image/png');
|
||||
});
|
||||
|
||||
it('为视觉能力限制提供明确反馈', () => {
|
||||
expect(AGENT_IMAGE_UNSUPPORTED_MESSAGE).toBe(
|
||||
'当前大模型不支持视觉,无法上传图片',
|
||||
);
|
||||
expect(AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE).toBe(
|
||||
'当前大模型不支持视觉,已添加的图片无法发送,请先移除',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
export const AGENT_CHAT_ATTACHMENT_ACCEPT =
|
||||
'.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.md,.png,.jpg,.jpeg,.webp,.gif,.bmp,image/png,image/jpeg,image/webp,image/gif,image/bmp';
|
||||
|
||||
export const AGENT_IMAGE_UNSUPPORTED_MESSAGE =
|
||||
'当前大模型不支持视觉,无法上传图片';
|
||||
|
||||
export const AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE =
|
||||
'当前大模型不支持视觉,已添加的图片无法发送,请先移除';
|
||||
|
||||
export function supportsAgentImageInput(
|
||||
supportImage?: boolean | null,
|
||||
): boolean {
|
||||
return supportImage === true;
|
||||
}
|
||||
@@ -8,8 +8,7 @@ import type {
|
||||
ChatTimelineToolApprovalPayload,
|
||||
} from '@easyflow/common-ui';
|
||||
|
||||
import type { AgentInfo } from '../agents/types';
|
||||
import type { AgentChatSessionView } from './api';
|
||||
import type { AgentChatAgentOption, AgentChatSessionView } from './api';
|
||||
|
||||
import type {
|
||||
ChatInputTriggerGroup,
|
||||
@@ -78,6 +77,12 @@ import {
|
||||
renameAgentSession,
|
||||
saveAgentSessionExtraKnowledges,
|
||||
} from './api';
|
||||
import {
|
||||
AGENT_CHAT_ATTACHMENT_ACCEPT,
|
||||
AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE,
|
||||
AGENT_IMAGE_UNSUPPORTED_MESSAGE,
|
||||
supportsAgentImageInput,
|
||||
} from './imageCapability';
|
||||
import {
|
||||
isMissingAgentSessionError,
|
||||
resolveAgentSessionErrorMessage,
|
||||
@@ -86,7 +91,7 @@ import {
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const agents = ref<AgentInfo[]>([]);
|
||||
const agents = ref<AgentChatAgentOption[]>([]);
|
||||
const sessions = ref<AgentChatSessionView[]>([]);
|
||||
const timelineItems = ref<ChatTimelineItem[]>([]);
|
||||
const selectedAgentId = ref('');
|
||||
@@ -122,9 +127,7 @@ const selectedAgent = computed(() =>
|
||||
agents.value.find((agent) => String(agent.id) === selectedAgentId.value),
|
||||
);
|
||||
const selectedAgentImageSupport = computed(() =>
|
||||
Boolean(
|
||||
selectedAgent.value?.publishedSnapshotJson?.modelSummary?.supportImage,
|
||||
),
|
||||
supportsAgentImageInput(selectedAgent.value?.supportImage),
|
||||
);
|
||||
const supportedAttachmentFormats = computed(() =>
|
||||
selectedAgentImageSupport.value === false
|
||||
@@ -614,7 +617,7 @@ async function handleAgentChange() {
|
||||
selectedAgentImageSupport.value === false &&
|
||||
composer.images.items.value.length > 0
|
||||
) {
|
||||
ElMessage.warning('当前智能体不支持图片,请先移除图片');
|
||||
ElMessage.warning(AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -822,7 +825,7 @@ async function addImageFiles(files: File[]) {
|
||||
if (selectedAgentImageSupport.value === false) {
|
||||
ElMessage.warning({
|
||||
grouping: true,
|
||||
message: `当前智能体不支持图片,支持:${CHAT_DOCUMENT_SUPPORTED_FORMATS}`,
|
||||
message: AGENT_IMAGE_UNSUPPORTED_MESSAGE,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -1395,11 +1398,7 @@ onBeforeUnmount(() => {
|
||||
ref="attachmentFileInputRef"
|
||||
class="agent-chat__image-file-input"
|
||||
type="file"
|
||||
:accept="
|
||||
selectedAgentImageSupport === false
|
||||
? '.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.md'
|
||||
: '.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.md,.png,.jpg,.jpeg,.webp,.gif,.bmp,image/png,image/jpeg,image/webp,image/gif,image/bmp'
|
||||
"
|
||||
:accept="AGENT_CHAT_ATTACHMENT_ACCEPT"
|
||||
multiple
|
||||
@change="handleAttachmentFiles"
|
||||
/>
|
||||
|
||||
@@ -49,7 +49,9 @@ export function buildInteractionConfigPayload(
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveInteractionDisplay(agent?: AgentInfo) {
|
||||
export function resolveInteractionDisplay(
|
||||
agent?: Pick<AgentInfo, 'interactionConfigJson' | 'name'>,
|
||||
) {
|
||||
const config = buildInteractionConfigPayload(agent?.interactionConfigJson);
|
||||
const agentName = String(agent?.name || '').trim() || '智能体';
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user