Ver Fonte

接口开发调整

S0025136190 há 10 meses atrás
pai
commit
19a472285f
24 ficheiros alterados com 1633 adições e 14 exclusões
  1. 212 8
      takai-admin/src/main/java/com/takai/web/controller/bigmodel/BigModelController.java
  2. 2 0
      takai-admin/src/main/resources/application.yml
  3. 136 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/ApplicationParams.java
  4. 24 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/BmApplication.java
  5. 26 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/DocumentObject.java
  6. 129 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/DocumentParams.java
  7. 24 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/IndexType.java
  8. 106 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/KnowledgeInfo.java
  9. 64 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/KnowledgeParams.java
  10. 17 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/Question.java
  11. 44 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/QuestionInfo.java
  12. 2 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/BmApplicationMapper.java
  13. 2 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/BmDocumentMapper.java
  14. 2 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/BmKnowledgeMapper.java
  15. 22 0
      takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/QuestionMapper.java
  16. 37 2
      takai-bigmodel/src/main/java/com/takai/bigmodel/service/IBigModelService.java
  17. 644 2
      takai-bigmodel/src/main/java/com/takai/bigmodel/service/impl/BigModelServiceImpl.java
  18. 13 1
      takai-bigmodel/src/main/resources/mapper/bm/BmApplicationMapper.xml
  19. 4 0
      takai-bigmodel/src/main/resources/mapper/bm/BmDocumentMapper.xml
  20. 4 0
      takai-bigmodel/src/main/resources/mapper/bm/BmKnowledgeMapper.xml
  21. 61 0
      takai-bigmodel/src/main/resources/mapper/bm/QuestionMapper.xml
  22. 27 0
      takai-common/src/main/java/com/takai/common/enums/BackgroundColor.java
  23. 28 0
      takai-common/src/main/java/com/takai/common/enums/IconImg.java
  24. 3 1
      takai-framework/src/main/java/com/takai/framework/config/SecurityConfig.java

+ 212 - 8
takai-admin/src/main/java/com/takai/web/controller/bigmodel/BigModelController.java

@@ -1,14 +1,10 @@
 package com.takai.web.controller.bigmodel;
 
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
-import com.takai.bigmodel.domain.dto.AsyncCompletions;
-import com.takai.bigmodel.domain.dto.AsyncResult;
 import com.takai.bigmodel.domain.dto.DialogReqDTO;
 import com.takai.bigmodel.domain.dto.DialogRespDTO;
-import com.takai.bigmodel.domain.entity.AssistantParams;
-import com.takai.bigmodel.domain.entity.BmApplication;
-import com.takai.bigmodel.domain.entity.CompletionsParams;
-import com.takai.bigmodel.domain.entity.SseParams;
+import com.takai.bigmodel.domain.entity.*;
 import com.takai.bigmodel.service.IBigModelService;
 import com.takai.common.annotation.Log;
 import com.takai.common.config.BigModelConfig;
@@ -19,12 +15,13 @@ import com.takai.common.utils.poi.ExcelUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -217,10 +214,217 @@ public class BigModelController extends BaseController {
     @GetMapping("/index")
     public AjaxResult index(){
         // 问答应用总数
-
+        List<BmApplication> applicationList = bigModelService.getApplicationList();
         // 知识库总数
+        List<BmKnowledge> knowledgeList = bigModelService.getKnowledgeList();
+        Map<String, Object> map = new HashMap();
+        map.put("applicationCount", applicationList.size());
+        map.put("knowledgeCount", knowledgeList.size());
+        map.put("application", applicationList);
+        return success(map);
+    }
+
+    /**
+     * 创建知识库
+     * @return
+     */
+    @PostMapping("/createKnowledge")
+    public AjaxResult createKnowledge(@RequestBody KnowledgeParams knowledge){
+        String id = bigModelService.createKnowledge(knowledge);
+        Map<String, Object> map = new HashMap();
+        map.put("data", id);
+        return success(map);
+    }
 
+    /**
+     * 编辑知识库
+     * @return
+     */
+    @PutMapping("/updateKnowledge/{knowledgeId}")
+    public AjaxResult updateKnowledge(@RequestBody KnowledgeParams knowledge, @PathVariable String knowledgeId){
+        bigModelService.updateKnowledge(knowledge, knowledgeId);
         return success();
     }
 
+    /**
+     * 知识库详情
+     * @param knowledgeId
+     * @return
+     */
+    @GetMapping("/detailKnowledge/{knowledgeId}")
+    public AjaxResult detailKonwledge(@PathVariable String knowledgeId){
+        Map<String, Object> map = bigModelService.detailKnowledge(knowledgeId);
+        return success(map);
+    }
+
+    /**
+     * 删除知识库
+     * @return
+     */
+    @DeleteMapping("/delKnowledge/{knowledgeId}")
+    public AjaxResult delKnowledge(@PathVariable String knowledgeId){
+        Map<String, Object> map = bigModelService.delKnowledge(knowledgeId);
+        return success(map);
+    }
+
+    /**
+     * 知识库列表
+     * @return
+     */
+    @GetMapping("/knowledgeList")
+    public AjaxResult getKnowledgeList(){
+        List<BmKnowledge> knowledgeList = bigModelService.getKnowledgeList();
+        return success(knowledgeList);
+    }
+
+    /**
+     * 上传知识文件
+     * @param file
+     * @param documentParams
+     * @param knowledgeId
+     * @return
+     */
+    @PostMapping("/uploadDocument/{knowledgeId}")
+    public AjaxResult uploadDocument(@RequestPart MultipartFile[] file, @RequestPart DocumentParams documentParams, @PathVariable String knowledgeId){
+        JSONObject json = bigModelService.uploadDocument(file, documentParams, knowledgeId);
+        return success(json);
+    }
+
+    /**
+     * 编辑知识
+     * @param documentParams
+     * @param documentId
+     * @return
+     */
+    @PutMapping("/updateDocument/{documentId}")
+    public AjaxResult updateDocument(@RequestBody DocumentParams documentParams, @PathVariable String documentId){
+        JSONObject obj = bigModelService.updateDocument(documentParams, documentId);
+        return success(obj);
+    }
+
+    /**
+     * 知识列表
+     * @return
+     */
+    @GetMapping("/documentList")
+    public AjaxResult documentList(@RequestBody DocumentParams documentParams){
+        JSONArray array = bigModelService.documentList(documentParams);
+        return success(array);
+    }
+
+    /**
+     * 知识详情
+     * @param documentId
+     * @return
+     */
+    @GetMapping("/documentDetail/{documentId}")
+    public AjaxResult documentDetail(@PathVariable String documentId){
+        Map<String, Object> map = bigModelService.documentDetail(documentId);
+        return success(map);
+    }
+
+    /**
+     * 删除知识
+     * @param documentId
+     * @return
+     */
+    @DeleteMapping("/delDocument/{documentId}")
+    public AjaxResult delDocument(@PathVariable String documentId){
+        Map<String, Object> map = bigModelService.delDocument(documentId);
+        return success(map);
+    }
+
+    /**
+     * 上传url构建知识
+     * 用于创建个人知识 web页面
+     * 调用方式:(同步调用返回上传结果; 向量化结果需要调查询接口)
+     * @param object
+     * @return
+     */
+    @PostMapping()
+    public AjaxResult uploadUrl(@RequestBody DocumentObject object){
+        bigModelService.uploadUrl(object);
+        return success();
+    }
+
+    /**
+     * 重新向量化
+     * @param params
+     * @param documentId
+     * @return
+     */
+    @PostMapping("/document/embedding/{documentId}")
+    public AjaxResult documentEmbedding(@RequestBody DocumentParams params, @PathVariable String documentId){
+        JSONObject jsonObject = bigModelService.documentEmbedding(params, documentId);
+        return success(jsonObject);
+    }
+
+    /**
+     * 获取文件解析到的图片列表
+     * @param documentId
+     * @return
+     */
+    @PostMapping("/document/slice/imageList/{documentId}")
+    public AjaxResult documentSliceImageList(@PathVariable String documentId){
+        Map<String, Object> map = bigModelService.documentSliceImageList(documentId);
+        return success(map);
+    }
+
+    /**
+     * 创建应用
+     * @param applicationParams
+     * @return
+     */
+    @PostMapping("/createApplication")
+    public AjaxResult createApplication(@RequestBody ApplicationParams applicationParams){
+        JSONObject jsonObject = bigModelService.createApplication(applicationParams);
+        return success(jsonObject);
+    }
+
+    /**
+     * 更新应用
+     * @param applicationParams
+     * @param appId
+     * @return
+     */
+    @PutMapping("/updateApplication/{appId}")
+    public AjaxResult updateApplication(@RequestBody ApplicationParams applicationParams, @PathVariable String appId){
+        JSONObject jsonObject = bigModelService.updateApplication(applicationParams, appId);
+        return success(jsonObject);
+    }
+
+    /**
+     * 应用列表
+     * @param page
+     * @param size
+     * @return
+     */
+    @GetMapping("/getApplicationList/{page}/{size}")
+    public AjaxResult getApplicationList(@PathVariable Integer page, @PathVariable Integer size){
+        JSONObject jsonObject = bigModelService.getApplicationList(page, size);
+        return success(jsonObject);
+    }
+
+    /**
+     * 应用详情
+     * @param appId
+     * @return
+     */
+    @GetMapping("/selectApplication/{appId}")
+    public AjaxResult selectApplication(@PathVariable String appId){
+        JSONObject jsonObject = bigModelService.selectApplication(appId);
+        return success(jsonObject);
+    }
+
+    /**
+     * 删除应用
+     * @param appId
+     * @return
+     */
+    @DeleteMapping("/delApplication/{appId}")
+    public AjaxResult delApplication(@PathVariable String appId){
+        JSONObject jsonObject = bigModelService.delApplication(appId);
+        return success(jsonObject);
+    }
+
 }

