991bd29a14
- 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.
200 lines
5.6 KiB
Vue
200 lines
5.6 KiB
Vue
<template>
|
||
<div class="dialogue-wrap">
|
||
<div class="dialogue-answers">
|
||
<div class="dialogue-title">
|
||
<span>{{ $t('createChat.title') }}</span>
|
||
</div>
|
||
<InputField @send-msg="sendMsg"></InputField>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 知识库编辑器(创建/编辑统一组件) -->
|
||
<KnowledgeBaseEditorModal
|
||
:visible="uiStore.showKBEditorModal"
|
||
:mode="uiStore.kbEditorMode"
|
||
:kb-id="uiStore.currentKBId || undefined"
|
||
:initial-type="uiStore.kbEditorType"
|
||
@update:visible="(val) => val ? null : uiStore.closeKBEditor()"
|
||
@success="handleKBEditorSuccess"
|
||
/>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { ref } from 'vue';
|
||
import InputField from '@/components/Input-field.vue';
|
||
import { createSessions } from "@/api/chat/index";
|
||
import { useMenuStore } from '@/stores/menu';
|
||
import { useSettingsStore } from '@/stores/settings';
|
||
import { useUIStore } from '@/stores/ui';
|
||
import { useRoute, useRouter } from 'vue-router';
|
||
import { MessagePlugin } from 'tdesign-vue-next';
|
||
import { useI18n } from 'vue-i18n';
|
||
import KnowledgeBaseEditorModal from '@/views/knowledge/KnowledgeBaseEditorModal.vue';
|
||
import { useKnowledgeBaseCreationNavigation } from '@/hooks/useKnowledgeBaseCreationNavigation';
|
||
|
||
const router = useRouter();
|
||
const route = useRoute();
|
||
const usemenuStore = useMenuStore();
|
||
const settingsStore = useSettingsStore();
|
||
const uiStore = useUIStore();
|
||
const { t } = useI18n();
|
||
const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
|
||
|
||
const sendMsg = (value: string, modelId: string, mentionedItems: any[], imageFiles: any[] = []) => {
|
||
createNewSession(value, modelId, mentionedItems, imageFiles);
|
||
}
|
||
|
||
async function createNewSession(value: string, modelId: string, mentionedItems: any[] = [], imageFiles: any[] = []) {
|
||
const selectedKbs = settingsStore.settings.selectedKnowledgeBases || [];
|
||
const selectedFiles = settingsStore.settings.selectedFiles || [];
|
||
|
||
// 构建 session 数据,包含 Agent 配置
|
||
const sessionData: any = {};
|
||
|
||
// 添加 Agent 配置(知识库信息在 agent_config 中)
|
||
sessionData.agent_config = {
|
||
enabled: true,
|
||
max_iterations: settingsStore.agentConfig.maxIterations,
|
||
temperature: settingsStore.agentConfig.temperature,
|
||
knowledge_bases: selectedKbs, // 所有选中的知识库
|
||
knowledge_ids: selectedFiles, // 所有选中的普通知识/文件
|
||
allowed_tools: settingsStore.agentConfig.allowedTools
|
||
};
|
||
|
||
try {
|
||
const res = await createSessions(sessionData);
|
||
if (res.data && res.data.id) {
|
||
await navigateToSession(res.data.id, value, modelId, mentionedItems, imageFiles);
|
||
} else {
|
||
console.error('[createChat] Failed to create session');
|
||
MessagePlugin.error(t('createChat.messages.createFailed'));
|
||
}
|
||
} catch (error) {
|
||
console.error('[createChat] Create session error:', error);
|
||
MessagePlugin.error(t('createChat.messages.createError'));
|
||
}
|
||
}
|
||
|
||
const navigateToSession = async (sessionId: string, value: string, modelId: string, mentionedItems: any[], imageFiles: any[] = []) => {
|
||
const now = new Date().toISOString();
|
||
let obj = {
|
||
title: t('createChat.newSessionTitle'),
|
||
path: `chat/${sessionId}`,
|
||
id: sessionId,
|
||
isMore: false,
|
||
isNoTitle: true,
|
||
created_at: now,
|
||
updated_at: now
|
||
};
|
||
usemenuStore.updataMenuChildren(obj);
|
||
usemenuStore.changeIsFirstSession(true);
|
||
usemenuStore.changeFirstQuery(value, mentionedItems, modelId, imageFiles);
|
||
router.push(`/platform/chat/${sessionId}`);
|
||
}
|
||
|
||
const handleKBEditorSuccess = (kbId: string) => {
|
||
navigateToKnowledgeBaseList(kbId)
|
||
}
|
||
|
||
</script>
|
||
<style lang="less" scoped>
|
||
.dialogue-wrap {
|
||
flex: 1;
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
// position: relative;
|
||
}
|
||
|
||
.dialogue-answers {
|
||
position: absolute;
|
||
display: flex;
|
||
flex-flow: column;
|
||
align-items: center;
|
||
|
||
:deep(.answers-input) {
|
||
position: static;
|
||
transform: translateX(0);
|
||
}
|
||
}
|
||
|
||
.dialogue-title {
|
||
display: flex;
|
||
color: var(--td-text-color-primary);
|
||
font-family: "PingFang SC";
|
||
font-size: 28px;
|
||
font-weight: 600;
|
||
align-items: center;
|
||
margin-bottom: 30px;
|
||
|
||
.icon {
|
||
display: flex;
|
||
width: 32px;
|
||
height: 32px;
|
||
justify-content: center;
|
||
align-items: center;
|
||
border-radius: 6px;
|
||
background: var(--td-bg-color-container);
|
||
box-shadow: var(--td-shadow-1);
|
||
margin-right: 12px;
|
||
|
||
.logo_img {
|
||
height: 24px;
|
||
width: 24px;
|
||
}
|
||
}
|
||
}
|
||
|
||
@media (max-width: 1250px) and (min-width: 1045px) {
|
||
.answers-input {
|
||
transform: translateX(-329px);
|
||
}
|
||
|
||
:deep(.t-textarea__inner) {
|
||
width: 654px !important;
|
||
}
|
||
}
|
||
|
||
@media (max-width: 1045px) {
|
||
.answers-input {
|
||
transform: translateX(-250px);
|
||
}
|
||
|
||
:deep(.t-textarea__inner) {
|
||
width: 500px !important;
|
||
}
|
||
}
|
||
@media (max-width: 750px) {
|
||
.answers-input {
|
||
transform: translateX(-250px);
|
||
}
|
||
|
||
:deep(.t-textarea__inner) {
|
||
width: 340px !important;
|
||
}
|
||
}
|
||
@media (max-width: 600px) {
|
||
.answers-input {
|
||
transform: translateX(-250px);
|
||
}
|
||
|
||
:deep(.t-textarea__inner) {
|
||
width: 300px !important;
|
||
}
|
||
}
|
||
|
||
</style>
|
||
<style lang="less">
|
||
.del-menu-popup {
|
||
z-index: 99 !important;
|
||
|
||
.t-popup__content {
|
||
width: 100px;
|
||
height: 40px;
|
||
line-height: 30px;
|
||
padding-left: 14px;
|
||
cursor: pointer;
|
||
margin-top: 4px !important;
|
||
|
||
}
|
||
}
|
||
</style> |