|
@@ -1,6 +1,7 @@
|
|
|
import LoginModal from "@/components/LoginModal";
|
|
|
import MarkdownIt from "markdown-it";
|
|
|
import { pcInnerAi,getMinioURl } from "@/api/api";
|
|
|
+import {modelList,listBuckets,selectTypeList,getBucketContents,configSave,configList} from "@/api/knowledge"
|
|
|
import axios from 'axios';
|
|
|
const md = new MarkdownIt();
|
|
|
|
|
@@ -34,30 +35,66 @@ export default {
|
|
|
AImodel:'1',//模型
|
|
|
AIknowledgeBase:"1",//知识库
|
|
|
AIFile:'1',//文件
|
|
|
- chatHistory: [
|
|
|
- {
|
|
|
- username: "Theresa Rose",
|
|
|
- avatar: "/path/to/avatar1.jpg",
|
|
|
- timestamp: "08:33AM",
|
|
|
- message: "I hope I can finish Frox soon",
|
|
|
- preview: "Hi, what's new with Frox? Please upload the latest code, and I will check today"
|
|
|
- },
|
|
|
- {
|
|
|
- username: "Theresa Rose",
|
|
|
- avatar: "/path/to/avatar2.jpg",
|
|
|
- timestamp: "08:33AM",
|
|
|
- message: "I hope I can finish Frox soon",
|
|
|
- preview: "Hi, what's new with Frox? Please upload the latest code, and I will check today"
|
|
|
- },
|
|
|
- // Add more chat history items as needed
|
|
|
- ],
|
|
|
- currentChatIndex: 0,
|
|
|
+ AIform:{
|
|
|
+ chat_name:'',
|
|
|
+ modelLibrary: 'ollama',
|
|
|
+ model_type: 'chat',
|
|
|
+ model_name: '',
|
|
|
+ knowledge_base_names: [],
|
|
|
+ document_directories: [],
|
|
|
+ documents: [],
|
|
|
+ temperature: 0.7,
|
|
|
+ max_tokens: 150,
|
|
|
+ top_p: 1.0,
|
|
|
+ frequency_penalty: 0.0,
|
|
|
+ presence_penalty: 0.0,
|
|
|
+ response_format: "text",
|
|
|
+ context_window: 2048,
|
|
|
+ user_id: "user123",
|
|
|
+ session_id: "session456",
|
|
|
+ language: "en",
|
|
|
+ timeout: 30,
|
|
|
+ role_name: "Admin",
|
|
|
+ role_description: "Administrator role with full access.",
|
|
|
+ role_permissions: ["read", "write", "delete"]
|
|
|
+ },
|
|
|
+ /* 模型库 */
|
|
|
+ modelList:[],
|
|
|
+ /* 模型类型 */
|
|
|
+ modelTypeList:[],
|
|
|
+ /* 模型名称 */
|
|
|
+ modelNameList:[],
|
|
|
+ /* 知识库 */
|
|
|
+ kneList:[],
|
|
|
+ /* 文档目录 */
|
|
|
+ directoryList: [],
|
|
|
+ /* 文档 */
|
|
|
+ documentList: [],
|
|
|
+ bucket_id:'',
|
|
|
+ rules: {
|
|
|
+ chat_name: [
|
|
|
+ { required: true, message: '请填写应名称', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ modelName: [
|
|
|
+ { required: true, message: '请选择模型名称', trigger: 'change' }
|
|
|
+ ],
|
|
|
+ knowledge_base_names: [
|
|
|
+ { required: true, message: '请选择至少一个知识库', trigger: 'change' }
|
|
|
+ ],
|
|
|
+ document_directories: [
|
|
|
+ { required: true, message: '请选择文档目录', trigger: 'change' }
|
|
|
+ ],
|
|
|
+ documents: [
|
|
|
+ { required: true, message: '请选择至少一个文档', trigger: 'change' }
|
|
|
+ ]
|
|
|
+ }
|
|
|
};
|
|
|
},
|
|
|
created() {
|
|
|
// this.connectWebSocket();
|
|
|
},
|
|
|
mounted() {
|
|
|
+ /* */
|
|
|
if(this.$route.name=='ai'){
|
|
|
/* 外部知识库 */
|
|
|
const AIData=JSON.parse(sessionStorage.getItem("AIData"))
|
|
@@ -69,12 +106,146 @@ export default {
|
|
|
if(res.status!==200) return
|
|
|
this.wsUrl=res.data.url
|
|
|
this.tweaks=res.data.tweaks
|
|
|
-
|
|
|
})
|
|
|
-
|
|
|
}
|
|
|
+ /* 获取模型列表 */
|
|
|
+ this.init()
|
|
|
},
|
|
|
methods: {
|
|
|
+ /* 生成引用 */
|
|
|
+ generateApplication() {
|
|
|
+ this.$refs.AIformRef.validate(async (valid) => {
|
|
|
+ if (valid) {
|
|
|
+ try {
|
|
|
+ // 创建一个新对象来存储转换后的数据
|
|
|
+ const convertedForm = { ...this.AIform };
|
|
|
+
|
|
|
+ // 将知识库 ID 转换为名称
|
|
|
+ convertedForm.knowledge_base_names = this.safeGetNamesByIds(this.AIform.knowledge_base_names, this.kneList);
|
|
|
+
|
|
|
+ // 将文档 ID 转换为名称
|
|
|
+ convertedForm.documents = this.safeGetNamesByIds(this.AIform.documents, this.documentList);
|
|
|
+
|
|
|
+ // 将文档目录 ID 转换为名称,如果为空则传递 '全部'
|
|
|
+ convertedForm.document_directories = this.safeGetNamesByIds(this.AIform.document_directories, this.directoryList);
|
|
|
+ if (convertedForm.document_directories.length === 0) {
|
|
|
+ convertedForm.document_directories = ['全部'];
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('Converted form:', convertedForm);
|
|
|
+
|
|
|
+ // 使用 axios 发送 POST 请求
|
|
|
+ const response = await axios.post(`http://192.168.1.199:8084/chatbot/configSave/`, convertedForm, {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.status === 200 && response.data.code === 200) {
|
|
|
+ this.$message.success('应用生成成功');
|
|
|
+ // 可选:重定向到新应用或更新 UI
|
|
|
+ } else {
|
|
|
+ this.$message.error(response.data.message || '应用生成失败');
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error generating application:', error);
|
|
|
+ this.$message.error('应用生成失败,请稍后重试');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message.error('请填写所有必填字段');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 安全的辅助方法:通过 ID 数组获取名称数组
|
|
|
+ safeGetNamesByIds(ids, list) {
|
|
|
+ if (!Array.isArray(ids)) {
|
|
|
+ console.warn('Expected an array of ids, but received:', ids);
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ return ids.map(id => {
|
|
|
+ if (id === '001') {
|
|
|
+ return '全部';
|
|
|
+ }
|
|
|
+ const item = list.find(item => item.id === id);
|
|
|
+ return item ? item.name : '';
|
|
|
+ }).filter(name => name !== '');
|
|
|
+ },
|
|
|
+ /* 监听联动 */
|
|
|
+ handleKnowledgeBaseChange(val) {
|
|
|
+ // 重置目录和文档选择
|
|
|
+ this.AIform.document_directories = [];
|
|
|
+ this.AIform.documents = [];
|
|
|
+ this.documentList = [];
|
|
|
+ this.bucket_id=val[0]
|
|
|
+ // 根据选中的知识库加载目录列表
|
|
|
+ // 这里需要调用后端 API 来获取目录列表
|
|
|
+ this.loadDirectoryList(val);
|
|
|
+ },
|
|
|
+ handleDirectoryChange(val) {
|
|
|
+ // 重置文档选择
|
|
|
+ this.AIform.documents = [];
|
|
|
+
|
|
|
+ // 根据选中的目录加载文档列表
|
|
|
+ // 这里需要调用后端 API 来获取文档列表
|
|
|
+ this.loadDocumentList(val);
|
|
|
+ },
|
|
|
+ async loadDirectoryList(val) {
|
|
|
+ this.directoryList = []; // 清空现有目录列表
|
|
|
+ let totalDocuments = 0;
|
|
|
+ let otherFolderCount = 0;
|
|
|
+
|
|
|
+ for (const kbId of val) {
|
|
|
+ const typeForm = {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 9999,
|
|
|
+ kb_id: kbId,
|
|
|
+ };
|
|
|
+
|
|
|
+ try {
|
|
|
+ const res = await selectTypeList(typeForm);
|
|
|
+ // 假设 res.data 包含目录列表
|
|
|
+ if (res.data && Array.isArray(res.data)) {
|
|
|
+ // 将新的目录添加到列表中,避免重复
|
|
|
+ this.directoryList = [...new Set([...this.directoryList, ...res.data])];
|
|
|
+
|
|
|
+ // 计算总文档数和其他文件夹数量
|
|
|
+ res.data.forEach(folder => {
|
|
|
+ if (folder.id === "other") {
|
|
|
+ otherFolderCount += folder.document_count || 0;
|
|
|
+ } else {
|
|
|
+ totalDocuments += folder.document_count || 0;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error(`Error loading directory list for kb_id ${kbId}:`, error);
|
|
|
+ // 可以在这里添加错误处理,比如显示一个错误提示
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 在列表开头插入"全部"选项
|
|
|
+ this.directoryList.unshift({
|
|
|
+ id: "001",
|
|
|
+ name: "全部",
|
|
|
+ document_count: totalDocuments + otherFolderCount,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ loadDocumentList(val) {
|
|
|
+ let queryForm={
|
|
|
+ page: 1,
|
|
|
+ pageSize: 9999,
|
|
|
+ bucket_id: this.bucket_id,
|
|
|
+ doc_type_id: val[0]=='001'?0 :val[0],
|
|
|
+ }
|
|
|
+ getBucketContents(queryForm).then(res=>{
|
|
|
+ console.log(res);
|
|
|
+ this.documentList=res.data.documents
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
/* 聊天记录 */
|
|
|
selectChat(index) {
|
|
|
this.currentChatIndex = index;
|
|
@@ -422,9 +593,25 @@ newChat() {
|
|
|
this.websocket.close();
|
|
|
}
|
|
|
},
|
|
|
+ /* 获取列表 */
|
|
|
+ init(){
|
|
|
+ /* 模型库 */
|
|
|
+ modelList({model_type:'model'}).then(res=>{
|
|
|
+ this.modelNameList=res.data
|
|
|
+ })
|
|
|
+ /* 知识库 */
|
|
|
+ listBuckets({ user_id: this.$store.state.user.id }).then(res=>{
|
|
|
+ this.kneList=res.data
|
|
|
+ })
|
|
|
+ /* 配置列表 */
|
|
|
+ configList().then(res=>{
|
|
|
+ console.log(res);
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
updated() {
|
|
|
const messagesContainer = this.$el.querySelector(".messages");
|
|
|
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
|
|
},
|
|
|
+
|
|
|
};
|