+ 2 - 0
takai-admin/src/main/resources/application.yml

@@ -156,4 +156,6 @@ bigmodel:
   asyncResult: https://open.bigmodel.cn/api/paas/v4/async-result/{id}
   #智能体会话
   assistant: https://open.bigmodel.cn/api/paas/v4/assistant
+  #上传用于模型微调、知识库、Batch、文件抽取等功能所使用的文件。
+  uploadFile: https://open.bigmodel.cn/api/paas/v4/files
 

+ 136 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/ApplicationParams.java

@@ -0,0 +1,136 @@
+package com.takai.bigmodel.domain.entity;
+
+import java.util.List;
+
+public class ApplicationParams {
+
+    private String name;
+
+    private String desc;
+
+    private String prompt;
+
+    private String top_p;
+
+    private String temperature;
+
+    private List<String> knowledge_ids;
+
+    private String model;
+
+    private String icon_color;
+
+    private String icon_type;
+
+    private KnowledgeInfo knowledge_info;
+
+    private String param_desc;
+
+    private Integer max_token;
+
+    private List<QuestionInfo> questionList;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+    }
+
+    public String getPrompt() {
+        return prompt;
+    }
+
+    public void setPrompt(String prompt) {
+        this.prompt = prompt;
+    }
+
+    public String getTop_p() {
+        return top_p;
+    }
+
+    public void setTop_p(String top_p) {
+        this.top_p = top_p;
+    }
+
+    public String getTemperature() {
+        return temperature;
+    }
+
+    public void setTemperature(String temperature) {
+        this.temperature = temperature;
+    }
+
+    public List<String> getKnowledge_ids() {
+        return knowledge_ids;
+    }
+
+    public void setKnowledge_ids(List<String> knowledge_ids) {
+        this.knowledge_ids = knowledge_ids;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getIcon_color() {
+        return icon_color;
+    }
+
+    public void setIcon_color(String icon_color) {
+        this.icon_color = icon_color;
+    }
+
+    public String getIcon_type() {
+        return icon_type;
+    }
+
+    public void setIcon_type(String icon_type) {
+        this.icon_type = icon_type;
+    }
+
+    public KnowledgeInfo getKnowledge_info() {
+        return knowledge_info;
+    }
+
+    public void setKnowledge_info(KnowledgeInfo knowledge_info) {
+        this.knowledge_info = knowledge_info;
+    }
+
+    public String getParam_desc() {
+        return param_desc;
+    }
+
+    public void setParam_desc(String param_desc) {
+        this.param_desc = param_desc;
+    }
+
+    public Integer getMax_token() {
+        return max_token;
+    }
+
+    public void setMax_token(Integer max_token) {
+        this.max_token = max_token;
+    }
+
+    public List<QuestionInfo> getQuestionList() {
+        return questionList;
+    }
+
+    public void setQuestionList(List<QuestionInfo> questionList) {
+        this.questionList = questionList;
+    }
+}

+ 24 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/BmApplication.java

@@ -49,6 +49,12 @@ public class BmApplication extends BaseEntity
     /** icon_type */
     private String iconType;
 
+    /** param_desc */
+    private String paramDesc;
+
+    /** max_token */
+    private Integer maxToken;
+
     public String getAppId() {
         return appId;
     }
@@ -137,6 +143,22 @@ public class BmApplication extends BaseEntity
         this.iconType = iconType;
     }
 
