180 lines
4.4 KiB
Vue
180 lines
4.4 KiB
Vue
<template>
|
|
<div class="dialogue-wrap">
|
|
<div class="dialogue-answers">
|
|
<div class="dialogue-title">
|
|
<span>基于知识库内容问答 - AI 问答</span>
|
|
</div>
|
|
<InputField @send-msg="sendMsg"></InputField>
|
|
</div>
|
|
</div>
|
|
</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 { useRoute, useRouter } from 'vue-router';
|
|
import { MessagePlugin } from 'tdesign-vue-next';
|
|
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
const usemenuStore = useMenuStore();
|
|
const settingsStore = useSettingsStore();
|
|
|
|
const sendMsg = (value: string) => {
|
|
createNewSession(value);
|
|
}
|
|
|
|
async function createNewSession(value: string) {
|
|
const selectedKbs = settingsStore.settings.selectedKnowledgeBases;
|
|
|
|
if (!selectedKbs || selectedKbs.length === 0) {
|
|
MessagePlugin.warning('请先选择知识库');
|
|
return;
|
|
}
|
|
|
|
// 构建 session 数据,包含 Agent 配置
|
|
const sessionData: any = {};
|
|
|
|
// 添加 Agent 配置(知识库信息在 agent_config 中)
|
|
sessionData.agent_config = {
|
|
enabled: true,
|
|
max_iterations: settingsStore.agentConfig.maxIterations,
|
|
temperature: settingsStore.agentConfig.temperature,
|
|
thinking_model_id: settingsStore.agentConfig.thinkingModelId,
|
|
knowledge_bases: selectedKbs, // 所有选中的知识库
|
|
allowed_tools: settingsStore.agentConfig.allowedTools
|
|
};
|
|
|
|
try {
|
|
const res = await createSessions(sessionData);
|
|
if (res.data && res.data.id) {
|
|
await navigateToSession(res.data.id, value, selectedKbs[0]);
|
|
} else {
|
|
console.error("创建会话失败");
|
|
MessagePlugin.error("创建会话失败");
|
|
}
|
|
} catch (error) {
|
|
console.error("创建会话出错:", error);
|
|
MessagePlugin.error("创建会话失败,请稍后重试");
|
|
}
|
|
}
|
|
|
|
const navigateToSession = async (sessionId: string, value: string, kbId: string) => {
|
|
let obj = {
|
|
title: '新会话',
|
|
path: `chat/${kbId}/${sessionId}`,
|
|
id: sessionId,
|
|
isMore: false,
|
|
isNoTitle: true
|
|
};
|
|
usemenuStore.updataMenuChildren(obj);
|
|
usemenuStore.changeIsFirstSession(true);
|
|
usemenuStore.changeFirstQuery(value);
|
|
router.push(`/platform/chat/${kbId}/${sessionId}`);
|
|
}
|
|
|
|
</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: #000000;
|
|
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: #FFF;
|
|
box-shadow: 0 0 2px -1px #0000001f;
|
|
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> |