|
@@ -49,6 +49,8 @@ func LLMKnowledgeBaseSearchDocs(search LLMKnowledgeSearch) (resp bus_response.Se
|
|
|
|
|
|
// AIGCBaseOnPromote aigc 生成内容
|
|
|
func AIGCBaseOnPromote(aigc AIGC) (resp bus_response.AIGCEtaResponse, err error) {
|
|
|
+ param := make(map[string]interface{})
|
|
|
+ param["LLM"] =aigc.LLMModel
|
|
|
mapping, queryErr := rag.GetArticleKbMapping(aigc.ArticleId)
|
|
|
if queryErr != nil && !errors.Is(queryErr, gorm.ErrRecordNotFound) {
|
|
|
utils.FileLog.Error("获取文章知识库信息失败,err: %v", queryErr)
|
|
@@ -85,7 +87,7 @@ func AIGCBaseOnPromote(aigc AIGC) (resp bus_response.AIGCEtaResponse, err error)
|
|
|
utils.FileLog.Error("打开文件失败,err:", err)
|
|
|
return
|
|
|
}
|
|
|
- uploadResp, httpErr := llmService.UploadFileToTemplate([]*os.File{file}, nil)
|
|
|
+ uploadResp, httpErr := llmService.UploadFileToTemplate([]*os.File{file}, param)
|
|
|
if httpErr != nil {
|
|
|
utils.FileLog.Error("上传文件失败,err:", err.Error())
|
|
|
err = fmt.Errorf("上传文件失败,err:%v", httpErr)
|
|
@@ -111,9 +113,9 @@ func AIGCBaseOnPromote(aigc AIGC) (resp bus_response.AIGCEtaResponse, err error)
|
|
|
kbId = mapping.KbId
|
|
|
}
|
|
|
//知识库对话
|
|
|
- response, httpErr := llmService.FileChat(aigc.Promote, kbId, nil)
|
|
|
+ response, httpErr := llmService.FileChat(aigc.Promote, kbId, aigc.LLMModel, nil)
|
|
|
if httpErr != nil {
|
|
|
- utils.FileLog.Error("内容生成失败,err:", err.Error())
|
|
|
+ utils.FileLog.Error("内容生成失败,err:", httpErr.Error())
|
|
|
err = fmt.Errorf("内容生成失败,err:%v", httpErr)
|
|
|
return
|
|
|
}
|
|
@@ -129,7 +131,41 @@ func AIGCBaseOnPromote(aigc AIGC) (resp bus_response.AIGCEtaResponse, err error)
|
|
|
return
|
|
|
}
|
|
|
if gcResp.Code == 404 {
|
|
|
- response, httpErr = llmService.FileChat(aigc.Promote, kbId, nil)
|
|
|
+ param["PrevId"] = kbId
|
|
|
+ article, fileErr := rag.GetArticleById(aigc.ArticleId)
|
|
|
+ if fileErr != nil {
|
|
|
+ // 找不到就处理失败
|
|
|
+ utils.FileLog.Error("公众号文章不存在")
|
|
|
+ err = fmt.Errorf("公众号文章不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if article.TextContent == "" {
|
|
|
+ utils.FileLog.Error("暂不支持纯文本以外的内容生成")
|
|
|
+ err = fmt.Errorf("暂不支持纯文本以外的内容生成")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 文章加入到知识库
|
|
|
+ path, fileErr := localService.CreateArticleFile(article)
|
|
|
+ if fileErr != nil {
|
|
|
+ utils.FileLog.Error("创建文章文件失败,err: %v", fileErr)
|
|
|
+ err = fmt.Errorf("创建文章文件失败,err: %v", fileErr)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ _ = os.Remove(path)
|
|
|
+ }()
|
|
|
+ file, err = os.Open(path)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("打开文件失败,err:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ _, httpErr = llmService.UploadFileToTemplate([]*os.File{file}, param)
|
|
|
+ if httpErr != nil {
|
|
|
+ utils.FileLog.Error("上传文件失败,err:", err.Error())
|
|
|
+ err = fmt.Errorf("上传文件失败,err:%v", httpErr)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ response, httpErr = llmService.FileChat(aigc.Promote, kbId, aigc.LLMModel, nil)
|
|
|
if httpErr != nil {
|
|
|
utils.FileLog.Error("内容生成失败,err:%v", httpErr.Error())
|
|
|
err = fmt.Errorf("内容生成失败,err:%v", httpErr)
|
|
@@ -164,6 +200,7 @@ type LLMKnowledgeSearch struct {
|
|
|
type AIGC struct {
|
|
|
Promote string
|
|
|
ArticleId int
|
|
|
+ LLMModel string
|
|
|
}
|
|
|
|
|
|
func dealFileChatResp(response eta_llm_http.BaseResponse) (httpResponse bus_response.FileChatBaseResponse, err error) {
|