+    public String getParamDesc() {
+        return paramDesc;
+    }
+
+    public void setParamDesc(String paramDesc) {
+        this.paramDesc = paramDesc;
+    }
+
+    public Integer getMaxToken() {
+        return maxToken;
+    }
+
+    public void setMaxToken(Integer maxToken) {
+        this.maxToken = maxToken;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -151,6 +173,8 @@ public class BmApplication extends BaseEntity
             .append("model", getModel())
             .append("iconColor", getIconColor())
             .append("iconType", getIconType())
+            .append("paramDesc", getParamDesc())
+            .append("maxToken", getMaxToken())
             .append("createBy", getCreateBy())
             .append("createTime", getCreateTime())
             .append("updateBy", getUpdateBy())

+ 26 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/DocumentObject.java

@@ -0,0 +1,26 @@
+package com.takai.bigmodel.domain.entity;
+
+import java.util.List;
+
+public class DocumentObject {
+
+    private List<DocumentParams> upload_detail;
+
+    private String knowledge_id;
+
+    public List<DocumentParams> getUpload_detail() {
+        return upload_detail;
+    }
+
+    public void setUpload_detail(List<DocumentParams> upload_detail) {
+        this.upload_detail = upload_detail;
+    }
+
+    public String getKnowledge_id() {
+        return knowledge_id;
+    }
+
+    public void setKnowledge_id(String knowledge_id) {
+        this.knowledge_id = knowledge_id;
+    }
+}

+ 129 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/DocumentParams.java

@@ -0,0 +1,129 @@
+package com.takai.bigmodel.domain.entity;
+
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.util.List;
+
+public class DocumentParams {
+
+    private MultipartFile[] files;
+
+    private int knowledge_type;
+
+    private List<String> custom_separator;
+
+    private int sentence_size;
+
+    private Boolean parse_image;
+
+    private String callback_url;
+
+    private Object callback_header;
+
+    private String word_num_limit;
+
+    private String req_id;
+
+    private String knowledge_id;
+
+    private int page;
+
+    private int size;
+
+    public MultipartFile[] getFiles() {
+        return files;
+    }
+
+    public void setFiles(MultipartFile[] files) {
+        this.files = files;
+    }
+
+    public int getKnowledge_type() {
+        return knowledge_type;
+    }
+
+    public void setKnowledge_type(int knowledge_type) {
+        this.knowledge_type = knowledge_type;
+    }
+
+    public List<String> getCustom_separator() {
+        return custom_separator;
+    }
+
+    public void setCustom_separator(List<String> custom_separator) {
+        this.custom_separator = custom_separator;
+    }
+
+    public int getSentence_size() {
+        return sentence_size;
+    }
+
+    public void setSentence_size(int sentence_size) {
+        this.sentence_size = sentence_size;
+    }
+
+    public Boolean isParse_image() {
+        return parse_image;
+    }
+
+    public void setParse_image(Boolean parse_image) {
+        this.parse_image = parse_image;
+    }
+
+    public String getCallback_url() {
+        return callback_url;
+    }
+
+    public void setCallback_url(String callback_url) {
+        this.callback_url = callback_url;
+    }
+
+    public Object getCallback_header() {
+        return callback_header;
+    }
+
+    public void setCallback_header(Object callback_header) {
+        this.callback_header = callback_header;
+    }
+
+    public String getWord_num_limit() {
+        return word_num_limit;
+    }
+
+    public void setWord_num_limit(String word_num_limit) {
+        this.word_num_limit = word_num_limit;
+    }
+
+    public String getReq_id() {
+        return req_id;
+    }
+
+    public void setReq_id(String req_id) {
+        this.req_id = req_id;
+    }
+
+    public String getKnowledge_id() {
+        return knowledge_id;
+    }
+
+    public void setKnowledge_id(String knowledge_id) {
+        this.knowledge_id = knowledge_id;
+    }
+
+    public int getPage() {
+        return page;
+    }
+
+    public void setPage(int page) {
+        this.page = page;
+    }
+
+    public int getSize() {
+        return size;
+    }
+
+    public void setSize(int size) {
+        this.size = size;
+    }
+}

+ 24 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/IndexType.java

@@ -0,0 +1,24 @@
+package com.takai.bigmodel.domain.entity;
+
+public class IndexType {
+
+    private String knowledge_id;
+
+    private Integer index_type_id;
+
+    public String getKnowledge_id() {
+        return knowledge_id;
+    }
+
+    public void setKnowledge_id(String knowledge_id) {
+        this.knowledge_id = knowledge_id;
+    }
+
+    public Integer getIndex_type_id() {
+        return index_type_id;
+    }
+
+    public void setIndex_type_id(Integer index_type_id) {
+        this.index_type_id = index_type_id;
+    }
+}

+ 106 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/KnowledgeInfo.java

@@ -0,0 +1,106 @@
+package com.takai.bigmodel.domain.entity;
+
+import java.util.List;
+
+public class KnowledgeInfo {
+
+    private String slice_config_type;
+
+    private String recall_method;
+
+    private Integer rerank_status;
+
+    private Integer slice_count;
+
+    private String rerank_model_name;
+
+    private Integer embedding_recall_ratio;
+
+    private Boolean show_recall_result;
+
+    private List rerank_index_type_list;
+
+    private List<IndexType> recall_index_type_list;
+
+    private String recall_slice_splicing_method;
+
+    public String getSlice_config_type() {
+        return slice_config_type;
+    }
+
+    public void setSlice_config_type(String slice_config_type) {
+        this.slice_config_type = slice_config_type;
+    }
+
+    public String getRecall_method() {
+        return recall_method;
+    }
+
+    public void setRecall_method(String recall_method) {
+        this.recall_method = recall_method;
+    }
+
+    public Integer getRerank_status() {
+        return rerank_status;
+    }
+
+    public void setRerank_status(Integer rerank_status) {
+        this.rerank_status = rerank_status;
+    }
+
+    public Integer getSlice_count() {
+        return slice_count;
+    }
+
+    public void setSlice_count(Integer slice_count) {
+        this.slice_count = slice_count;
+    }
+
+    public String getRerank_model_name() {
+        return rerank_model_name;
+    }
+
+    public void setRerank_model_name(String rerank_model_name) {
+        this.rerank_model_name = rerank_model_name;
+    }
+
+    public Integer getEmbedding_recall_ratio() {
+        return embedding_recall_ratio;
+    }
+
+    public void setEmbedding_recall_ratio(Integer embedding_recall_ratio) {
+        this.embedding_recall_ratio = embedding_recall_ratio;
+    }
+
+    public Boolean getShow_recall_result() {
+        return show_recall_result;
+    }
+
+    public void setShow_recall_result(Boolean show_recall_result) {
+        this.show_recall_result = show_recall_result;
+    }
+
+    public List getRerank_index_type_list() {
+        return rerank_index_type_list;
+    }
+
+    public void setRerank_index_type_list(List rerank_index_type_list) {
+        this.rerank_index_type_list = rerank_index_type_list;
+    }
+
+    public List<IndexType> getRecall_index_type_list() {
+        return recall_index_type_list;
+    }
+
+    public void setRecall_index_type_list(List<IndexType> recall_index_type_list) {
+        this.recall_index_type_list = recall_index_type_list;
+    }
+
+    public String getRecall_slice_splicing_method() {
+        return recall_slice_splicing_method;
+    }
+
+    public void setRecall_slice_splicing_method(String recall_slice_splicing_method) {
+        this.recall_slice_splicing_method = recall_slice_splicing_method;
+    }
+}

+ 64 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/KnowledgeParams.java

@@ -0,0 +1,64 @@
+package com.takai.bigmodel.domain.entity;
+
+import com.takai.common.enums.BackgroundColor;
+import com.takai.common.enums.IconImg;
+import com.takai.common.utils.StringUtils;
+import lombok.Data;
+
+public class KnowledgeParams {
+
+    /** 知识库绑定的向量化模型 */
+    private Integer embeddingId;
+
+    /** 知识库名称 */
+    private String name;
+
+    /** 知识库描述 */
+    private String description;
+
+    /** 背景颜色 */
+    private String background;
+
+    /** 知识库图标 */
+    private String icon = IconImg.QUESTION.getValue();
+
+    public Integer getEmbeddingId() {
+        return embeddingId;
+    }
+
+    public void setEmbeddingId(Integer embeddingId) {
+        this.embeddingId = embeddingId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getBackground() {
+        return background;
+    }
+
+    public void setBackground(String background) {
+        this.background = background;
+    }
+
+    public String getIcon() {
+        return icon;
+    }
+
+    public void setIcon(String icon) {
+        this.icon = icon;
+    }
+}

+ 17 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/Question.java

@@ -0,0 +1,17 @@
+package com.takai.bigmodel.domain.entity;
+
+import com.takai.common.core.domain.BaseEntity;
+import lombok.Builder;
+
+@Builder
+public class Question extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    private String id;
+
+    private String appId;
+
+    private String question;
+
+}

+ 44 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/domain/entity/QuestionInfo.java

@@ -0,0 +1,44 @@
+package com.takai.bigmodel.domain.entity;
+
+public class QuestionInfo {
+
+    private String id;
+
+    private String appId;
+
+    private String question;
+
+    private String delFlag;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getQuestion() {
+        return question;
+    }
+
+    public void setQuestion(String question) {
+        this.question = question;
+    }
+
+    public String getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(String delFlag) {
+        this.delFlag = delFlag;
+    }
+}

+ 2 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/BmApplicationMapper.java

@@ -45,6 +45,8 @@ public interface BmApplicationMapper
      */
     public int updateApplication(BmApplication mData);
 
+    int delApplication(String appId);
+
 
 
 }

