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;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="action-header" @click="toggleEvent(event.event_id)">
|
||||
<div class="action-title">
|
||||
<img class="action-title-icon" :src="thinkingIcon" alt="" />
|
||||
<span class="action-name">{{ $t('agent.think') }}</span>
|
||||
<span v-if="isEventExpanded(event.event_id)" class="action-name">{{ $t('agent.think') }}</span>
|
||||
<span v-if="getThinkingSummary(event) && !isEventExpanded(event.event_id)" class="action-summary">{{ getThinkingSummary(event) }}</span>
|
||||
</div>
|
||||
<div v-if="event.content" class="action-show-icon">
|
||||
@@ -134,12 +134,7 @@
|
||||
<div class="detail-output">{{ event.output }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="event.arguments && event.tool_name !== 'todo_write' && !event.display_type" class="tool-arguments-wrapper">
|
||||
<div class="arguments-header">
|
||||
<span class="arguments-label">{{ $t('agent.argumentsLabel') }}</span>
|
||||
</div>
|
||||
<pre class="detail-code">{{ formatJSON(event.arguments) }}</pre>
|
||||
</div>
|
||||
<!-- Raw arguments hidden for user-friendly display -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -296,12 +291,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="event.arguments && event.tool_name !== 'todo_write' && !event.display_type" class="tool-arguments-wrapper">
|
||||
<div class="arguments-header">
|
||||
<span class="arguments-label">{{ $t('agent.argumentsLabel') }}</span>
|
||||
</div>
|
||||
<pre class="detail-code">{{ formatJSON(event.arguments) }}</pre>
|
||||
</div>
|
||||
<!-- Raw arguments hidden for user-friendly display -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -435,6 +425,7 @@ const TOOL_NAME_KEYS: Record<string, string> = {
|
||||
todo_write: 'agentStream.tools.todoWrite',
|
||||
knowledge_graph_extract: 'agentStream.tools.knowledgeGraphExtract',
|
||||
thinking: 'agentStream.tools.thinking',
|
||||
image_analysis: 'agentStream.tools.imageAnalysis',
|
||||
};
|
||||
|
||||
const getLocalizedToolName = (toolName?: string | null): string => {
|
||||
@@ -443,6 +434,42 @@ const getLocalizedToolName = (toolName?: string | null): string => {
|
||||
return key ? t(key) : toolName;
|
||||
};
|
||||
|
||||
const TOOL_NAME_DISPLAY: Record<string, string> = {
|
||||
knowledge_search: '语义搜索',
|
||||
search_knowledge: '语义搜索',
|
||||
grep_chunks: '文本搜索',
|
||||
list_knowledge_chunks: '阅读文档内容',
|
||||
get_document_info: '获取文档信息',
|
||||
query_knowledge_graph: '知识图谱查询',
|
||||
web_search: '网络搜索',
|
||||
web_fetch: '网页抓取',
|
||||
todo_write: '制定计划',
|
||||
final_answer: '生成回答',
|
||||
thinking: '思考',
|
||||
read_skill: '读取技能',
|
||||
execute_skill_script: '执行技能脚本',
|
||||
data_analysis: '数据分析',
|
||||
data_schema: '数据结构',
|
||||
database_query: '数据库查询',
|
||||
image_analysis: '查看图片内容',
|
||||
};
|
||||
|
||||
const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
||||
const ID_LABEL_RE = /\b(knowledge_base_id|knowledge_id|chunk_id|knowledge_base_ids)\s*[:=]\s*/gi;
|
||||
|
||||
const sanitizeForDisplay = (text: string): string => {
|
||||
if (!text) return text;
|
||||
let result = text;
|
||||
for (const [name, display] of Object.entries(TOOL_NAME_DISPLAY)) {
|
||||
result = result.replaceAll(name, display);
|
||||
}
|
||||
result = result.replace(ID_LABEL_RE, '');
|
||||
result = result.replace(UUID_RE, '');
|
||||
result = result.replace(/`\s*`/g, '');
|
||||
result = result.replace(/\(\s*\)/g, '');
|
||||
return result;
|
||||
};
|
||||
|
||||
// 根元素引用
|
||||
const rootElement = ref<HTMLElement | null>(null);
|
||||
|
||||
@@ -759,13 +786,12 @@ const getThinkingContent = (event: any): string => {
|
||||
const getThinkingSummary = (event: any): string => {
|
||||
const content = getThinkingContent(event);
|
||||
if (!content) return '';
|
||||
// Strip markdown formatting and take first meaningful line
|
||||
const cleaned = content
|
||||
.replace(/^#+\s+/gm, '') // remove heading markers
|
||||
.replace(/\*\*/g, '') // remove bold
|
||||
.replace(/\*/g, '') // remove italic
|
||||
.replace(/`/g, '') // remove code ticks
|
||||
.replace(/\n+/g, ' ') // collapse newlines
|
||||
const cleaned = sanitizeForDisplay(content)
|
||||
.replace(/^#+\s+/gm, '')
|
||||
.replace(/\*\*/g, '')
|
||||
.replace(/\*/g, '')
|
||||
.replace(/`/g, '')
|
||||
.replace(/\n+/g, ' ')
|
||||
.trim();
|
||||
if (cleaned.length <= 50) return cleaned;
|
||||
return cleaned.slice(0, 50) + '...';
|
||||
@@ -1321,12 +1347,12 @@ const preprocessMarkdown = (contentStr: string): string => {
|
||||
);
|
||||
};
|
||||
|
||||
// Get tokens from markdown content
|
||||
// Get tokens from markdown content (with sanitization for user-friendly display)
|
||||
const getTokens = (content: any) => {
|
||||
const contentStr = typeof content === 'string' ? content : String(content || '');
|
||||
if (!contentStr.trim()) return [];
|
||||
|
||||
const processed = preprocessMarkdown(contentStr);
|
||||
const processed = preprocessMarkdown(sanitizeForDisplay(contentStr));
|
||||
return marked.lexer(processed);
|
||||
};
|
||||
|
||||
@@ -1524,6 +1550,8 @@ const getToolIcon = (toolName: string): string => {
|
||||
return documentIcon;
|
||||
} else if (toolName === 'todo_write') {
|
||||
return fileAddIcon;
|
||||
} else if (toolName === 'image_analysis') {
|
||||
return thinkingIcon;
|
||||
} else {
|
||||
return documentIcon; // default icon
|
||||
}
|
||||
@@ -1621,6 +1649,9 @@ const getQueryText = (args: any): string => {
|
||||
// Get tool title - prefer summary over description, add query for search tools
|
||||
const getToolTitle = (event: any): string => {
|
||||
if (event.pending) {
|
||||
if (event.tool_name === 'image_analysis') {
|
||||
return t('agentStream.toolStatus.imageAnalyzing');
|
||||
}
|
||||
const localizedName = getLocalizedToolName(event.tool_name);
|
||||
return t('agentStream.toolStatus.calling', { name: localizedName });
|
||||
}
|
||||
@@ -1706,6 +1737,9 @@ const getToolTitle = (event: any): string => {
|
||||
// Tool description
|
||||
const getToolDescription = (event: any): string => {
|
||||
if (event.pending) {
|
||||
if (event.tool_name === 'image_analysis') {
|
||||
return t('agentStream.toolStatus.imageAnalyzing');
|
||||
}
|
||||
const localizedName = getLocalizedToolName(event.tool_name);
|
||||
return t('agentStream.toolStatus.calling', { name: localizedName });
|
||||
}
|
||||
@@ -1723,6 +1757,8 @@ const getToolDescription = (event: any): string => {
|
||||
return success ? t('agentStream.toolStatus.thinkingDone') : t('agentStream.toolStatus.thinkingFailed');
|
||||
} else if (toolName === 'todo_write') {
|
||||
return success ? t('agentStream.toolStatus.updateTodos') : t('agentStream.toolStatus.updateTodosFailed');
|
||||
} else if (toolName === 'image_analysis') {
|
||||
return success ? t('agentStream.toolStatus.imageAnalysisDone') : t('agentStream.toolStatus.imageAnalysisFailed');
|
||||
} else {
|
||||
const localizedName = getLocalizedToolName(toolName);
|
||||
return success ? t('agentStream.toolStatus.called', { name: localizedName }) : t('agentStream.toolStatus.calledFailed', { name: localizedName });
|
||||
@@ -2121,7 +2157,6 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
|
||||
&.action-error {
|
||||
border-left: 2px solid var(--td-error-color);
|
||||
animation: shakeError 0.4s ease-out;
|
||||
}
|
||||
|
||||
&.action-pending {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="user_msg_container">
|
||||
<div class="user_msg_container" ref="containerRef">
|
||||
<!-- 显示@的知识库和文件 -->
|
||||
<div v-if="mentioned_items && mentioned_items.length > 0" class="mentioned_items">
|
||||
<span
|
||||
@@ -17,27 +17,70 @@
|
||||
<span class="tag_name">{{ item.name }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<!-- 显示上传的图片 -->
|
||||
<div v-if="hasImages" class="user_images">
|
||||
<img
|
||||
v-for="(img, idx) in props.images"
|
||||
:key="idx"
|
||||
:src="img.url"
|
||||
class="user_image_thumb"
|
||||
@click="previewImage($event)"
|
||||
/>
|
||||
</div>
|
||||
<div class="user_msg">
|
||||
{{ content }}
|
||||
</div>
|
||||
<picturePreview :reviewImg="reviewImg" :reviewUrl="reviewUrl" @closePreImg="closePreImg" />
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { defineProps } from "vue";
|
||||
import { defineProps, computed, ref, watch, onMounted, nextTick } from "vue";
|
||||
import { hydrateProtectedFileImages } from '@/utils/security';
|
||||
import picturePreview from '@/components/picture-preview.vue';
|
||||
|
||||
const props = defineProps({
|
||||
// 必填项
|
||||
content: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
// @提及的知识库和文件
|
||||
mentioned_items: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: () => []
|
||||
},
|
||||
images: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: () => []
|
||||
}
|
||||
});
|
||||
|
||||
const containerRef = ref(null);
|
||||
const hasImages = computed(() => props.images && props.images.length > 0);
|
||||
|
||||
const hydrateImages = async () => {
|
||||
await nextTick();
|
||||
await hydrateProtectedFileImages(containerRef.value);
|
||||
};
|
||||
|
||||
watch(() => props.images, hydrateImages);
|
||||
onMounted(hydrateImages);
|
||||
|
||||
const reviewImg = ref(false);
|
||||
const reviewUrl = ref('');
|
||||
|
||||
const previewImage = (event) => {
|
||||
const src = event.target?.src;
|
||||
if (src) {
|
||||
reviewUrl.value = src;
|
||||
reviewImg.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
const closePreImg = () => {
|
||||
reviewImg.value = false;
|
||||
reviewUrl.value = '';
|
||||
};
|
||||
</script>
|
||||
<style scoped lang="less">
|
||||
.user_msg_container {
|
||||
@@ -125,6 +168,28 @@ const props = defineProps({
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.user_images {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
justify-content: flex-end;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.user_image_thumb {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
object-fit: cover;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
border: 1px solid var(--td-border-level-2-color, #e7e7e7);
|
||||
transition: opacity 0.2s;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
|
||||
html[theme-mode="dark"] {
|
||||
.user_msg {
|
||||
background: var(--td-brand-color-3);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="msg_list">
|
||||
<div v-for="(session, id) in messagesList" :key='id'>
|
||||
<div v-if="session.role == 'user'">
|
||||
<usermsg :content="session.content" :mentioned_items="session.mentioned_items"></usermsg>
|
||||
<usermsg :content="session.content" :mentioned_items="session.mentioned_items" :images="session.images"></usermsg>
|
||||
</div>
|
||||
<div v-if="session.role == 'assistant'">
|
||||
<botmsg :content="session.content" :session="session" :user-query="getUserQuery(id)" @scroll-bottom="scrollToBottom"
|
||||
@@ -23,7 +23,7 @@
|
||||
</div>
|
||||
<div style="min-height: 115px; margin: 16px auto 4px;width: 100%;max-width: 800px;">
|
||||
<InputField
|
||||
@send-msg="(query, modelId, mentionedItems) => sendMsg(query, modelId, mentionedItems)"
|
||||
@send-msg="(query, modelId, mentionedItems, imageFiles) => sendMsg(query, modelId, mentionedItems, imageFiles)"
|
||||
@stop-generation="handleStopGeneration"
|
||||
:isReplying="isReplying"
|
||||
:sessionId="session_id"
|
||||
@@ -61,7 +61,7 @@ const useSettingsStoreInstance = useSettingsStore();
|
||||
const uiStore = useUIStore();
|
||||
const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
|
||||
const { t } = useI18n();
|
||||
const { menuArr, isFirstSession, firstQuery, firstMentionedItems, firstModelId } = storeToRefs(usemenuStore);
|
||||
const { menuArr, isFirstSession, firstQuery, firstMentionedItems, firstModelId, firstImageFiles } = storeToRefs(usemenuStore);
|
||||
const { output, onChunk, isStreaming, isLoading, error, startStream, stopStream } = useStream();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -83,6 +83,15 @@ const handleKBEditorSuccess = (kbId) => {
|
||||
navigateToKnowledgeBaseList(kbId)
|
||||
}
|
||||
|
||||
function fileToBase64(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => resolve(reader.result);
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
|
||||
const getUserQuery = (index) => {
|
||||
if (index <= 0) {
|
||||
return '';
|
||||
@@ -323,12 +332,31 @@ const handleStopGeneration = () => {
|
||||
// API 调用成功后,后端的 stop 事件会清空它
|
||||
};
|
||||
|
||||
const sendMsg = async (value, modelId = '', mentionedItems = []) => {
|
||||
const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []) => {
|
||||
userquery.value = value;
|
||||
isReplying.value = true;
|
||||
loading.value = true;
|
||||
|
||||
// Convert images to base64 data URIs for backend processing and local display
|
||||
let imageAttachments = [];
|
||||
let userImages = [];
|
||||
if (imageFiles && imageFiles.length > 0) {
|
||||
try {
|
||||
for (const file of imageFiles) {
|
||||
const dataURI = await fileToBase64(file);
|
||||
imageAttachments.push({ data: dataURI });
|
||||
userImages.push({ url: dataURI });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Image] Failed to read images:', e);
|
||||
loading.value = false;
|
||||
isReplying.value = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 将@提及的知识库和文件信息存入用户消息
|
||||
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems });
|
||||
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems, images: userImages });
|
||||
scrollToBottom();
|
||||
|
||||
// Get agent mode status from settings store
|
||||
@@ -377,6 +405,7 @@ const sendMsg = async (value, modelId = '', mentionedItems = []) => {
|
||||
summary_model_id: modelId,
|
||||
mcp_service_ids: mcpServiceIds,
|
||||
mentioned_items: mentionedItems,
|
||||
images: imageAttachments.length > 0 ? imageAttachments : undefined,
|
||||
query: value,
|
||||
method: 'POST',
|
||||
url: endpoint
|
||||
@@ -953,8 +982,8 @@ onMounted(async () => {
|
||||
checkmenuTitle(session_id.value)
|
||||
if (firstQuery.value) {
|
||||
scrollLock.value = true;
|
||||
sendMsg(firstQuery.value, firstModelId.value || '', firstMentionedItems.value || []);
|
||||
usemenuStore.changeFirstQuery('', [], '');
|
||||
sendMsg(firstQuery.value, firstModelId.value || '', firstMentionedItems.value || [], firstImageFiles.value || []);
|
||||
usemenuStore.changeFirstQuery('', [], '', []);
|
||||
} else {
|
||||
scrollLock.value = false;
|
||||
let data = {
|
||||
|
||||
@@ -39,11 +39,11 @@ const uiStore = useUIStore();
|
||||
const { t } = useI18n();
|
||||
const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
|
||||
|
||||
const sendMsg = (value: string, modelId: string, mentionedItems: any[]) => {
|
||||
createNewSession(value, modelId, mentionedItems);
|
||||
const sendMsg = (value: string, modelId: string, mentionedItems: any[], imageFiles: any[] = []) => {
|
||||
createNewSession(value, modelId, mentionedItems, imageFiles);
|
||||
}
|
||||
|
||||
async function createNewSession(value: string, modelId: string, mentionedItems: any[] = []) {
|
||||
async function createNewSession(value: string, modelId: string, mentionedItems: any[] = [], imageFiles: any[] = []) {
|
||||
const selectedKbs = settingsStore.settings.selectedKnowledgeBases || [];
|
||||
const selectedFiles = settingsStore.settings.selectedFiles || [];
|
||||
|
||||
@@ -63,7 +63,7 @@ async function createNewSession(value: string, modelId: string, mentionedItems:
|
||||
try {
|
||||
const res = await createSessions(sessionData);
|
||||
if (res.data && res.data.id) {
|
||||
await navigateToSession(res.data.id, value, modelId, mentionedItems);
|
||||
await navigateToSession(res.data.id, value, modelId, mentionedItems, imageFiles);
|
||||
} else {
|
||||
console.error('[createChat] Failed to create session');
|
||||
MessagePlugin.error(t('createChat.messages.createFailed'));
|
||||
@@ -74,7 +74,7 @@ async function createNewSession(value: string, modelId: string, mentionedItems:
|
||||
}
|
||||
}
|
||||
|
||||
const navigateToSession = async (sessionId: string, value: string, modelId: string, mentionedItems: any[]) => {
|
||||
const navigateToSession = async (sessionId: string, value: string, modelId: string, mentionedItems: any[], imageFiles: any[] = []) => {
|
||||
const now = new Date().toISOString();
|
||||
let obj = {
|
||||
title: t('createChat.newSessionTitle'),
|
||||
@@ -87,7 +87,7 @@ const navigateToSession = async (sessionId: string, value: string, modelId: stri
|
||||
};
|
||||
usemenuStore.updataMenuChildren(obj);
|
||||
usemenuStore.changeIsFirstSession(true);
|
||||
usemenuStore.changeFirstQuery(value, mentionedItems, modelId);
|
||||
usemenuStore.changeFirstQuery(value, mentionedItems, modelId, imageFiles);
|
||||
router.push(`/platform/chat/${sessionId}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -293,7 +293,8 @@ function convertToLegacyFormat(model: ModelConfig) {
|
||||
apiKey: model.parameters.api_key || '',
|
||||
provider: model.parameters.provider || '', // 添加 provider 字段
|
||||
dimension: model.parameters.embedding_parameters?.dimension,
|
||||
isBuiltin: model.is_builtin || false
|
||||
isBuiltin: model.is_builtin || false,
|
||||
supportsVision: model.parameters.supports_vision || false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,6 +409,9 @@ const handleModelSave = async (modelData: any) => {
|
||||
dimension: modelData.dimension,
|
||||
truncate_prompt_tokens: 0
|
||||
}
|
||||
} : {}),
|
||||
...((currentModelType.value === 'chat' || currentModelType.value === 'vllm') ? {
|
||||
supports_vision: modelData.supportsVision ?? false
|
||||
} : {})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user