feat: implement image upload and multimodal support
- Added functionality for image uploads in chat, allowing users to attach images for multimodal Q&A. - Enhanced the input field to handle image selection via drag-and-drop and paste, with validation for file types and sizes. - Updated the backend to process images alongside text queries, including support for image analysis. - Introduced new UI components for image previews and management, improving user interaction with uploaded content. - Added localization strings for image upload features and error messages, enhancing accessibility for users in multiple languages. These changes significantly improve the chat experience by enabling users to incorporate images into their queries, facilitating richer interactions and responses.
This commit is contained in:
@@ -318,6 +318,68 @@
|
||||
<t-switch v-model="thinkingEnabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 图片上传(多模态) -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('agentEditor.imageUpload.label') }}</label>
|
||||
<p class="desc">{{ $t('agentEditor.imageUpload.desc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch v-model="formData.config.image_upload_enabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- VLM模型(图片上传启用时) -->
|
||||
<div v-if="formData.config.image_upload_enabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('agentEditor.imageUpload.vlmModel') }} <span class="required">*</span></label>
|
||||
<p class="desc">{{ $t('agentEditor.imageUpload.vlmModelDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<ModelSelector
|
||||
model-type="VLLM"
|
||||
:selected-model-id="formData.config.vlm_model_id"
|
||||
:all-models="allModels"
|
||||
@update:selected-model-id="(val: string) => formData.config.vlm_model_id = val"
|
||||
@add-model="handleAddModel('vllm')"
|
||||
:placeholder="$t('agentEditor.imageUpload.vlmModelPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 图片存储 Provider(图片上传启用时) -->
|
||||
<div v-if="formData.config.image_upload_enabled" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('agentEditor.imageUpload.storageProvider') }}</label>
|
||||
<p class="desc">{{ $t('agentEditor.imageUpload.storageProviderDesc') }}</p>
|
||||
</div>
|
||||
<div class="setting-control" style="flex-direction: column; align-items: flex-end;">
|
||||
<t-select
|
||||
v-model="formData.config.image_storage_provider"
|
||||
style="width: 280px;"
|
||||
:placeholder="$t('agentEditor.imageUpload.storageProviderPlaceholder')"
|
||||
clearable
|
||||
>
|
||||
<t-option value="" :label="$t('agentEditor.imageUpload.storageDefault')" />
|
||||
<t-option
|
||||
v-for="opt in imageStorageOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
:label="opt.label"
|
||||
:disabled="opt.disabled"
|
||||
>
|
||||
<span class="select-option-with-tag">
|
||||
<span>{{ opt.label }}</span>
|
||||
<t-tag v-if="opt.disabled" theme="warning" variant="light" size="small">{{ $t('agentEditor.imageUpload.notConfigured') }}</t-tag>
|
||||
</span>
|
||||
</t-option>
|
||||
</t-select>
|
||||
<a href="javascript:void(0)" class="go-settings-link" @click.prevent="uiStore.openSettings('storage')">
|
||||
{{ $t('agentEditor.imageUpload.goStorageSettings') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1066,7 +1128,7 @@ import { listModels, type ModelConfig } from '@/api/model';
|
||||
import { listKnowledgeBases } from '@/api/knowledge-base';
|
||||
import { listMCPServices, type MCPService } from '@/api/mcp-service';
|
||||
import { listSkills, type SkillInfo } from '@/api/skill';
|
||||
import { getAgentConfig, getConversationConfig } from '@/api/system';
|
||||
import { getAgentConfig, getConversationConfig, getStorageEngineStatus, type StorageEngineStatusItem } from '@/api/system';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { useOrganizationStore } from '@/stores/organization';
|
||||
import AgentAvatar from '@/components/AgentAvatar.vue';
|
||||
@@ -1099,6 +1161,21 @@ const mcpOptions = ref<{ label: string; value: string }[]>([]);
|
||||
const skillOptions = ref<{ name: string; description: string }[]>([]);
|
||||
// 是否允许启用 Skills(取决于后端沙箱是否启用,disabled 时为 false;未请求前为 false 避免闪显)
|
||||
const skillsAvailable = ref(false);
|
||||
// 存储引擎可用状态(用于图片存储 provider 选择)
|
||||
const storageEngineStatus = ref<StorageEngineStatusItem[]>([]);
|
||||
const imageStorageOptions = computed(() => {
|
||||
const statusMap: Record<string, boolean> = {};
|
||||
for (const e of storageEngineStatus.value) {
|
||||
statusMap[e.name] = e.available;
|
||||
}
|
||||
return [
|
||||
{ value: 'local', label: t('settings.storage.engineLocal'), disabled: false },
|
||||
{ value: 'minio', label: 'MinIO', disabled: statusMap.minio === false },
|
||||
{ value: 'cos', label: t('settings.storage.engineCos'), disabled: statusMap.cos === false },
|
||||
{ value: 'tos', label: t('settings.storage.engineTos'), disabled: statusMap.tos === false },
|
||||
{ value: 's3', label: 'Amazon S3', disabled: statusMap.s3 === false },
|
||||
];
|
||||
});
|
||||
|
||||
// 系统默认配置(用于内置智能体显示默认提示词)
|
||||
const defaultAgentSystemPrompt = ref(''); // Agent 模式的默认系统提示词(来自 agent-config)
|
||||
@@ -1320,6 +1397,10 @@ const defaultFormData = {
|
||||
// 知识库设置
|
||||
kb_selection_mode: 'none' as 'all' | 'selected' | 'none',
|
||||
knowledge_bases: [] as string[],
|
||||
// 图片上传/多模态设置
|
||||
image_upload_enabled: false,
|
||||
vlm_model_id: '',
|
||||
image_storage_provider: '',
|
||||
// 文件类型限制
|
||||
supported_file_types: [] as string[],
|
||||
// FAQ 策略设置
|
||||
@@ -1642,12 +1723,18 @@ watch(() => uiStore.showSettingsModal, async (visible, prevVisible) => {
|
||||
// 从设置页面返回时(弹窗关闭),刷新模型列表
|
||||
if (prevVisible && !visible && props.visible) {
|
||||
try {
|
||||
const models = await listModels();
|
||||
const [models, statusRes] = await Promise.all([
|
||||
listModels(),
|
||||
getStorageEngineStatus(),
|
||||
]);
|
||||
if (models && models.length > 0) {
|
||||
allModels.value = models;
|
||||
}
|
||||
if (statusRes?.data?.engines) {
|
||||
storageEngineStatus.value = statusRes.data.engines;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to refresh models after settings closed', e);
|
||||
console.warn('Failed to refresh data after settings closed', e);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1725,6 +1812,16 @@ const loadDependencies = async () => {
|
||||
skillsAvailable.value = false;
|
||||
}
|
||||
|
||||
// 加载存储引擎可用状态(用于图片存储 provider 选择)
|
||||
try {
|
||||
const statusRes = await getStorageEngineStatus();
|
||||
if (statusRes?.data?.engines) {
|
||||
storageEngineStatus.value = statusRes.data.engines;
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to load storage engine status', e);
|
||||
}
|
||||
|
||||
// 加载占位符定义(从统一 API)
|
||||
try {
|
||||
const placeholdersRes = await getPlaceholders();
|
||||
@@ -2627,6 +2724,13 @@ const handleSave = async () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验 VLM 模型(当图片上传启用时必填)
|
||||
if (formData.value.config.image_upload_enabled && !formData.value.config.vlm_model_id) {
|
||||
MessagePlugin.error(t('agentEditor.imageUpload.vlmModelRequired'));
|
||||
currentSection.value = 'model';
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验 ReRank 模型(当需要时必填)
|
||||
if (needsRerankModel.value && !formData.value.config.rerank_model_id) {
|
||||
MessagePlugin.error(t('agent.editor.rerankModelRequired'));
|
||||
@@ -2914,6 +3018,24 @@ const handleSave = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
.select-option-with-tag {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.go-settings-link {
|
||||
font-size: 12px;
|
||||
color: var(--td-brand-color);
|
||||
margin-top: 4px;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
// 名称输入框带头像预览
|
||||
.name-input-wrapper {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user