+ 2 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/BmDocumentMapper.java

@@ -44,4 +44,6 @@ public interface BmDocumentMapper
      */
     public int updateDocument(BmDocument mData);
 
+    int delDocument(String documentId);
+
 }

+ 2 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/BmKnowledgeMapper.java

@@ -44,4 +44,6 @@ public interface BmKnowledgeMapper
      */
     public int updateKnowledge(BmKnowledge mData);
 
+    int delKnowledge(String knowledgeId);
+
 }

+ 22 - 0
takai-bigmodel/src/main/java/com/takai/bigmodel/mapper/QuestionMapper.java

@@ -0,0 +1,22 @@
+package com.takai.bigmodel.mapper;
+
+import com.takai.bigmodel.domain.entity.Question;
+
+import java.util.List;
+
+public interface QuestionMapper {
+
+    List<Question> getQuestionList(String appId);
+
+    int insertQuestion(Question vo);
+
+    int updateQuestion(Question vo);
+
+    int delQuestion(String id);
+
+    Question selectQuestionById(String id);
+
+    int delQuestionByAppId(String appId);
+
+
+}

+ 37 - 2
takai-bigmodel/src/main/java/com/takai/bigmodel/service/IBigModelService.java

@@ -1,11 +1,11 @@
 package com.takai.bigmodel.service;
 
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
-import com.takai.bigmodel.domain.dto.AsyncCompletions;
-import com.takai.bigmodel.domain.dto.AsyncResult;
 import com.takai.bigmodel.domain.dto.DialogReqDTO;
 import com.takai.bigmodel.domain.dto.DialogRespDTO;
 import com.takai.bigmodel.domain.entity.*;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 
 import java.util.List;
@@ -83,4 +83,39 @@ public interface IBigModelService
     void updateDialog(DialogReqDTO dialogReqDTO);
 
     List<DialogRespDTO> exportExcel(String id);
+
+    String createKnowledge(KnowledgeParams knowledge);
+
+    void updateKnowledge(KnowledgeParams knowledge, String knowledgeId);
+
+    Map<String, Object> detailKnowledge(String knowledgeId);
+
+    Map<String, Object> delKnowledge(String knowledgeId);
+
+    JSONObject uploadDocument(MultipartFile[] file, DocumentParams documentParams, String knowledgeId);
+
+    JSONObject updateDocument(DocumentParams documentParams, String documentId);
+
+    JSONArray documentList(DocumentParams documentParams);
+
+    JSONObject documentDetail(String documentId);
+
+    JSONObject delDocument(String documentId);
+
+    void uploadUrl(DocumentObject object);
+
+    JSONObject documentEmbedding(DocumentParams params, String documentId);
+
+    Map<String, Object> documentSliceImageList(String documentId);
+
+    JSONObject createApplication(ApplicationParams params);
+
+    JSONObject updateApplication(ApplicationParams params, String appId);
+
+    JSONObject getApplicationList(Integer page, Integer size);
+
+    JSONObject selectApplication(String appId);
+
+    JSONObject delApplication(String appId);
+
 }

+ 644 - 2
takai-bigmodel/src/main/java/com/takai/bigmodel/service/impl/BigModelServiceImpl.java

@@ -9,19 +9,24 @@ import com.takai.bigmodel.mapper.*;
 import com.takai.bigmodel.service.IBigModelService;
 import com.takai.common.config.BigModelConfig;
 import com.takai.common.core.redis.RedisCache;
+import com.takai.common.enums.BackgroundColor;
+import com.takai.common.enums.IconImg;
 import com.takai.common.utils.uuid.IdUtils;
 import lombok.extern.slf4j.Slf4j;
 import okhttp3.*;
 import okhttp3.sse.EventSource;
 import okhttp3.sse.EventSourceListener;
 import okhttp3.sse.EventSources;
+import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 
 import javax.validation.constraints.NotNull;
+import java.io.File;
 import java.io.IOException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -63,6 +68,9 @@ public class BigModelServiceImpl implements IBigModelService
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    private QuestionMapper questionMapper;
+
 
     @Override
     public List<BmMediaReplacement> selectMediaList(BmMediaReplacement mData) {
@@ -429,6 +437,8 @@ public class BigModelServiceImpl implements IBigModelService
                                 .model(json.getString("model"))
                                 .iconColor(json.getString("icon_color"))
                                 .iconType(json.getString("icon_type"))
+                                .paramDesc(json.getString("param_desc"))
+                                .maxToken(json.getInteger("max_token"))
                                 .build();
                         applicationList.add(bmApplication);
                     }
@@ -716,7 +726,7 @@ public class BigModelServiceImpl implements IBigModelService
                 }
             }
         } catch (IOException e) {
-            throw new RuntimeException(e);
+            log.info("获取切片信息失败", e);
         }
         return null;
     }
@@ -788,7 +798,7 @@ public class BigModelServiceImpl implements IBigModelService
                 }
             }
         } catch (IOException e) {
-            throw new RuntimeException(e);
+            log.info("异步提示词获取失败", e);
         }
         return resultList;
     }
@@ -945,6 +955,598 @@ public class BigModelServiceImpl implements IBigModelService
         return dialogMapper.selectDialogExport(id);
     }
 
+    @Override
+    public String createKnowledge(KnowledgeParams knowledge) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getKnowledge();
+        JSONObject json = new JSONObject();
+        json.put("embedding_id",knowledge.getEmbeddingId());
+        json.put("name", knowledge.getName());
+        json.put("description", knowledge.getDescription());
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , json.toJSONString());
+
+        Request request = buildPostRequest(url,requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        String id = null;
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String body = response.body().string();
+                boolean status = isJsonObject(body);
+                if(status){
+                    JSONObject jsonObj = JSON.parseObject(body);
+                    if(jsonObj != null){
+                        JSONObject dataObj = jsonObj.getJSONObject("data");
+                        if(dataObj != null){
+                            id = String.valueOf(dataObj.get("id"));
+                            BmKnowledge bm = BmKnowledge.builder()
+                                            .knowledgeId(id).build();
+                            BmKnowledge vo = bmKnowledgeMapper.selectTargetKnowledge(bm);
+                            if(vo == null){
+                                //保存知识库信息
+                                BmKnowledge bmKnowledge = BmKnowledge.builder()
+                                        .knowledgeId(id)
+                                        .embeddingId(knowledge.getEmbeddingId())
+                                        .name(knowledge.getName())
+                                        .description(knowledge.getDescription())
+                                        .icon(knowledge.getIcon() == null ? IconImg.QUESTION.getValue() : knowledge.getIcon())
+                                        .background(knowledge.getBackground() == null ? BackgroundColor.BLUE.getValue() : knowledge.getBackground()).build();
+                                bmKnowledgeMapper.insertKnowledge(bmKnowledge);
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return id;
+    }
+
+    @Override
+    public void updateKnowledge(KnowledgeParams knowledge, String knowledgeId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getKnowledge() + "/" + knowledgeId;
+        JSONObject object = JSONObject.from(knowledge);
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , object.toJSONString());
+
+        Request request = buildPutRequest(url,requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                BmKnowledge bm = BmKnowledge.builder()
+                        .knowledgeId(knowledgeId).build();
+                BmKnowledge vo = bmKnowledgeMapper.selectTargetKnowledge(bm);
+                if(vo != null){
+                    //保存知识库信息
+                    BmKnowledge bmKnowledge = BmKnowledge.builder()
+                            .knowledgeId(knowledgeId)
+                            .embeddingId(knowledge.getEmbeddingId())
+                            .name(knowledge.getName())
+                            .description(knowledge.getDescription())
+                            .icon(knowledge.getIcon())
+                            .background(knowledge.getBackground())
+                            .build();
+                    bmKnowledgeMapper.updateKnowledge(bmKnowledge);
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public Map<String, Object> detailKnowledge(String knowledgeId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getKnowledge() + "/" + knowledgeId;
+        Map<String, Object> map = new HashMap();
+        Request request = buildGetRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String data = response.body().string();
+                boolean status = isJsonObject(data);
+                if(status){
+                    JSONObject obj = JSON.parseObject(data);
+                    if(obj != null){
+
+                        JSONObject dataObject = obj.getJSONObject("data");
+                        String code = String.valueOf(obj.get("code"));
+                        String message = String.valueOf(obj.get("message"));
+                        String timestamp = String.valueOf(obj.get("timestamp"));
+                        map.put("detail", dataObject);
+                        map.put("code", code);
+                        map.put("message", message);
+                        map.put("timestamp", timestamp);
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        };
+        return map;
+    }
+
+    @Override
+    public Map<String, Object> delKnowledge(String knowledgeId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getKnowledge() + "/" + knowledgeId;
+        Map<String, Object> map = new HashMap();
+        Request request = buildDeleteRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String data = response.body().string();
+                boolean status = isJsonObject(data);
+                if(status){
+                    JSONObject obj = JSON.parseObject(data);
+                    if(obj != null){
+                        String code = String.valueOf(obj.get("code"));
+                        String message = String.valueOf(obj.get("message"));
+                        String timestamp = String.valueOf(obj.get("timestamp"));
+                        map.put("code", code);
+                        map.put("message", message);
+                        map.put("timestamp", timestamp);
+                        if("200".equals(code)){
+                            //删除
+                            bmKnowledgeMapper.delKnowledge(knowledgeId);
+                        }
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        };
+        return map;
+    }
+
+    @Override
+    public JSONObject uploadDocument(MultipartFile[] file, DocumentParams documentParams, String knowledgeId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument() + "/upload_document/" + knowledgeId;
+
+        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
+        //MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
+        for (int i = 0; i < file.length; i++) {
+
+            File f = new File(file[i].getOriginalFilename());
+            try {
+                FileUtils.writeByteArrayToFile(f, file[i].getBytes());
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+            String type = getMimeType(f);
+            // 为每个文件创建RequestBody
+            RequestBody requestBody = FormBody.create(MediaType.parse(type) , f);
+            // 添加文件到MultipartBodyBuilder
+            builder.addFormDataPart("files", f.getName(), requestBody);
+        }
+        MultipartBody body = builder.build();
+        OkHttpClient client = buildOkHttpClient();
+        Request request = buildPostFileRequest(url, body);
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String result = response.body().string();
+                if(isJsonObject(result)){
+                    JSONObject jsonObj = JSON.parseObject(result);
+                    if(jsonObj != null){
+                        JSONObject dataObj = jsonObj.getJSONObject("data");
+                        if(dataObj != null){
+                            JSONArray array = dataObj.getJSONArray("successInfos");
+                            if(array != null){
+                                for(int i=0; i<array.size(); i++){
+                                    JSONObject obj = array.getJSONObject(i);
+                                    String documentId = String.valueOf(obj.get("documentId"));
+                                    String fileName = String.valueOf(obj.get("fileName"));
+                                    String urlStr = String.valueOf(obj.get("url"));
+
+                                    BmDocument bm = BmDocument.builder()
+                                            .documentId(documentId).build();
+                                    BmDocument vo = bmDocumentMapper.selectTargetDocument(bm);
+                                    if(vo == null){
+                                        //保存知识信息
+                                        BmDocument res = BmDocument.builder()
+                                                .documentId(documentId)
+                                                .knowledgeId(knowledgeId)
+                                                .name(fileName)
+                                                .url(urlStr)
+                                                .customSeparator(String.format("[\"%s\"", "\\n")+ "]")
+                                                .sentenceSize("300")
+                                                .build();
+                                        bmDocumentMapper.insertDocument(res);
+                                    }
+
+                                }
+                            }
+                        }
+                        JSONObject json = new JSONObject();
+                        json.put("code", jsonObj.getJSONObject("code"));
+                        json.put("message", jsonObj.getJSONObject("message"));
+                        json.put("timestamp", jsonObj.getJSONObject("timestamp"));
+                        return json;
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject updateDocument(DocumentParams documentParams, String documentId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument() + "/" + documentId;
+        JSONObject object = JSONObject.from(documentParams);
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , object.toJSONString());
+
+        Request request = buildPutRequest(url, requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                JSONObject obj = JSON.parseObject(response.body().string());
+                String code = String.valueOf(obj.get("code"));
+                if("200".equals(code)){
+                    //更新知识数据
+                    BmDocument vo = BmDocument.builder().documentId(documentId).build();
+                    BmDocument result = bmDocumentMapper.selectTargetDocument(vo);
+                    if(result != null){
+                        BmDocument bm = BmDocument.builder()
+                                .documentId(documentId)
+                                .sentenceSize(String.valueOf(documentParams.getSentence_size()))
+                                .knowledgeType(documentParams.getKnowledge_type())
+                                .wordNum(documentParams.getWord_num_limit() == null ? null : Integer.valueOf(documentParams.getWord_num_limit()))
+                                .build();
+                        bmDocumentMapper.updateDocument(bm);
+                    }
+                }
+                return obj;
+            }
+        } catch (IOException e) {
+            log.info("更新知识失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONArray documentList(DocumentParams documentParams) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument();
+        if(com.takai.common.utils.StringUtils.isNotEmpty(documentParams.getKnowledge_id())){
+            url += "?knowledge_id=" + documentParams.getKnowledge_id();
+        }
+        if (documentParams.getPage() >= 1) {
+            url += "&page=" + documentParams.getPage();
+        }
+        if (documentParams.getSize() >= 10) {
+            url += "&size=" + documentParams.getSize();
+        }
+        Request request = buildGetRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                JSONObject obj = JSON.parseObject(response.body().string());
+                JSONObject dataObj = obj.getJSONObject("data");
+                JSONArray array = dataObj.getJSONArray("list");
+                return array;
+            }
+        } catch (IOException e) {
+            log.info("获取知识列表失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject documentDetail(String documentId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument() + "/" + documentId;
+
+        Request request = buildGetRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                JSONObject obj = JSON.parseObject(response.body().string());
+                JSONObject dataObje = obj.getJSONObject("data");
+                return dataObje;
+            }
+        } catch (IOException e) {
+            log.info("获取知识详情失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject delDocument(String documentId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument() + "/" + documentId;
+
+        Request request = buildDeleteRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                JSONObject obj = JSON.parseObject(response.body().string());
+                Map<String, Object> map = new HashMap();
+                if("200".equals(String.valueOf(obj.get("code")))){
+                    bmDocumentMapper.delDocument(documentId);
+                }
+                return obj;
+            }
+        } catch (IOException e) {
+            log.info("删除知识失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public void uploadUrl(DocumentObject object) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument() + "/upload_url";
+        JSONObject jsonObject = JSONObject.from(object);
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , jsonObject.toJSONString());
+        Request request = buildPostRequest(url, requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                JSONObject obj = JSON.parseObject(response.body().string());
+                JSONObject dataObj = obj.getJSONObject("data");
+                JSONArray array = dataObj.getJSONArray("successInfos");
+                if(array != null){
+                    for(int i=0; i<array.size(); i++){
+                        JSONObject aObj = array.getJSONObject(i);
+                        String documentId = String.valueOf(aObj.get("documentId"));
+                        String urlStr = String.valueOf(aObj.get("url"));
+
+                        BmDocument bm = BmDocument.builder()
+                                .documentId(documentId).build();
+                        BmDocument vo = bmDocumentMapper.selectTargetDocument(bm);
+                        if(vo != null) {
+                            //保存知识信息
+                            BmDocument res = BmDocument.builder()
+                                    .documentId(documentId)
+                                    .url(urlStr)
+                                    .build();
+                            bmDocumentMapper.updateDocument(res);
+                        }
+                    }
+                }
+            }
+        } catch (IOException e) {
+            log.info("上传url构建知识失败", e);
+        }
+    }
+
+    @Override
+    public JSONObject documentEmbedding(DocumentParams params, String documentId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument() + "/embedding/" + documentId;
+        JSONObject jsonObject = JSONObject.from(params);
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , jsonObject.toJSONString());
+        Request request = buildPostRequest(url, requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                JSONObject object = JSON.parseObject(response.body().string());
+                if(object != null){
+                    return object;
+                }
+            }
+        } catch (IOException e) {
+            log.info("重新向量化失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public Map<String, Object> documentSliceImageList(String documentId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getDocument() + "/slice/image_list/" + documentId;
+        JSONObject jsonObject = new JSONObject();
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , jsonObject.toJSONString());
+        Request request = buildPostRequest(url, requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                JSONObject object = JSON.parseObject(response.body().string());
+                JSONObject dataObj = object.getJSONObject("data");
+                JSONArray array = dataObj.getJSONArray("images");
+                if(array != null){
+                    BmMediaReplacement condition = BmMediaReplacement.builder().documentId(documentId).build();
+                    List<BmMediaReplacement>  dbList = bmMediaReplacementMapper.selectMediaList(condition);
+                    for(int i=0; i<array.size(); i++){
+                        JSONObject aObj = array.getJSONObject(i);
+                        Optional<BmMediaReplacement> optObj = dbList.stream().filter(a -> a.getOriginText().equals(String.valueOf(aObj.get("text")))).findFirst();
+                        if (!optObj.isPresent()) {
+                            BmMediaReplacement image = BmMediaReplacement
+                                            .builder()
+                                            .documentId(documentId)
+                                            .originText(String.valueOf(aObj.get("text")))
+                                            .mediaUrl(String.valueOf(aObj.get("cos_url")))
+                                            .build();
+                            bmMediaReplacementMapper.insertMedia(image);
+                        } else if(!optObj.get().getOriginText().equals(String.valueOf(aObj.get("text")))
+                                || !optObj.get().getMediaUrl().equals(String.valueOf(aObj.get("cos_url")))) {
+                            BmMediaReplacement updateObj = BmMediaReplacement
+                                            .builder()
+                                            .documentId(documentId)
+                                            .originText(String.valueOf(aObj.get("text")))
+                                            .mediaUrl(String.valueOf(aObj.get("cos_url")))
+                                            .build();
+                            bmMediaReplacementMapper.updateMedia(updateObj);
+                        }
+                    }
+                }
+                Map<String, Object> map = new HashMap();
+                map.put("code", object.get("code"));
+                map.put("message", object.get("message"));
+                map.put("timestamp", object.get("timestamp"));
+                return map;
+            }
+        } catch (IOException e) {
+            log.info("获取文件解析到的图片列表失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject createApplication(ApplicationParams params) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getApplication();
+        JSONObject jsonObject = JSONObject.from(params);
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , jsonObject.toJSONString());
+        Request request = buildPostRequest(url, requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String result = response.body().string();
+                JSONObject object = JSON.parseObject(result);
+                if(object != null){
+                    String code = String.valueOf(object.get("code"));
+                    String appId = String.valueOf(object.get("data"));
+                    if("200".equals(code)){
+                        //调用列表接口将应用数据写入数据库
+                        getValidAppList();
+                        //预设问题写入数据库
+                        List<QuestionInfo> list = params.getQuestionList();
+                        if(!list.isEmpty() && list.size() > 0){
+                            for(QuestionInfo vo : list){
+                                String uuid = IdUtils.simpleUUID();
+                                Question question = Question.builder().id(uuid).question(vo.getQuestion()).appId(appId).build();
+                                questionMapper.insertQuestion(question);
+                            }
+                        }
+                    }
+                }
+                return object;
+            }
+        } catch (IOException e) {
+            log.info("应用创建失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject updateApplication(ApplicationParams params, String appId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getApplication() + "/" + appId;
+        JSONObject json = JSONObject.from(params);
+        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8") , json.toJSONString());
+        Request request = buildPutRequest(url, requestBody);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String result = response.body().string();
+                JSONObject object = JSON.parseObject(result);
+                if(object != null){
+                    String code = String.valueOf(object.get("code"));
+                    if("200".equals(code)){
+                        //调用列表接口将应用数据写入数据库
+                        getValidAppList();
+                        //预设问题写入数据库
+                        List<QuestionInfo> list = params.getQuestionList();
+                        if(!list.isEmpty() && list.size() > 0){
+                            for(QuestionInfo vo : list){
+                                //删除预设问题
+                                if(com.takai.common.utils.StringUtils.isNotEmpty(vo.getDelFlag()) && "1".equals(vo.getDelFlag())){
+                                    questionMapper.delQuestion(vo.getId());
+                                }else{
+                                    if(com.takai.common.utils.StringUtils.isNotEmpty(vo.getId())){
+                                        // 更新预设问题
+                                        Question question = Question.builder().question(vo.getQuestion()).build();
+                                        questionMapper.updateQuestion(question);
+                                    }else{
+                                        // 新增预设问题
+                                        String uuid = IdUtils.simpleUUID();
+                                        Question question = Question.builder().id(uuid).question(vo.getQuestion()).appId(appId).build();
+                                        questionMapper.insertQuestion(question);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                return object;
+            }
+        } catch (IOException e) {
+            log.info("更新应用失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject getApplicationList(Integer page, Integer size) {
+        String url = null;
+        if(page != null && size != null){
+            url = bigModelConfig.getBaseurl() + bigModelConfig.getApplication() + "?page=" + page +"&size=" + size;
+        }else{
+            url = bigModelConfig.getBaseurl() + bigModelConfig.getApplication();
+        }
+        Request request = buildGetRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String result = response.body().string();
+                JSONObject object = JSON.parseObject(result);
+                if(object != null){
+                    return object.getJSONObject("data");
+                }
+            }
+        } catch (IOException e) {
+            log.info("获取应用列表失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject selectApplication(String appId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getApplication() + "/" + appId;
+        Request request = buildGetRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String result = response.body().string();
+                JSONObject object = JSON.parseObject(result);
+                if(object != null){
+                    String code = String.valueOf(object.get("code"));
+                    if("200".equals(code)){
+                        JSONObject obj = new JSONObject();
+                        List<Question> list = questionMapper.getQuestionList(appId);
+                        obj.put("detail", object.getJSONObject("data"));
+                        obj.put("questionlist", list);
+                        return obj;
+                    }
+                }
+            }
+        } catch (IOException e) {
+            log.info("获取应用详情失败", e);
+        }
+        return null;
+    }
+
+    @Override
+    public JSONObject delApplication(String appId) {
+        String url = bigModelConfig.getBaseurl() + bigModelConfig.getApplication() + "/" + appId;
+        Request request = buildDeleteRequest(url);
+        OkHttpClient client = buildOkHttpClient();
+        try {
+            Response response = client.newCall(request).execute();
+            if(response.isSuccessful()){
+                String result = response.body().string();
+                JSONObject object = JSON.parseObject(result);
+                String code = String.valueOf(object.get("code"));
+                if("200".equals(code)){
+                    //getValidAppList();
+                    bmApplicationMapper.delApplication(appId);
+                    questionMapper.delQuestionByAppId(appId);
+                }
+                return object;
+            }
+        } catch (IOException e) {
+            log.info("获取应用详情失败", e);
+        }
+        return null;
+    }
+
     private Request buildGetRequest(String url) {
         return new Request.Builder()
                 .addHeader("accept", "*/*")
@@ -961,6 +1563,14 @@ public class BigModelServiceImpl implements IBigModelService
                 .url(url).post(requestBody).build();
     }
 
+    private Request buildPostFileRequest(String url,RequestBody requestBody) {
+        return new Request.Builder()
+                .addHeader("accept", "*/*")
+                .addHeader("Authorization", bigModelConfig.getBigModelApiKey())
+                .addHeader("Content-Type", "multipart/form-data")
+                .url(url).post(requestBody).build();
+    }
+
     private OkHttpClient buildOkHttpClient() {
         return new OkHttpClient.Builder()
                 .connectTimeout(10, TimeUnit.SECONDS)
@@ -969,6 +1579,21 @@ public class BigModelServiceImpl implements IBigModelService
                 .build();
     }
 
+    private Request buildPutRequest(String url, RequestBody requestBody){
+        return new Request.Builder()
+                .addHeader("accept", "*/*")
+                .addHeader("Authorization", bigModelConfig.getBigModelApiKey())
+                .addHeader("Content-Type", "application/json")
+                .url(url).put(requestBody).build();
+    }
+
+    private Request buildDeleteRequest(String url){
+        return new Request.Builder()
+                .addHeader("accept", "*/*")
+                .addHeader("Authorization", bigModelConfig.getBigModelApiKey())
+                .url(url).delete().build();
+    }
+
     private boolean isJsonObject(String data){
         try {
             JSON.parseObject(data);
@@ -989,4 +1614,21 @@ public class BigModelServiceImpl implements IBigModelService
         return l;
     }
 
+    private String getMimeType(File file){
+        if(!file.exists()){
+            return null;
+        }
+
+        String fileName = file.getName().toLowerCase();
+        if(fileName.endsWith(".pdf")){
+            return "application/json";
+        }else if (fileName.endsWith(".doc") || fileName.endsWith(".docx")) {
+            return "application/msword";
+        }else if (fileName.endsWith(".txt")) {
+            return "text/plain";
+        }else {
+            return null;
+        }
+    }
+
 }

+ 13 - 1
takai-bigmodel/src/main/resources/mapper/bm/BmApplicationMapper.xml

@@ -16,6 +16,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="model"   column="model"   />
 		<result property="iconColor"   column="icon_color"   />
 		<result property="iconType"   column="icon_type"   />
+		<result property="paramDesc"   column="param_desc"   />
+		<result property="maxToken"   column="max_token"   />
 		<result property="remark"   column="remark"   />
 		<result property="createBy"   column="create_by"   />
 		<result property="createTime" column="create_time" />
@@ -24,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</resultMap>
 	
 	<sql id="selectSql">
-        select appId, name, description, prompt, top_p, temperature, knowledge_ids, slice_count,model,icon_color,icon_type,create_by, create_time, remark
+        select appId, name, description, prompt, top_p, temperature, knowledge_ids, slice_count,model,icon_color,icon_type, param_desc, max_token, create_by, create_time, remark
 		from bm_application
     </sql>
 
@@ -56,6 +58,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="model != null and model != ''">model,</if>
 			<if test="iconColor != null and iconColor != ''">icon_color,</if>
 			<if test="iconType != null and iconType != ''">icon_type,</if>
+			<if test="paramDesc != null and paramDesc != ''">param_desc,</if>
+			<if test="maxToken != null and maxToken != ''">max_token,</if>
  			<if test="remark != null and remark != ''">remark,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
  			create_time
@@ -71,6 +75,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="model != null and model != ''">#{model},</if>
 			<if test="iconColor != null and iconColor != ''">#{iconColor},</if>
 			<if test="iconType != null and iconType != ''">#{iconType},</if>
+			<if test="paramDesc != null and paramDesc != ''">#{paramDesc},</if>
+			<if test="maxToken != null and maxToken != ''">#{maxToken},</if>
  			<if test="remark != null and remark != ''">#{remark},</if>
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
  			sysdate()
@@ -91,10 +97,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="iconColor != null and iconColor != ''">icon_color = #{iconColor},</if>
 			<if test="iconType != null and iconType != ''">icon_type = #{iconType},</if>
 			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
+			<if test="paramDesc != null and paramDesc != ''">param_desc = #{paramDesc},</if>
+			<if test="maxToken != null and maxToken != ''">max_token = #{maxToken},</if>
 			<if test="remark != null">remark = #{remark},</if>
 			update_time = sysdate()
 		</set>
 		where appId = #{appId}
 	</update>
+
+	<delete id="delApplication" parameterType="String">
+		delete from bm_application where appId = #{appId}
+	</delete>
 	
 </mapper> 

+ 4 - 0
takai-bigmodel/src/main/resources/mapper/bm/BmDocumentMapper.xml

@@ -95,5 +95,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		</set>
 		where document_id = #{documentId}
 	</update>
+
+	<delete id="delDocument" parameterType="String">
+		delete from bm_document where document_id = #{documentId}
+	</delete>
 	
 </mapper> 

+ 4 - 0
takai-bigmodel/src/main/resources/mapper/bm/BmKnowledgeMapper.xml

@@ -89,5 +89,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		</set>
 		where knowledge_id = #{knowledgeId}
 	</update>
+
+	<delete id="delKnowledge" parameterType="String">
+		delete from bm_knowledge where knowledge_id = #{knowledgeId}
+	</delete>
 	
 </mapper> 

+ 61 - 0
takai-bigmodel/src/main/resources/mapper/bm/QuestionMapper.xml

@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.takai.bigmodel.mapper.QuestionMapper">
+	
+	<resultMap type="Question" id="QuestionResult">
+		<id property="id"   column="id"   />
+		<result property="app_id"  column="app_id"  />
+		<result property="question"  column="question"  />
+		<result property="create_time" column="create_time" />
+	</resultMap>
+
+	<select id="getQuestionList"  resultMap="QuestionResult">
+		select
+			q.id,
+			q.app_id as appId,
+			q.question,
+			q.create_time
+		from question q
+		where q.app_id = #{appId}
+		ORDER BY q.create_time desc
+	</select>
+ 	
+ 	<insert id="insertQuestion" parameterType="Question">
+ 		insert into question(
+		    id,
+			<if test="appId != null">app_id,</if>
+			<if test="question != null">question,</if>
+ 			create_time
+ 		)values(
+			#{id},
+			<if test="appId != null">#{appId},</if>
+			<if test="question != null">#{question},</if>
+ 			sysdate()
+ 		)
+	</insert>
+
+	<select id="selectQuestionById"  resultMap="QuestionResult">
+		select
+			q.id,
+			q.app_id as appId,
+			q.question,
+			q.create_time
+		from question q
+		where q.id = #{id}
+	</select>
+
+	<delete id="delQuestion" parameterType="String">
+		delete from question where id = #{id}
+	</delete>
+
+	<update id="updateQuestion" parameterType="Question">
+		update question set question = #{question} where id = #{id}
+	</update>
+
+	<delete id="delQuestionByAppId" parameterType="String">
+		delete from question where app_id = #{appId}
+	</delete>
+
+</mapper>

+ 27 - 0
takai-common/src/main/java/com/takai/common/enums/BackgroundColor.java

@@ -0,0 +1,27 @@
+package com.takai.common.enums;
+
+public enum BackgroundColor {
+
+    BLUE("blue"),
+
+    RED("red"),
+
+
+    ORANGE("orange"),
+
+
+    PURPLE("purple"),
+
+    SKY("sky")
+    ;
+
+    private final String value;
+
+    BackgroundColor(String value){
+        this.value = value;
+    }
+
+    public String getValue(){
+        return value;
+    }
+}

+ 28 - 0
takai-common/src/main/java/com/takai/common/enums/IconImg.java

@@ -0,0 +1,28 @@
+package com.takai.common.enums;
+
+public enum IconImg {
+
+    QUESTION("question"),
+
+    BOOK("book"),
+
+    SEAL("seal"),
+
+    WRENCH("wrench"),
+
+    TAG("tag"),
+
+    HORN("horn"),
+
+    HOUSE("house");
+
+    private final String value;
+
+    IconImg(String value){
+        this.value = value;
+    }
+
+    public String getValue(){
+        return value;
+    }
+}

+ 3 - 1
takai-framework/src/main/java/com/takai/framework/config/SecurityConfig.java

@@ -113,7 +113,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
                 .antMatchers("/login", "/register", "/captchaImage","/getToken","/**/sse-invoke","/**/application/list","/bigmodel/api/dialog/**",
                         "/**/completions", "/**/slice_info/**", "/**/async_result/**", "/**/assistant/**", "/getInfo",
-                        "/checkToken", "/**/presets/**").permitAll()
+                        "/checkToken", "/**/presets/**", "/**/index/**", "/**/createApplaction/**", "/**/createKnowledge/**",
+                        "/**/updateKnowledge/**", "/**/detailKnowledge/**", "/**/delKnowledge/**", "/**/knowledgeList/**",
+                        "/**//bigmodel/api/**").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()