作者 yangfu

feat-1.0 chat doc

正在显示 68 个修改的文件 包含 3986 行增加289 行删除

要显示太多修改。

为保证性能只显示 68 of 68+ 个文件。

@@ -8,7 +8,7 @@ Timeout: 30000 @@ -8,7 +8,7 @@ Timeout: 30000
8 LogRequest: true # 记录详细请求日志 8 LogRequest: true # 记录详细请求日志
9 9
10 Log: 10 Log:
11 - Mode: file 11 + #Mode: file
12 Encoding: plain 12 Encoding: plain
13 Level: debug # info 13 Level: debug # info
14 MaxSize: 1 # 2MB 14 MaxSize: 1 # 2MB
@@ -25,5 +25,5 @@ Redis: @@ -25,5 +25,5 @@ Redis:
25 Type: node 25 Type: node
26 Pass: 26 Pass:
27 DB: 27 DB:
28 - DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform port=31543 sslmode=disable TimeZone=Asia/Shanghai 28 + DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform_preonline port=31543 sslmode=disable TimeZone=Asia/Shanghai
29 29
  1 +package chat
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDataSessionGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatSessionGetRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := chat.NewChatDataSessionGetLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDataSessionGet(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package chat
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDataSessionSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDataSessionSearchRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := chat.NewChatDataSessionSearchLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDataSessionSearch(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package chat
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  5 + "net/http"
  6 +
  7 + "github.com/zeromicro/go-zero/rest/httpx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  11 +)
  12 +
  13 +func ChatMySparkSessionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.ChatSessionSearchRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := chat.NewChatSessionSearchLogic(r.Context(), svcCtx)
  22 + req.Module = domain.ModuleSparkChat
  23 + resp, err := l.ChatSessionSearch(&req)
  24 + if err != nil {
  25 + httpx.ErrorCtx(r.Context(), w, err)
  26 + } else {
  27 + httpx.OkJsonCtx(r.Context(), w, resp)
  28 + }
  29 + }
  30 +}
  1 +package chat
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatSessionAddFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatSessionAddFilesRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := chat.NewChatSessionAddFilesLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatSessionAddFiles(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package chat
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatSessionRemoveFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatSessionAddFilesRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := chat.NewChatSessionRemoveFilesLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatSessionRemoveFiles(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package chat
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatSessionRenameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatSessionRenameRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := chat.NewChatSessionRenameLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatSessionRename(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
1 package chat 1 package chat
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
4 "net/http" 5 "net/http"
5 6
6 "github.com/zeromicro/go-zero/rest/httpx" 7 "github.com/zeromicro/go-zero/rest/httpx"
@@ -18,6 +19,8 @@ func ChatSessionSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -18,6 +19,8 @@ func ChatSessionSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
18 } 19 }
19 20
20 l := chat.NewChatSessionSaveLogic(r.Context(), svcCtx) 21 l := chat.NewChatSessionSaveLogic(r.Context(), svcCtx)
  22 + req.ChatSession.Module = domain.ModuleOpenaiChat
  23 + req.ChatSession.Type = domain.TypeChat
21 resp, err := l.ChatSessionSave(&req) 24 resp, err := l.ChatSessionSave(&req)
22 if err != nil { 25 if err != nil {
23 httpx.ErrorCtx(r.Context(), w, err) 26 httpx.ErrorCtx(r.Context(), w, err)
1 package chat 1 package chat
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
4 "net/http" 5 "net/http"
5 6
6 "github.com/zeromicro/go-zero/rest/httpx" 7 "github.com/zeromicro/go-zero/rest/httpx"
@@ -18,6 +19,7 @@ func ChatSessionSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -18,6 +19,7 @@ func ChatSessionSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
18 } 19 }
19 20
20 l := chat.NewChatSessionSearchLogic(r.Context(), svcCtx) 21 l := chat.NewChatSessionSearchLogic(r.Context(), svcCtx)
  22 + req.Module = domain.ModuleOpenaiChat
21 resp, err := l.ChatSessionSearch(&req) 23 resp, err := l.ChatSessionSearch(&req)
22 if err != nil { 24 if err != nil {
23 httpx.ErrorCtx(r.Context(), w, err) 25 httpx.ErrorCtx(r.Context(), w, err)
  1 +package chat
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  6 + "net/http"
  7 +
  8 + "github.com/zeromicro/go-zero/rest/httpx"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  12 +)
  13 +
  14 +func ChatSparkSessionSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  15 + return func(w http.ResponseWriter, r *http.Request) {
  16 + var req types.ChatSessionSaveRequest
  17 + if err := httpx.Parse(r, &req); err != nil {
  18 + httpx.ErrorCtx(r.Context(), w, err)
  19 + return
  20 + }
  21 +
  22 + l := chat.NewChatSessionSaveLogic(r.Context(), svcCtx)
  23 + req.ChatSession.Module = domain.ModuleSparkChat
  24 + if req.ChatSession.DatasetId > 0 {
  25 + req.ChatSession.Type = domain.TypeSparkDatasetChat
  26 + } else if len(req.ChatSession.DocumentIds) > 0 {
  27 + req.ChatSession.Type = domain.TypeSparkDocumentsChat
  28 + } else {
  29 + httpx.ErrorCtx(r.Context(), w, xerr.NewErrMsgErr("知识库、文档至少选一个", nil))
  30 + return
  31 + }
  32 + resp, err := l.ChatSessionSave(&req)
  33 + if err != nil {
  34 + httpx.ErrorCtx(r.Context(), w, err)
  35 + } else {
  36 + httpx.OkJsonCtx(r.Context(), w, resp)
  37 + }
  38 + }
  39 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetAddFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetAddFilesRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetAddFilesLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetAddFiles(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetDeleteRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetDeleteLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetDelete(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetGetRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetGetLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetGet(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetRemvoeFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetAddFilesRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetRemvoeFilesLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetRemvoeFiles(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetRenameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetRenameRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetRenameLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetRename(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetSaveRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetSaveLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetSave(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetSearchRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetSearchLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetSearch(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDatasetUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDatasetUpdateRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := dataset.NewChatDatasetUpdateLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDatasetUpdate(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package document
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDocumentBatchSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDocumentBatchSaveRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := document.NewChatDocumentBatchSaveLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDocumentBatchSave(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package document
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDocumentDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDocumentDeleteRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := document.NewChatDocumentDeleteLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDocumentDelete(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package document
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDocumentGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDocumentGetRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := document.NewChatDocumentGetLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDocumentGet(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package document
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDocumentRenameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDocumentRenameRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := document.NewChatDocumentRenameLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDocumentRename(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package document
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDocumentSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDocumentSaveRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := document.NewChatDocumentSaveLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDocumentSave(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package document
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/zeromicro/go-zero/rest/httpx"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +)
  11 +
  12 +func ChatDocumentSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.ChatDocumentSearchRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := document.NewChatDocumentSearchLogic(r.Context(), svcCtx)
  21 + resp, err := l.ChatDocumentSearch(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
5 "net/http" 5 "net/http"
6 6
7 chat "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/handler/chat" 7 chat "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/handler/chat"
  8 + dataset "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/handler/dataset"
  9 + document "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/handler/document"
8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" 10 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
9 11
10 "github.com/zeromicro/go-zero/rest" 12 "github.com/zeromicro/go-zero/rest"
@@ -37,6 +39,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -37,6 +39,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
37 }, 39 },
38 { 40 {
39 Method: http.MethodPost, 41 Method: http.MethodPost,
  42 + Path: "/chat/session/rename",
  43 + Handler: chat.ChatSessionRenameHandler(serverCtx),
  44 + },
  45 + {
  46 + Method: http.MethodPost,
40 Path: "/chat/session/search", 47 Path: "/chat/session/search",
41 Handler: chat.ChatSessionSearchHandler(serverCtx), 48 Handler: chat.ChatSessionSearchHandler(serverCtx),
42 }, 49 },
@@ -52,6 +59,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -52,6 +59,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
52 }, 59 },
53 { 60 {
54 Method: http.MethodPost, 61 Method: http.MethodPost,
  62 + Path: "/chat/session/add_files",
  63 + Handler: chat.ChatSessionAddFilesHandler(serverCtx),
  64 + },
  65 + {
  66 + Method: http.MethodPost,
  67 + Path: "/chat/session/remove_files",
  68 + Handler: chat.ChatSessionRemoveFilesHandler(serverCtx),
  69 + },
  70 + {
  71 + Method: http.MethodPost,
  72 + Path: "/chat/session/my_spark_sessions",
  73 + Handler: chat.ChatMySparkSessionsHandler(serverCtx),
  74 + },
  75 + {
  76 + Method: http.MethodPost,
  77 + Path: "/chat/spark_session",
  78 + Handler: chat.ChatSparkSessionSaveHandler(serverCtx),
  79 + },
  80 + {
  81 + Method: http.MethodPost,
55 Path: "/chat/session/records", 82 Path: "/chat/session/records",
56 Handler: chat.ChatSessionRecordsHandler(serverCtx), 83 Handler: chat.ChatSessionRecordsHandler(serverCtx),
57 }, 84 },
@@ -65,4 +92,114 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -65,4 +92,114 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
65 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), 92 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
66 rest.WithPrefix("/v1"), 93 rest.WithPrefix("/v1"),
67 ) 94 )
  95 +
  96 + server.AddRoutes(
  97 + rest.WithMiddlewares(
  98 + []rest.Middleware{serverCtx.LogRequest},
  99 + []rest.Route{
  100 + {
  101 + Method: http.MethodPost,
  102 + Path: "/chat/data/session/search",
  103 + Handler: chat.ChatDataSessionSearchHandler(serverCtx),
  104 + },
  105 + {
  106 + Method: http.MethodGet,
  107 + Path: "/chat/data/session/:id",
  108 + Handler: chat.ChatDataSessionGetHandler(serverCtx),
  109 + },
  110 + }...,
  111 + ),
  112 + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
  113 + rest.WithPrefix("/v1"),
  114 + )
  115 +
  116 + server.AddRoutes(
  117 + rest.WithMiddlewares(
  118 + []rest.Middleware{serverCtx.LogRequest},
  119 + []rest.Route{
  120 + {
  121 + Method: http.MethodGet,
  122 + Path: "/chat/document/:id",
  123 + Handler: document.ChatDocumentGetHandler(serverCtx),
  124 + },
  125 + {
  126 + Method: http.MethodPost,
  127 + Path: "/chat/document",
  128 + Handler: document.ChatDocumentSaveHandler(serverCtx),
  129 + },
  130 + {
  131 + Method: http.MethodPost,
  132 + Path: "/chat/document/batch_save",
  133 + Handler: document.ChatDocumentBatchSaveHandler(serverCtx),
  134 + },
  135 + {
  136 + Method: http.MethodDelete,
  137 + Path: "/chat/document/:id",
  138 + Handler: document.ChatDocumentDeleteHandler(serverCtx),
  139 + },
  140 + {
  141 + Method: http.MethodPost,
  142 + Path: "/chat/document/rename",
  143 + Handler: document.ChatDocumentRenameHandler(serverCtx),
  144 + },
  145 + {
  146 + Method: http.MethodPost,
  147 + Path: "/chat/document/search",
  148 + Handler: document.ChatDocumentSearchHandler(serverCtx),
  149 + },
  150 + }...,
  151 + ),
  152 + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
  153 + rest.WithPrefix("/v1"),
  154 + )
  155 +
  156 + server.AddRoutes(
  157 + rest.WithMiddlewares(
  158 + []rest.Middleware{serverCtx.LogRequest},
  159 + []rest.Route{
  160 + {
  161 + Method: http.MethodGet,
  162 + Path: "/chat/dataset/:id",
  163 + Handler: dataset.ChatDatasetGetHandler(serverCtx),
  164 + },
  165 + {
  166 + Method: http.MethodPost,
  167 + Path: "/chat/dataset",
  168 + Handler: dataset.ChatDatasetSaveHandler(serverCtx),
  169 + },
  170 + {
  171 + Method: http.MethodDelete,
  172 + Path: "/chat/dataset/:id",
  173 + Handler: dataset.ChatDatasetDeleteHandler(serverCtx),
  174 + },
  175 + {
  176 + Method: http.MethodPut,
  177 + Path: "/chat/dataset/:id",
  178 + Handler: dataset.ChatDatasetUpdateHandler(serverCtx),
  179 + },
  180 + {
  181 + Method: http.MethodPost,
  182 + Path: "/chat/dataset/rename",
  183 + Handler: dataset.ChatDatasetRenameHandler(serverCtx),
  184 + },
  185 + {
  186 + Method: http.MethodPost,
  187 + Path: "/chat/dataset/search",
  188 + Handler: dataset.ChatDatasetSearchHandler(serverCtx),
  189 + },
  190 + {
  191 + Method: http.MethodPost,
  192 + Path: "/chat/dataset/add_files",
  193 + Handler: dataset.ChatDatasetAddFilesHandler(serverCtx),
  194 + },
  195 + {
  196 + Method: http.MethodPost,
  197 + Path: "/chat/dataset/remove_files",
  198 + Handler: dataset.ChatDatasetRemvoeFilesHandler(serverCtx),
  199 + },
  200 + }...,
  201 + ),
  202 + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
  203 + rest.WithPrefix("/v1"),
  204 + )
68 } 205 }
  1 +package chat
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type ChatDataSessionGetLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewChatDataSessionGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDataSessionGetLogic {
  19 + return &ChatDataSessionGetLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *ChatDataSessionGetLogic) ChatDataSessionGet(req *types.ChatSessionGetRequest) (resp *types.ChatSessionGetResponse, err error) {
  27 + logic := NewChatSessionGetLogic(l.ctx, l.svcCtx)
  28 + return logic.ChatSessionGet(req)
  29 +}
  1 +package chat
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type ChatDataSessionSearchLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewChatDataSessionSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDataSessionSearchLogic {
  23 + return &ChatDataSessionSearchLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *ChatDataSessionSearchLogic) ChatDataSessionSearch(req *types.ChatDataSessionSearchRequest) (resp *types.ChatDataSessionSearchResponse, err error) {
  31 + var (
  32 + conn = l.svcCtx.DefaultDBConn()
  33 + sessions []*domain.ChatSession
  34 + total int64
  35 + token = contextdata.GetUserTokenFromCtx(l.ctx)
  36 + )
  37 +
  38 + queryOptions := domain.NewQueryOptions().
  39 + //WithKV("module", domain.ModuleOpenaiChat).
  40 + WithKV("companyId", token.CompanyId).
  41 + LikeKV("title", req.Title).
  42 + WithKV("beginTime", req.BeginTime).WithKV("endTime", req.EndTime)
  43 + if len(req.UserName) > 0 {
  44 + users, _ := l.svcCtx.SystemOpen.UserByName(l.ctx, conn, token.CompanyId, req.UserName)
  45 + userIds := make([]int64, 0)
  46 + for _, user := range users {
  47 + userIds = append(userIds, user.Id)
  48 + }
  49 + if len(userIds) > 0 {
  50 + queryOptions.WithKV("inUserIds", userIds)
  51 + }
  52 + }
  53 + if req.Page != 0 && req.Size != 0 {
  54 + queryOptions.WithOffsetLimit(req.Page, req.Size)
  55 + }
  56 +
  57 + total, sessions, err = l.svcCtx.ChatSessionRepository.Find(l.ctx, conn, queryOptions)
  58 + if err != nil {
  59 + return nil, xerr.NewErr(err)
  60 + }
  61 +
  62 + // 查询对话数量
  63 + sessionIdList := domain.Values(sessions, func(item *domain.ChatSession) int64 {
  64 + return item.Id
  65 + })
  66 + countSessionRecords, _ := l.svcCtx.ChatSessionRecordRepository.CountRecordsBySessions(l.ctx, conn, token.CompanyId, sessionIdList...)
  67 + countSessionRecordMap := lo.SliceToMap(countSessionRecords, func(item *domain.CountRecordsBySessionResult) (int64, *domain.CountRecordsBySessionResult) {
  68 + return item.SessionId, item
  69 + })
  70 + list := make([]types.ChatSessionItem, 0)
  71 + userLazyLoad := tool.NewLazyLoadService(l.svcCtx.SystemOpen.User)
  72 + for i := range sessions {
  73 + typesSession := NewTypesChatSession(sessions[i])
  74 + user, _ := userLazyLoad.Load(l.ctx, conn, sessions[i].UserId)
  75 + typesSession.Author = NewTypesUser(user)
  76 +
  77 + if v, ok := countSessionRecordMap[sessions[i].Id]; ok {
  78 + typesSession.TotalRecords = v.Count
  79 + typesSession.Model = NewTypesModel(v.ModelId)
  80 + }
  81 + // 默认模型星火问答
  82 + if sessions[i].Module == domain.ModuleSparkChat {
  83 + typesSession.Model = NewTypesModel(domain.SparkChatDocModelId)
  84 + }
  85 + list = append(list, typesSession)
  86 + }
  87 + resp = &types.ChatDataSessionSearchResponse{
  88 + List: list,
  89 + Total: total,
  90 + }
  91 + return
  92 +}
@@ -28,6 +28,9 @@ func NewChatModelsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatMo @@ -28,6 +28,9 @@ func NewChatModelsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatMo
28 func (l *ChatModelsLogic) ChatModels(req *types.ChatModelsRequest) (resp *types.ChatModelsResponse, err error) { 28 func (l *ChatModelsLogic) ChatModels(req *types.ChatModelsRequest) (resp *types.ChatModelsResponse, err error) {
29 var models = make([]types.Model, 0) 29 var models = make([]types.Model, 0)
30 lo.ForEach(domain.DefaultChatModels, func(item *domain.ChatModel, index int) { 30 lo.ForEach(domain.DefaultChatModels, func(item *domain.ChatModel, index int) {
  31 + if item.Id == domain.SparkChatDocModelId {
  32 + return
  33 + }
31 models = append(models, types.Model{ 34 models = append(models, types.Model{
32 Id: item.Id, 35 Id: item.Id,
33 Name: item.Name, 36 Name: item.Name,
  1 +package chat
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  9 +
  10 + "github.com/zeromicro/go-zero/core/logx"
  11 +)
  12 +
  13 +type ChatMySparkSessionsLogic struct {
  14 + logx.Logger
  15 + ctx context.Context
  16 + svcCtx *svc.ServiceContext
  17 +}
  18 +
  19 +func NewChatMySparkSessionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatMySparkSessionsLogic {
  20 + return &ChatMySparkSessionsLogic{
  21 + Logger: logx.WithContext(ctx),
  22 + ctx: ctx,
  23 + svcCtx: svcCtx,
  24 + }
  25 +}
  26 +
  27 +func (l *ChatMySparkSessionsLogic) ChatMySparkSessions(req *types.ChatSessionSearchRequest) (resp *types.ChatSessionSearchResponse, err error) {
  28 + logic := NewChatSessionSearchLogic(l.ctx, l.svcCtx)
  29 + req.Module = domain.ModuleSparkChat
  30 + resp, err = logic.ChatSessionSearch(req)
  31 + //resp.List =
  32 + return
  33 +}
  1 +package chat
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  11 +
  12 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  13 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  14 +
  15 + "github.com/zeromicro/go-zero/core/logx"
  16 +)
  17 +
  18 +type ChatSessionAddFilesLogic struct {
  19 + logx.Logger
  20 + ctx context.Context
  21 + svcCtx *svc.ServiceContext
  22 +}
  23 +
  24 +func NewChatSessionAddFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSessionAddFilesLogic {
  25 + return &ChatSessionAddFilesLogic{
  26 + Logger: logx.WithContext(ctx),
  27 + ctx: ctx,
  28 + svcCtx: svcCtx,
  29 + }
  30 +}
  31 +
  32 +func (l *ChatSessionAddFilesLogic) ChatSessionAddFiles(req *types.ChatSessionAddFilesRequest) (resp *types.ChatSessionAddFilesResponse, err error) {
  33 + var (
  34 + conn = l.svcCtx.DefaultDBConn()
  35 + dm *domain.ChatSession
  36 + token = contextdata.GetUserTokenFromCtx(l.ctx)
  37 + )
  38 + if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  39 + return nil, xerr.NewErrMsgErr("不存在", err)
  40 + }
  41 + if dm.UserId != token.UserId {
  42 + return nil, xerr.NewErrMsgErr("无权限", err)
  43 + }
  44 + // 赋值
  45 + if dm.Module != domain.ModuleSparkChat {
  46 + return nil, xerr.NewErrMsgErr("类型有误,星火文档类型才可以添加文档", err)
  47 + }
  48 +
  49 + // 更新
  50 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  51 + // 知识库移除
  52 + if dm.Type == domain.TypeSparkDatasetChat {
  53 + if err = core.DatasetAddFiles(l.ctx, l.svcCtx, conn, dm.Metadata.DatasetId, req.DocumentIds); err != nil {
  54 + return err
  55 + }
  56 + return nil
  57 + }
  58 + // 普通多文档移除
  59 + dm.Metadata.DocumentIds = lo.Union(dm.Metadata.DocumentIds, req.DocumentIds)
  60 + dm, err = l.svcCtx.ChatSessionRepository.UpdateWithVersion(l.ctx, conn, dm)
  61 + return err
  62 + }, true); err != nil {
  63 + return nil, xerr.NewErrMsg("更新失败")
  64 + }
  65 + resp = &types.ChatSessionAddFilesResponse{}
  66 + return
  67 +}
@@ -2,10 +2,13 @@ package chat @@ -2,10 +2,13 @@ package chat
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "github.com/samber/lo"
  6 + "github.com/zeromicro/go-zero/core/fx"
5 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
6 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open" 8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open"
7 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai" 9 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai"
8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata" 10 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
9 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction" 12 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
10 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" 13 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
11 "net/http" 14 "net/http"
@@ -38,7 +41,6 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr @@ -38,7 +41,6 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
38 token = contextdata.GetUserTokenFromCtx(l.ctx) 41 token = contextdata.GetUserTokenFromCtx(l.ctx)
39 session *domain.ChatSession 42 session *domain.ChatSession
40 user open.User 43 user open.User
41 - model *domain.ChatModel  
42 ok bool 44 ok bool
43 beginUnix = time.Now().UnixMilli() 45 beginUnix = time.Now().UnixMilli()
44 ) 46 )
@@ -51,8 +53,8 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr @@ -51,8 +53,8 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
51 if user.Id != session.UserId { 53 if user.Id != session.UserId {
52 return nil, xerr.NewErrMsgErr("无权限", err) 54 return nil, xerr.NewErrMsgErr("无权限", err)
53 } 55 }
54 - if model, ok = domain.DefaultChatModels.Match(req.ModelId); !ok {  
55 - return nil, xerr.NewErrMsgErr("模型不存在", err) 56 + if session.Module == domain.ModuleSparkChat {
  57 + req.ModelId = domain.SparkChatDocModelId
56 } 58 }
57 dm = &domain.ChatSessionRecord{ 59 dm = &domain.ChatSessionRecord{
58 CompanyId: token.CompanyId, 60 CompanyId: token.CompanyId,
@@ -69,15 +71,16 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr @@ -69,15 +71,16 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
69 var answer string 71 var answer string
70 var channel = make(chan string, 5) 72 var channel = make(chan string, 5)
71 // 异步访问AI接口 73 // 异步访问AI接口
72 - go func() {  
73 - // 异步访问AI接口  
74 - answer, err = Conversation(model, req.Text, channel)  
75 - }()  
76 - for {  
77 - if _, ok = <-channel; !ok {  
78 - break 74 + fx.Parallel(func() {
  75 + answer, err = Conversation(l.ctx, l.svcCtx, session, req.ModelId, req.Text, channel)
  76 + }, func() {
  77 + for {
  78 + if _, ok = <-channel; !ok {
  79 + break
  80 + }
  81 + logx.Info(1)
79 } 82 }
80 - } 83 + })
81 if err != nil { 84 if err != nil {
82 return nil, xerr.NewErrMsgErr("AI模型异常,稍后再试", err) 85 return nil, xerr.NewErrMsgErr("AI模型异常,稍后再试", err)
83 } 86 }
@@ -101,17 +104,63 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr @@ -101,17 +104,63 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
101 return 104 return
102 } 105 }
103 106
104 -func Conversation(m *domain.ChatModel, text string, channel chan string) (answer string, err error) {  
105 - 107 +// Conversation 普通对话
  108 +func Conversation(ctx context.Context, svc *svc.ServiceContext, session *domain.ChatSession, modelId int64, text string, channel chan string) (answer string, err error) {
  109 + var (
  110 + m *domain.ChatModel
  111 + ok bool
  112 + )
  113 + defer close(channel)
  114 + if m, ok = domain.DefaultChatModels.Match(modelId); !ok {
  115 + err = xerr.NewErrMsgErr("模型不存在", err)
  116 + return
  117 + }
  118 + if session.Module == domain.ModuleSparkChat {
  119 + return SparkDocumentConversation(ctx, svc, session, m, text, channel)
  120 + }
106 switch m.Id { 121 switch m.Id {
107 // 星火3.5 122 // 星火3.5
108 case 1, 2, 3: 123 case 1, 2, 3:
109 answer, err = ai.ChatGPT(m.Code, m.Config.AppKey, text, channel) 124 answer, err = ai.ChatGPT(m.Code, m.Config.AppKey, text, channel)
110 case 4: 125 case 4:
111 - answer, err = ai.Spark(m.Config.AppId, m.Config.AppKey, m.Config.AppSecret, text, channel) 126 + answer, err = ai.ChatSpark(m.Config.AppId, m.Config.AppKey, m.Config.AppSecret, text, channel)
112 } 127 }
113 if err != nil { 128 if err != nil {
114 return "", err 129 return "", err
115 } 130 }
116 return 131 return
117 } 132 }
  133 +
  134 +// SparkDocumentConversation 星火文档对话
  135 +func SparkDocumentConversation(ctx context.Context, svcCtx *svc.ServiceContext, session *domain.ChatSession, m *domain.ChatModel, text string, channel chan string) (answer string, err error) {
  136 + var (
  137 + conn = svcCtx.DefaultDBConn()
  138 + )
  139 + // 获取文件ID列表
  140 + fileIds := make([]string, 0)
  141 + lazyDocument := tool.NewLazyLoadService(svcCtx.ChatDocumentRepository.FindOne)
  142 + if session.Type == domain.TypeSparkDatasetChat { // 知识库
  143 + _, documentMapping, _ := svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(ctx, conn, session.Metadata.DatasetId)
  144 + lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
  145 + if document, _ := lazyDocument.Load(ctx, conn, item.DocumentId); document != nil {
  146 + if len(document.Metadata.FileId) == 0 {
  147 + return
  148 + }
  149 + fileIds = append(fileIds, document.Metadata.FileId)
  150 + }
  151 + })
  152 + } else if session.Type == domain.TypeSparkDocumentsChat { // 多文档
  153 + lo.ForEach(session.Metadata.DocumentIds, func(item int64, index int) {
  154 + if document, _ := lazyDocument.Load(ctx, conn, item); document != nil {
  155 + if len(document.Metadata.FileId) == 0 {
  156 + return
  157 + }
  158 + fileIds = append(fileIds, document.Metadata.FileId)
  159 + }
  160 + })
  161 + }
  162 +
  163 + // 对话
  164 + c := m.Config
  165 + return ai.ChatSparkDocument(c.AppId, c.AppKey, c.AppSecret, fileIds, text, channel)
  166 +}
@@ -40,7 +40,6 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon @@ -40,7 +40,6 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon
40 token = contextdata.GetUserTokenFromCtx(l.ctx) 40 token = contextdata.GetUserTokenFromCtx(l.ctx)
41 session *domain.ChatSession 41 session *domain.ChatSession
42 user open.User 42 user open.User
43 - model *domain.ChatModel  
44 ok bool 43 ok bool
45 ) 44 )
46 if session, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.SessionId); err != nil { 45 if session, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.SessionId); err != nil {
@@ -52,12 +51,10 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon @@ -52,12 +51,10 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon
52 if user.Id != session.UserId { 51 if user.Id != session.UserId {
53 return nil, xerr.NewErrMsgErr("无权限", err) 52 return nil, xerr.NewErrMsgErr("无权限", err)
54 } 53 }
55 - if model, ok = domain.DefaultChatModels.Match(req.ModelId); !ok {  
56 - return nil, xerr.NewErrMsgErr("模型不存在", err) 54 + if session.Module == domain.ModuleSparkChat {
  55 + req.ModelId = domain.SparkChatDocModelId
57 } 56 }
58 -  
59 var answer string 57 var answer string
60 -  
61 var upgrader = websocket.Upgrader{ 58 var upgrader = websocket.Upgrader{
62 ReadBufferSize: 1024, 59 ReadBufferSize: 1024,
63 WriteBufferSize: 1024, 60 WriteBufferSize: 1024,
@@ -96,7 +93,7 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon @@ -96,7 +93,7 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon
96 } 93 }
97 fx.Parallel(func() { 94 fx.Parallel(func() {
98 // 异步访问AI接口 95 // 异步访问AI接口
99 - answer, err = Conversation(model, string(text), channel) 96 + answer, err = Conversation(l.ctx, l.svcCtx, session, req.ModelId, string(text), channel)
100 }, func() { 97 }, func() {
101 for { 98 for {
102 var v string 99 var v string
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open" 7 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open"
8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata" 8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
9 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" 10 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
10 11
11 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" 12 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
@@ -31,45 +32,57 @@ func NewChatSessionGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ch @@ -31,45 +32,57 @@ func NewChatSessionGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ch
31 func (l *ChatSessionGetLogic) ChatSessionGet(req *types.ChatSessionGetRequest) (resp *types.ChatSessionGetResponse, err error) { 32 func (l *ChatSessionGetLogic) ChatSessionGet(req *types.ChatSessionGetRequest) (resp *types.ChatSessionGetResponse, err error) {
32 var ( 33 var (
33 conn = l.svcCtx.DefaultDBConn() 34 conn = l.svcCtx.DefaultDBConn()
34 - dm *domain.ChatSession 35 + session *domain.ChatSession
35 records []*domain.ChatSessionRecord 36 records []*domain.ChatSessionRecord
36 token = contextdata.GetUserTokenFromCtx(l.ctx) 37 token = contextdata.GetUserTokenFromCtx(l.ctx)
37 user open.User 38 user open.User
38 ) 39 )
39 // 货号唯一 40 // 货号唯一
40 - if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil { 41 + if session, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
41 return nil, xerr.NewErrMsgErr("不存在", err) 42 return nil, xerr.NewErrMsgErr("不存在", err)
42 } 43 }
43 - if user, err = l.svcCtx.SystemOpen.User(l.ctx, conn, dm.UserId); err != nil { 44 + if user, err = l.svcCtx.SystemOpen.User(l.ctx, conn, session.UserId); err != nil {
44 return nil, xerr.NewErrMsgErr("用户不存在", err) 45 return nil, xerr.NewErrMsgErr("用户不存在", err)
45 } 46 }
46 - if _, records, err = l.svcCtx.ChatSessionRecordRepository.FindByCompanyUser(l.ctx, conn, token.CompanyId, token.UserId, domain.NewQueryOptions().MustWithKV("sessionId", dm.Id)); err != nil { 47 + if _, records, err = l.svcCtx.ChatSessionRecordRepository.FindByCompanyUser(l.ctx, conn, token.CompanyId, token.UserId, domain.NewQueryOptions().MustWithKV("sessionId", session.Id)); err != nil {
47 return nil, xerr.NewErr(err) 48 return nil, xerr.NewErr(err)
48 } 49 }
49 var typesRecords []types.Record 50 var typesRecords []types.Record
50 lo.ForEach(records, func(item *domain.ChatSessionRecord, index int) { 51 lo.ForEach(records, func(item *domain.ChatSessionRecord, index int) {
51 typesRecords = append(typesRecords, NewTypesChatRecord(item, user)) 52 typesRecords = append(typesRecords, NewTypesChatRecord(item, user))
52 }) 53 })
  54 + var documents []types.ChatDocumentItem
  55 + var dataset types.ChatDatasetItem
  56 + if session.Type == domain.TypeSparkDocumentsChat && len(session.Metadata.DocumentIds) > 0 {
  57 + for _, id := range session.Metadata.DocumentIds {
  58 + if item, _ := l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, id); item != nil {
  59 + documents = append(documents, types.NewTypesChatDocument(item))
  60 + }
  61 + }
  62 + } else if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
  63 + _, documentMapping, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, session.Metadata.DatasetId)
  64 + lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne)
  65 + lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
  66 + if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil {
  67 + documents = append(documents, types.NewTypesChatDocument(document))
  68 + }
  69 + })
  70 + if item, _ := l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, session.Metadata.DatasetId); item != nil {
  71 + dataset = types.NewTypesChatDataset(item, lo.ToPtr(len(documents)))
  72 + }
  73 + }
53 74
54 resp = &types.ChatSessionGetResponse{ 75 resp = &types.ChatSessionGetResponse{
55 - ChatSession: NewTypesChatSession(dm), 76 + ChatSession: NewTypesChatSession(session),
56 Records: typesRecords, 77 Records: typesRecords,
  78 + Documents: documents,
  79 + Dataset: &dataset,
57 } 80 }
58 return 81 return
59 } 82 }
60 83
61 func NewTypesChatRecord(item *domain.ChatSessionRecord, user open.User) types.Record { 84 func NewTypesChatRecord(item *domain.ChatSessionRecord, user open.User) types.Record {
62 - model, ok := domain.DefaultChatModels.Match(item.ModelId)  
63 - var typesModel *types.Model  
64 - if !ok {  
65 - typesModel = &types.Model{}  
66 - } else {  
67 - typesModel = &types.Model{  
68 - Name: model.Name,  
69 - Id: model.Id,  
70 - Logo: model.Logo,  
71 - }  
72 - } 85 + var typesModel *types.Model = NewTypesModel(item.ModelId)
73 return types.Record{ 86 return types.Record{
74 Id: item.Id, 87 Id: item.Id,
75 SessionId: item.SessionId, 88 SessionId: item.SessionId,
@@ -84,6 +97,21 @@ func NewTypesChatRecord(item *domain.ChatSessionRecord, user open.User) types.Re @@ -84,6 +97,21 @@ func NewTypesChatRecord(item *domain.ChatSessionRecord, user open.User) types.Re
84 } 97 }
85 } 98 }
86 99
  100 +func NewTypesModel(modelId int64) *types.Model {
  101 + model, ok := domain.DefaultChatModels.Match(modelId)
  102 + var typesModel *types.Model
  103 + if !ok {
  104 + typesModel = &types.Model{}
  105 + } else {
  106 + typesModel = &types.Model{
  107 + Name: model.Name,
  108 + Id: model.Id,
  109 + Logo: model.Logo,
  110 + }
  111 + }
  112 + return typesModel
  113 +}
  114 +
87 func NewTypesUser(user open.User) *types.User { 115 func NewTypesUser(user open.User) *types.User {
88 if user.Id == 0 && user.Name == "" { 116 if user.Id == 0 && user.Name == "" {
89 return nil 117 return nil
  1 +package chat
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  11 +
  12 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  13 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  14 +
  15 + "github.com/zeromicro/go-zero/core/logx"
  16 +)
  17 +
  18 +type ChatSessionRemoveFilesLogic struct {
  19 + logx.Logger
  20 + ctx context.Context
  21 + svcCtx *svc.ServiceContext
  22 +}
  23 +
  24 +func NewChatSessionRemoveFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSessionRemoveFilesLogic {
  25 + return &ChatSessionRemoveFilesLogic{
  26 + Logger: logx.WithContext(ctx),
  27 + ctx: ctx,
  28 + svcCtx: svcCtx,
  29 + }
  30 +}
  31 +
  32 +func (l *ChatSessionRemoveFilesLogic) ChatSessionRemoveFiles(req *types.ChatSessionAddFilesRequest) (resp *types.ChatSessionAddFilesResponse, err error) {
  33 + var (
  34 + conn = l.svcCtx.DefaultDBConn()
  35 + dm *domain.ChatSession
  36 + token = contextdata.GetUserTokenFromCtx(l.ctx)
  37 + )
  38 + if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  39 + return nil, xerr.NewErrMsgErr("不存在", err)
  40 + }
  41 + if dm.UserId != token.UserId {
  42 + return nil, xerr.NewErrMsgErr("无权限", err)
  43 + }
  44 + // 赋值
  45 + if dm.Module != domain.ModuleSparkChat {
  46 + return nil, xerr.NewErrMsgErr("类型有误,星火文档类型才可以添加文档", err)
  47 + }
  48 +
  49 + // 更新
  50 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  51 + // 知识库移除
  52 + if dm.Type == domain.TypeSparkDatasetChat {
  53 + if err = core.DatasetRemoveFiles(l.ctx, l.svcCtx, conn, dm.Metadata.DatasetId, req.DocumentIds); err != nil {
  54 + return err
  55 + }
  56 + return nil
  57 + }
  58 + dm.Metadata.DocumentIds = lo.Without(dm.Metadata.DocumentIds, req.DocumentIds...)
  59 + dm, err = l.svcCtx.ChatSessionRepository.UpdateWithVersion(l.ctx, conn, dm)
  60 + return err
  61 + }, true); err != nil {
  62 + return nil, xerr.NewErrMsg("更新失败")
  63 + }
  64 + resp = &types.ChatSessionAddFilesResponse{}
  65 + return
  66 +}
  1 +package chat
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  9 +
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type ChatSessionRenameLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewChatSessionRenameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSessionRenameLogic {
  23 + return &ChatSessionRenameLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *ChatSessionRenameLogic) ChatSessionRename(req *types.ChatSessionRenameRequest) (resp *types.ChatSessionRenameResponse, err error) {
  31 + var (
  32 + conn = l.svcCtx.DefaultDBConn()
  33 + dm *domain.ChatSession
  34 + token = contextdata.GetUserTokenFromCtx(l.ctx)
  35 + )
  36 + if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  37 + return nil, xerr.NewErrMsgErr("不存在", err)
  38 + }
  39 + if dm.UserId != token.UserId {
  40 + return nil, xerr.NewErrMsgErr("无权限", err)
  41 + }
  42 + // 赋值
  43 + dm.Title = req.Name
  44 +
  45 + // 更新
  46 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  47 + dm, err = l.svcCtx.ChatSessionRepository.UpdateWithVersion(l.ctx, conn, dm)
  48 + return err
  49 + }, true); err != nil {
  50 + return nil, xerr.NewErrMsg("更新失败")
  51 + }
  52 + resp = &types.ChatSessionRenameResponse{}
  53 + return
  54 +}
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata" 6 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
7 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction" 7 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr" 8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  9 + "time"
9 10
10 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" 11 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
11 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" 12 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
@@ -39,7 +40,9 @@ func (l *ChatSessionSaveLogic) ChatSessionSave(req *types.ChatSessionSaveRequest @@ -39,7 +40,9 @@ func (l *ChatSessionSaveLogic) ChatSessionSave(req *types.ChatSessionSaveRequest
39 }, true); err != nil { 40 }, true); err != nil {
40 return nil, xerr.NewErrMsg("保存失败") 41 return nil, xerr.NewErrMsg("保存失败")
41 } 42 }
42 - resp = &types.ChatSessionSaveResponse{} 43 + resp = &types.ChatSessionSaveResponse{
  44 + ChatSession: NewTypesChatSession(dm),
  45 + }
43 return 46 return
44 } 47 }
45 48
@@ -53,14 +56,31 @@ func NewDomainChatSession(token contextdata.UserToken, item types.ChatSessionIte @@ -53,14 +56,31 @@ func NewDomainChatSession(token contextdata.UserToken, item types.ChatSessionIte
53 UserId: token.UserId, 56 UserId: token.UserId,
54 Title: title, 57 Title: title,
55 Abstract: title, 58 Abstract: title,
  59 + Module: item.Module,
  60 + Type: item.Type,
  61 + Metadata: &domain.SessionMetadata{
  62 + DatasetId: item.DatasetId,
  63 + DocumentIds: item.DocumentIds,
  64 + },
  65 + Rank: time.Now().Unix(),
56 } 66 }
57 } 67 }
58 68
59 func NewTypesChatSession(item *domain.ChatSession) types.ChatSessionItem { 69 func NewTypesChatSession(item *domain.ChatSession) types.ChatSessionItem {
  70 + var documentIds []int64
  71 + var datasetId int64
  72 + if item.Metadata != nil {
  73 + datasetId = item.Metadata.DatasetId
  74 + documentIds = item.Metadata.DocumentIds
  75 + }
60 return types.ChatSessionItem{ 76 return types.ChatSessionItem{
61 - Id: item.Id,  
62 - Title: item.Title,  
63 - Abstract: item.Abstract,  
64 - CreatedAt: item.CreatedAt, 77 + Id: item.Id,
  78 + Title: item.Title,
  79 + Abstract: item.Abstract,
  80 + CreatedAt: item.CreatedAt,
  81 + Module: item.Module,
  82 + Type: item.Type,
  83 + DatasetId: datasetId,
  84 + DocumentIds: documentIds,
65 } 85 }
66 } 86 }
@@ -3,7 +3,10 @@ package chat @@ -3,7 +3,10 @@ package chat
3 import ( 3 import (
4 "context" 4 "context"
5 "fmt" 5 "fmt"
  6 + "github.com/samber/lo"
6 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
7 10
8 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc" 11 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
9 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types" 12 "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
@@ -30,19 +33,61 @@ func (l *ChatSessionSearchLogic) ChatSessionSearch(req *types.ChatSessionSearchR @@ -30,19 +33,61 @@ func (l *ChatSessionSearchLogic) ChatSessionSearch(req *types.ChatSessionSearchR
30 conn = l.svcCtx.DefaultDBConn() 33 conn = l.svcCtx.DefaultDBConn()
31 dms []*domain.ChatSession 34 dms []*domain.ChatSession
32 total int64 35 total int64
  36 + token = contextdata.GetUserTokenFromCtx(l.ctx)
33 ) 37 )
34 38
35 queryOptions := domain.NewQueryOptions(). 39 queryOptions := domain.NewQueryOptions().
36 - WithKV("title", fmt.Sprintf("%%%v%%", req.Title))  
37 - 40 + WithKV("module", req.Module).
  41 + WithKV("companyId", token.CompanyId).
  42 + WithKV("userId", token.UserId)
  43 + if req.Title != "" {
  44 + queryOptions.WithKV("title", fmt.Sprintf("%%%v%%", req.Title))
  45 + }
38 if req.Page != 0 && req.Size != 0 { 46 if req.Page != 0 && req.Size != 0 {
39 queryOptions.WithOffsetLimit(req.Page, req.Size) 47 queryOptions.WithOffsetLimit(req.Page, req.Size)
40 } 48 }
41 49
42 total, dms, err = l.svcCtx.ChatSessionRepository.Find(l.ctx, conn, queryOptions) 50 total, dms, err = l.svcCtx.ChatSessionRepository.Find(l.ctx, conn, queryOptions)
43 list := make([]types.ChatSessionItem, 0) 51 list := make([]types.ChatSessionItem, 0)
44 - for i := range dms {  
45 - list = append(list, NewTypesChatSession(dms[i])) 52 +
  53 + // 1.分组dataset document mapping
  54 + var datasetIds []int64
  55 + for _, session := range dms {
  56 + if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
  57 + datasetIds = append(datasetIds, session.Metadata.DatasetId)
  58 + }
  59 + datasetIds = lo.Uniq(datasetIds)
  60 + }
  61 + var groupDocumentMappings map[int64][]*domain.ChatDatasetDocumentMapping
  62 + if len(datasetIds) > 0 {
  63 + _, documentMapping, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, datasetIds...)
  64 + groupDocumentMappings = lo.GroupBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) int64 {
  65 + return item.DatasetId
  66 + })
  67 + }
  68 +
  69 + // 2. 加载documents
  70 + lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne)
  71 + for i, session := range dms {
  72 + var documents []types.ChatDocumentItem
  73 + if session.Type == domain.TypeSparkDocumentsChat && len(session.Metadata.DocumentIds) > 0 {
  74 + for _, id := range session.Metadata.DocumentIds {
  75 + if document, _ := lazyDocument.Load(l.ctx, conn, id); document != nil {
  76 + documents = append(documents, types.NewTypesChatDocument(document))
  77 + }
  78 + }
  79 + } else if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
  80 + if documentMapping, ok := groupDocumentMappings[session.Metadata.DatasetId]; ok {
  81 + lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
  82 + if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil {
  83 + documents = append(documents, types.NewTypesChatDocument(document))
  84 + }
  85 + })
  86 + }
  87 + }
  88 + typesSession := NewTypesChatSession(dms[i])
  89 + typesSession.Documents = documents
  90 + list = append(list, typesSession)
46 } 91 }
47 resp = &types.ChatSessionSearchResponse{ 92 resp = &types.ChatSessionSearchResponse{
48 List: list, 93 List: list,
  1 +package chat
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  8 +
  9 + "github.com/zeromicro/go-zero/core/logx"
  10 +)
  11 +
  12 +type ChatSparkSessionSaveLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewChatSparkSessionSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSparkSessionSaveLogic {
  19 + return &ChatSparkSessionSaveLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *ChatSparkSessionSaveLogic) ChatSparkSessionSave(req *types.ChatSessionSaveRequest) (resp *types.ChatSessionSaveResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
  1 +package core
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  9 +)
  10 +
  11 +func DatasetAddFiles(ctx context.Context, svcCtx *svc.ServiceContext, conn transaction.Conn, datasetId int64, documents []int64) error {
  12 + var (
  13 + documentMapping []*domain.ChatDatasetDocumentMapping
  14 + err error
  15 + )
  16 + _, documentMapping, _ = svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(ctx, conn, datasetId)
  17 +
  18 + for _, id := range documents {
  19 + if lo.ContainsBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) bool {
  20 + return item.DocumentId == id
  21 + }) {
  22 + continue
  23 + }
  24 + if _, err = svcCtx.ChatDatasetDocumentMappingRepository.Insert(ctx, conn, &domain.ChatDatasetDocumentMapping{
  25 + DatasetId: datasetId,
  26 + DocumentId: id,
  27 + }); err != nil {
  28 + return err
  29 + }
  30 + }
  31 + return nil
  32 +}
  1 +package core
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  9 +)
  10 +
  11 +func DatasetRemoveFiles(ctx context.Context, svcCtx *svc.ServiceContext, conn transaction.Conn, datasetId int64, documents []int64) error {
  12 + var (
  13 + documentMapping []*domain.ChatDatasetDocumentMapping
  14 + err error
  15 + )
  16 + _, documentMapping, _ = svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(ctx, conn, datasetId)
  17 +
  18 + for _, id := range documents {
  19 + var found *domain.ChatDatasetDocumentMapping
  20 + if !lo.ContainsBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) bool {
  21 + if item.DocumentId == id {
  22 + found = item
  23 + }
  24 + return item.DocumentId == id
  25 + }) {
  26 + continue
  27 + }
  28 + if _, err = svcCtx.ChatDatasetDocumentMappingRepository.Delete(ctx, conn, found); err != nil {
  29 + return err
  30 + }
  31 + }
  32 + return nil
  33 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  9 +
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type ChatDatasetAddFilesLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewChatDatasetAddFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetAddFilesLogic {
  23 + return &ChatDatasetAddFilesLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *ChatDatasetAddFilesLogic) ChatDatasetAddFiles(req *types.ChatDatasetAddFilesRequest) (resp *types.ChatDatasetAddFilesResponse, err error) {
  31 + var (
  32 + conn = l.svcCtx.DefaultDBConn()
  33 + dm *domain.ChatDataset
  34 + )
  35 + // 货号唯一
  36 + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  37 + return nil, xerr.NewErrMsgErr("知识库不存在", err)
  38 + }
  39 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  40 + if err = core.DatasetAddFiles(l.ctx, l.svcCtx, conn, dm.Id, req.DocumentIds); err != nil {
  41 + return err
  42 + }
  43 + return err
  44 + }, true); err != nil {
  45 + return nil, xerr.NewErrMsg("添加文档失败")
  46 + }
  47 + resp = &types.ChatDatasetAddFilesResponse{}
  48 + return
  49 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type ChatDatasetDeleteLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewChatDatasetDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetDeleteLogic {
  22 + return &ChatDatasetDeleteLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *ChatDatasetDeleteLogic) ChatDatasetDelete(req *types.ChatDatasetDeleteRequest) (resp *types.ChatDatasetDeleteResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + dm *domain.ChatDataset
  33 + )
  34 + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  35 + return nil, xerr.NewErrMsgErr("不存在", err)
  36 + }
  37 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  38 + if dm, err = l.svcCtx.ChatDatasetRepository.Delete(l.ctx, conn, dm); err != nil {
  39 + return err
  40 + }
  41 + // 删除document & dataset 关联
  42 + if err = l.svcCtx.ChatDatasetDocumentMappingRepository.DeleteByDataset(l.ctx, conn, dm.Id); err != nil {
  43 + return err
  44 + }
  45 + return nil
  46 + }, true); err != nil {
  47 + return nil, xerr.NewErrMsgErr("移除失败", err)
  48 + }
  49 + resp = &types.ChatDatasetDeleteResponse{}
  50 + return
  51 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  9 +
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type ChatDatasetGetLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewChatDatasetGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetGetLogic {
  23 + return &ChatDatasetGetLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *ChatDatasetGetLogic) ChatDatasetGet(req *types.ChatDatasetGetRequest) (resp *types.ChatDatasetGetResponse, err error) {
  31 + var (
  32 + conn = l.svcCtx.DefaultDBConn()
  33 + dm *domain.ChatDataset
  34 + documentMapping []*domain.ChatDatasetDocumentMapping
  35 + )
  36 + // 货号唯一
  37 + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  38 + return nil, xerr.NewErrMsgErr("不存在", err)
  39 + }
  40 + documents := make([]types.ChatDocumentItem, 0)
  41 + _, documentMapping, _ = l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, dm.Id)
  42 + lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne)
  43 + lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
  44 + if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil {
  45 + documents = append(documents, types.NewTypesChatDocument(document))
  46 + }
  47 + })
  48 + resp = &types.ChatDatasetGetResponse{
  49 + ChatDataset: NewTypesChatDataset(dm, nil),
  50 + Documents: documents,
  51 + }
  52 + return
  53 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  9 +
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type ChatDatasetRemvoeFilesLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewChatDatasetRemvoeFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetRemvoeFilesLogic {
  23 + return &ChatDatasetRemvoeFilesLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *ChatDatasetRemvoeFilesLogic) ChatDatasetRemvoeFiles(req *types.ChatDatasetAddFilesRequest) (resp *types.ChatDatasetAddFilesResponse, err error) {
  31 + var (
  32 + conn = l.svcCtx.DefaultDBConn()
  33 + dm *domain.ChatDataset
  34 + )
  35 + // 货号唯一
  36 + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  37 + return nil, xerr.NewErrMsgErr("不存在", err)
  38 + }
  39 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  40 + if err = core.DatasetRemoveFiles(l.ctx, l.svcCtx, conn, dm.Id, req.DocumentIds); err != nil {
  41 + return err
  42 + }
  43 + return err
  44 + }, true); err != nil {
  45 + return nil, xerr.NewErrMsg("添加文档失败")
  46 + }
  47 + resp = &types.ChatDatasetAddFilesResponse{}
  48 + return
  49 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type ChatDatasetRenameLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewChatDatasetRenameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetRenameLogic {
  22 + return &ChatDatasetRenameLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *ChatDatasetRenameLogic) ChatDatasetRename(req *types.ChatDatasetRenameRequest) (resp *types.ChatDatasetRenameResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + dm *domain.ChatDataset
  33 + )
  34 + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  35 + return nil, xerr.NewErrMsgErr("不存在", err)
  36 + }
  37 + // 赋值
  38 + if req.Name != "" {
  39 + dm.Name = req.Name
  40 + }
  41 + // 更新
  42 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  43 + dm, err = l.svcCtx.ChatDatasetRepository.UpdateWithVersion(l.ctx, conn, dm)
  44 + return err
  45 + }, true); err != nil {
  46 + return nil, xerr.NewErrMsg("更新失败")
  47 + }
  48 + resp = &types.ChatDatasetRenameResponse{
  49 + ChatDataset: NewTypesChatDataset(dm, nil),
  50 + }
  51 + return
  52 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "github.com/samber/lo"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  10 +
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  12 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  13 +
  14 + "github.com/zeromicro/go-zero/core/logx"
  15 +)
  16 +
  17 +type ChatDatasetSaveLogic struct {
  18 + logx.Logger
  19 + ctx context.Context
  20 + svcCtx *svc.ServiceContext
  21 +}
  22 +
  23 +func NewChatDatasetSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetSaveLogic {
  24 + return &ChatDatasetSaveLogic{
  25 + Logger: logx.WithContext(ctx),
  26 + ctx: ctx,
  27 + svcCtx: svcCtx,
  28 + }
  29 +}
  30 +
  31 +func (l *ChatDatasetSaveLogic) ChatDatasetSave(req *types.ChatDatasetSaveRequest) (resp *types.ChatDatasetSaveResponse, err error) {
  32 + var (
  33 + dm *domain.ChatDataset
  34 + token = contextdata.GetUserTokenFromCtx(l.ctx)
  35 + )
  36 + if req.Name == "" {
  37 + req.Name = "新知识库"
  38 + }
  39 + dm = &domain.ChatDataset{
  40 + UserId: token.UserId,
  41 + CompanyId: token.CompanyId,
  42 + Name: req.Name,
  43 + Status: domain.Enable,
  44 + }
  45 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  46 + if dm, err = l.svcCtx.ChatDatasetRepository.Insert(l.ctx, conn, dm); err != nil {
  47 + return err
  48 + }
  49 + if len(req.DocumentIds) > 0 {
  50 + for _, id := range req.DocumentIds {
  51 + l.svcCtx.ChatDatasetDocumentMappingRepository.Insert(l.ctx, conn, &domain.ChatDatasetDocumentMapping{
  52 + DatasetId: dm.Id,
  53 + DocumentId: id,
  54 + })
  55 + }
  56 + }
  57 + return err
  58 + }, true); err != nil {
  59 + return nil, xerr.NewErrMsg("保存失败")
  60 + }
  61 + resp = &types.ChatDatasetSaveResponse{
  62 + ChatDataset: NewTypesChatDataset(dm, lo.ToPtr(len(req.DocumentIds))),
  63 + }
  64 + return
  65 +}
  66 +
  67 +//func NewDomainChatDataset(item types.ChatDatasetItem) *domain.ChatDataset {
  68 +// return &domain.ChatDataset{
  69 +
  70 +// }
  71 +// }
  72 +func NewTypesChatDataset(item *domain.ChatDataset, fileNum *int) types.ChatDatasetItem {
  73 + return types.ChatDatasetItem{
  74 + Id: item.Id,
  75 + Name: lo.ToPtr(item.Name),
  76 + Desc: lo.ToPtr(item.Desc),
  77 + Status: lo.ToPtr(item.Status),
  78 + CreatedAt: item.CreatedAt,
  79 + UpdatedAt: item.UpdatedAt,
  80 + FileNumber: fileNum,
  81 + }
  82 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "fmt"
  6 + "github.com/samber/lo"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type ChatDatasetSearchLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewChatDatasetSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetSearchLogic {
  22 + return &ChatDatasetSearchLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *ChatDatasetSearchLogic) ChatDatasetSearch(req *types.ChatDatasetSearchRequest) (resp *types.ChatDatasetSearchResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + dms []*domain.ChatDataset
  33 + total int64
  34 + )
  35 +
  36 + queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
  37 + WithKV("status", req.Status)
  38 + if req.Name != "" {
  39 + queryOptions.WithKV("name", fmt.Sprintf("%%%v%%", req.Name))
  40 + }
  41 + total, dms, err = l.svcCtx.ChatDatasetRepository.Find(l.ctx, conn, queryOptions)
  42 + list := make([]types.ChatDatasetItem, 0)
  43 +
  44 + // 知识库关联的文档
  45 + ids := domain.Values(dms, domain.ChatDatasetId)
  46 + _, documentMappings, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, ids...)
  47 + documentGroups := lo.GroupBy(documentMappings, func(item *domain.ChatDatasetDocumentMapping) int64 {
  48 + return item.DatasetId
  49 + })
  50 +
  51 + for i := range dms {
  52 + var num = 0
  53 + if v, ok := documentGroups[dms[i].Id]; ok {
  54 + num = len(v)
  55 + }
  56 + list = append(list, NewTypesChatDataset(dms[i], lo.ToPtr(num)))
  57 + }
  58 + resp = &types.ChatDatasetSearchResponse{
  59 + List: list,
  60 + Total: total,
  61 + }
  62 + return
  63 +}
  1 +package dataset
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type ChatDatasetUpdateLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewChatDatasetUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetUpdateLogic {
  22 + return &ChatDatasetUpdateLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *ChatDatasetUpdateLogic) ChatDatasetUpdate(req *types.ChatDatasetUpdateRequest) (resp *types.ChatDatasetUpdateResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + dm *domain.ChatDataset
  33 + )
  34 + if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  35 + return nil, xerr.NewErrMsgErr("不存在", err)
  36 + }
  37 + // 赋值
  38 + if req.ChatDataset.Name != nil {
  39 + dm.Name = *req.ChatDataset.Name
  40 + }
  41 + if req.ChatDataset.Desc != nil {
  42 + dm.Desc = *req.ChatDataset.Desc
  43 + }
  44 + if req.ChatDataset.Status != nil {
  45 + dm.Status = *req.ChatDataset.Status
  46 + }
  47 + // 更新
  48 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  49 + dm, err = l.svcCtx.ChatDatasetRepository.UpdateWithVersion(l.ctx, conn, dm)
  50 + return err
  51 + }, true); err != nil {
  52 + return nil, xerr.NewErrMsg("更新失败")
  53 + }
  54 + resp = &types.ChatDatasetUpdateResponse{}
  55 + return
  56 +}
  1 +package document
  2 +
  3 +import (
  4 + "context"
  5 + "fmt"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  10 +
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  12 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  13 +
  14 + "github.com/zeromicro/go-zero/core/logx"
  15 +)
  16 +
  17 +type ChatDocumentBatchSaveLogic struct {
  18 + logx.Logger
  19 + ctx context.Context
  20 + svcCtx *svc.ServiceContext
  21 +}
  22 +
  23 +func NewChatDocumentBatchSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentBatchSaveLogic {
  24 + return &ChatDocumentBatchSaveLogic{
  25 + Logger: logx.WithContext(ctx),
  26 + ctx: ctx,
  27 + svcCtx: svcCtx,
  28 + }
  29 +}
  30 +
  31 +func (l *ChatDocumentBatchSaveLogic) ChatDocumentBatchSave(req *types.ChatDocumentBatchSaveRequest) (resp *types.ChatDocumentBatchSaveResponse, err error) {
  32 + var (
  33 + model *domain.ChatModel
  34 + fileId string
  35 + documents = make([]types.ChatDocumentItem, 0)
  36 + fileMap = make(map[string]string)
  37 + )
  38 + model, _ = domain.DefaultChatModels.Match(4)
  39 + for _, file := range req.Files {
  40 + if ext := types.GetFileTypeByExt(types.GetExt(file.FileName)); ext == "" {
  41 + return nil, xerr.NewErrMsgErr(fmt.Sprintf("%v文件格式不支持,目前仅支持格式txt/markdown/pdf/doc/docx", file.FileName), nil)
  42 + }
  43 + }
  44 + for _, file := range req.Files {
  45 + // 文件上传星火文档
  46 + // 设置回调
  47 + if fileId, err = ai.SparkUploadFile(model.Config.AppId, model.Config.AppKey, model.Config.AppSecret, ai.SparkFileRequest{
  48 + Url: file.Url,
  49 + FileName: file.FileName,
  50 + CallbackUrl: "",
  51 + }); err != nil {
  52 + return nil, xerr.NewErrMsgErr("上传文件到星火文档失败", err)
  53 + }
  54 + fileMap[file.Url] = fileId
  55 + }
  56 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  57 + for _, file := range req.Files {
  58 + var ok bool
  59 + if fileId, ok = fileMap[file.Url]; !ok {
  60 + continue
  61 + }
  62 + var dm *domain.ChatDocument
  63 + // 唯一判断
  64 + dm = types.NewDomainChatDocument(file.FileName, file.Url, file.Size, fileId)
  65 + if dm, err = l.svcCtx.ChatDocumentRepository.Insert(l.ctx, conn, dm); err != nil {
  66 + return err
  67 + }
  68 + documents = append(documents, types.NewTypesChatDocument(dm))
  69 + }
  70 +
  71 + return err
  72 + }, true); err != nil {
  73 + return nil, xerr.NewErrMsgErr("保存失败", err)
  74 + }
  75 +
  76 + resp = &types.ChatDocumentBatchSaveResponse{
  77 + ChatDocument: documents,
  78 + }
  79 + return
  80 +}
  1 +package document
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type ChatDocumentDeleteLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewChatDocumentDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentDeleteLogic {
  22 + return &ChatDocumentDeleteLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *ChatDocumentDeleteLogic) ChatDocumentDelete(req *types.ChatDocumentDeleteRequest) (resp *types.ChatDocumentDeleteResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + dm *domain.ChatDocument
  33 + )
  34 + if dm, err = l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  35 + return nil, xerr.NewErrMsgErr("不存在", err)
  36 + }
  37 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  38 + if dm, err = l.svcCtx.ChatDocumentRepository.Delete(l.ctx, conn, dm); err != nil {
  39 + return err
  40 + }
  41 + // 删除document & dataset 关联
  42 + if err = l.svcCtx.ChatDatasetDocumentMappingRepository.DeleteByDocument(l.ctx, conn, dm.Id); err != nil {
  43 + return err
  44 + }
  45 + return nil
  46 + }, true); err != nil {
  47 + return nil, xerr.NewErrMsgErr("移除失败", err)
  48 + }
  49 + return
  50 +}
  1 +package document
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  7 +
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +
  11 + "github.com/zeromicro/go-zero/core/logx"
  12 +)
  13 +
  14 +type ChatDocumentGetLogic struct {
  15 + logx.Logger
  16 + ctx context.Context
  17 + svcCtx *svc.ServiceContext
  18 +}
  19 +
  20 +func NewChatDocumentGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentGetLogic {
  21 + return &ChatDocumentGetLogic{
  22 + Logger: logx.WithContext(ctx),
  23 + ctx: ctx,
  24 + svcCtx: svcCtx,
  25 + }
  26 +}
  27 +
  28 +func (l *ChatDocumentGetLogic) ChatDocumentGet(req *types.ChatDocumentGetRequest) (resp *types.ChatDocumentGetResponse, err error) {
  29 + var (
  30 + conn = l.svcCtx.DefaultDBConn()
  31 + dm *domain.ChatDocument
  32 + )
  33 + // 货号唯一
  34 + if dm, err = l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  35 + return nil, xerr.NewErrMsgErr("不存在", err)
  36 + }
  37 + resp = &types.ChatDocumentGetResponse{
  38 + ChatDocument: types.NewTypesChatDocument(dm),
  39 + }
  40 + return
  41 +}
  1 +package document
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  8 +
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  11 +
  12 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type ChatDocumentRenameLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewChatDocumentRenameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentRenameLogic {
  22 + return &ChatDocumentRenameLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *ChatDocumentRenameLogic) ChatDocumentRename(req *types.ChatDocumentRenameRequest) (resp *types.ChatDocumentRenameResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + dm *domain.ChatDocument
  33 + )
  34 + if dm, err = l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  35 + return nil, xerr.NewErrMsgErr("不存在", err)
  36 + }
  37 + // 赋值
  38 + dm.Name = req.Name
  39 + // 更新
  40 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  41 + dm, err = l.svcCtx.ChatDocumentRepository.UpdateWithVersion(l.ctx, conn, dm)
  42 + return err
  43 + }, true); err != nil {
  44 + return nil, xerr.NewErrMsg("更新失败")
  45 + }
  46 + resp = &types.ChatDocumentRenameResponse{
  47 + ChatDocument: types.NewTypesChatDocument(dm),
  48 + }
  49 + return
  50 +}
  1 +package document
  2 +
  3 +import (
  4 + "context"
  5 + "fmt"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  7 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai"
  10 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
  11 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
  12 +
  13 + "github.com/zeromicro/go-zero/core/logx"
  14 +)
  15 +
  16 +type ChatDocumentSaveLogic struct {
  17 + logx.Logger
  18 + ctx context.Context
  19 + svcCtx *svc.ServiceContext
  20 +}
  21 +
  22 +func NewChatDocumentSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentSaveLogic {
  23 + return &ChatDocumentSaveLogic{
  24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + }
  28 +}
  29 +
  30 +func (l *ChatDocumentSaveLogic) ChatDocumentSave(req *types.ChatDocumentSaveRequest) (resp *types.ChatDocumentSaveResponse, err error) {
  31 + var (
  32 + //conn = l.svcCtx.DefaultDBConn()
  33 + dm *domain.ChatDocument
  34 + model *domain.ChatModel
  35 + fileId string
  36 + )
  37 + if ext := types.GetFileTypeByExt(types.GetExt(req.FileName)); ext == "" {
  38 + return nil, xerr.NewErrMsgErr(fmt.Sprintf("%v文件格式不支持,目前仅支持格式txt/markdown/pdf/doc/docx", req.FileName), nil)
  39 + }
  40 + model, _ = domain.DefaultChatModels.Match(domain.SparkChatDocModelId)
  41 + // 文件上传星火文档
  42 + // 设置回调
  43 + if fileId, err = ai.SparkUploadFile(model.Config.AppId, model.Config.AppKey, model.Config.AppSecret, ai.SparkFileRequest{
  44 + Url: req.Url,
  45 + FileName: req.FileName,
  46 + CallbackUrl: "",
  47 + }); err != nil {
  48 + return nil, xerr.NewErrMsgErr("上传文档失败", err)
  49 + }
  50 + // 唯一判断
  51 + dm = types.NewDomainChatDocument(req.FileName, req.Url, req.Size, fileId)
  52 + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  53 + dm, err = l.svcCtx.ChatDocumentRepository.Insert(l.ctx, conn, dm)
  54 + return err
  55 + }, true); err != nil {
  56 + return nil, xerr.NewErrMsg("保存失败")
  57 + }
  58 +
  59 + resp = &types.ChatDocumentSaveResponse{
  60 + ChatDocument: types.NewTypesChatDocument(dm),
  61 + }
  62 + return
  63 +}
  1 +package document
  2 +
  3 +import (
  4 + "context"
  5 + "fmt"
  6 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  7 +
  8 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
  9 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
  10 +
  11 + "github.com/zeromicro/go-zero/core/logx"
  12 +)
  13 +
  14 +type ChatDocumentSearchLogic struct {
  15 + logx.Logger
  16 + ctx context.Context
  17 + svcCtx *svc.ServiceContext
  18 +}
  19 +
  20 +func NewChatDocumentSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentSearchLogic {
  21 + return &ChatDocumentSearchLogic{
  22 + Logger: logx.WithContext(ctx),
  23 + ctx: ctx,
  24 + svcCtx: svcCtx,
  25 + }
  26 +}
  27 +
  28 +func (l *ChatDocumentSearchLogic) ChatDocumentSearch(req *types.ChatDocumentSearchRequest) (resp *types.ChatDocumentSearchResponse, err error) {
  29 + var (
  30 + conn = l.svcCtx.DefaultDBConn()
  31 + dms []*domain.ChatDocument
  32 + total int64
  33 + )
  34 +
  35 + queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
  36 + WithKV("fileType", req.FileType).
  37 + WithKV("status", req.Status)
  38 + if req.Name != "" {
  39 + queryOptions.WithKV("name", fmt.Sprintf("%%%v%%", req.Name))
  40 + }
  41 + total, dms, err = l.svcCtx.ChatDocumentRepository.Find(l.ctx, conn, queryOptions)
  42 + list := make([]types.ChatDocumentItem, 0)
  43 + for i := range dms {
  44 + list = append(list, types.NewTypesChatDocument(dms[i]))
  45 + }
  46 + resp = &types.ChatDocumentSearchResponse{
  47 + List: list,
  48 + Total: total,
  49 + }
  50 + return
  51 +}
@@ -15,13 +15,16 @@ import ( @@ -15,13 +15,16 @@ import (
15 ) 15 )
16 16
17 type ServiceContext struct { 17 type ServiceContext struct {
18 - Config config.Config  
19 - LogRequest rest.Middleware  
20 - Redis *redis.Redis  
21 - DB *gorm.DB  
22 - ChatSessionRepository domain.ChatSessionRepository  
23 - ChatSessionRecordRepository domain.ChatSessionRecordRepository  
24 - SystemOpen open.SystemOpen 18 + Config config.Config
  19 + LogRequest rest.Middleware
  20 + Redis *redis.Redis
  21 + DB *gorm.DB
  22 + ChatSessionRepository domain.ChatSessionRepository
  23 + ChatSessionRecordRepository domain.ChatSessionRecordRepository
  24 + ChatDocumentRepository domain.ChatDocumentRepository
  25 + ChatDatasetRepository domain.ChatDatasetRepository
  26 + ChatDatasetDocumentMappingRepository domain.ChatDatasetDocumentMappingRepository
  27 + SystemOpen open.SystemOpen
25 } 28 }
26 29
27 func NewServiceContext(c config.Config) *ServiceContext { 30 func NewServiceContext(c config.Config) *ServiceContext {
@@ -30,14 +33,16 @@ func NewServiceContext(c config.Config) *ServiceContext { @@ -30,14 +33,16 @@ func NewServiceContext(c config.Config) *ServiceContext {
30 mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass) 33 mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass)
31 redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"}) 34 redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"})
32 return &ServiceContext{ 35 return &ServiceContext{
33 - Config: c,  
34 - DB: db,  
35 - Redis: redis,  
36 - LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,  
37 - ChatSessionRepository: repository.NewChatSessionRepository(cache.NewCachedRepository(mlCache)),  
38 - ChatSessionRecordRepository: repository.NewChatSessionRecordRepository(cache.NewCachedRepository(mlCache)),  
39 -  
40 - SystemOpen: open.NewSystemOpen(c.Redis), 36 + Config: c,
  37 + DB: db,
  38 + Redis: redis,
  39 + LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
  40 + ChatSessionRepository: repository.NewChatSessionRepository(cache.NewCachedRepository(mlCache)),
  41 + ChatSessionRecordRepository: repository.NewChatSessionRecordRepository(cache.NewCachedRepository(mlCache)),
  42 + ChatDocumentRepository: repository.NewChatDocumentRepository(cache.NewCachedRepository(mlCache)),
  43 + ChatDatasetRepository: repository.NewChatDatasetRepository(cache.NewCachedRepository(mlCache)),
  44 + ChatDatasetDocumentMappingRepository: repository.NewChatDatasetDocumentMappingRepository(cache.NewCachedRepository(mlCache)),
  45 + SystemOpen: open.NewSystemOpen(c.Redis),
41 } 46 }
42 } 47 }
43 48
  1 +package types
  2 +
  3 +import (
  4 + "github.com/samber/lo"
  5 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  6 +)
  7 +
  8 +func NewTypesChatDataset(item *domain.ChatDataset, fileNum *int) ChatDatasetItem {
  9 + return ChatDatasetItem{
  10 + Id: item.Id,
  11 + Name: lo.ToPtr(item.Name),
  12 + Desc: lo.ToPtr(item.Desc),
  13 + Status: lo.ToPtr(item.Status),
  14 + CreatedAt: item.CreatedAt,
  15 + UpdatedAt: item.UpdatedAt,
  16 + FileNumber: fileNum,
  17 + }
  18 +}
  1 +package types
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
  5 + "path/filepath"
  6 + "strings"
  7 +)
  8 +
  9 +func NewDomainChatDocument(name, url string, size float64, fileId string) *domain.ChatDocument {
  10 + ext := GetExt(name)
  11 + return &domain.ChatDocument{
  12 + Name: name,
  13 + Status: domain.StatusInUsed,
  14 + FileType: GetFileTypeByExt(ext),
  15 + Metadata: domain.DocumentMetadata{
  16 + OriginFileName: filepath.Base(name),
  17 + Ext: ext,
  18 + FileId: fileId,
  19 + FileUrl: url,
  20 + FileSize: size,
  21 + },
  22 + }
  23 +}
  24 +
  25 +func NewTypesChatDocument(item *domain.ChatDocument) ChatDocumentItem {
  26 + return ChatDocumentItem{
  27 + Id: item.Id,
  28 + Name: item.Name,
  29 + FileType: item.FileType,
  30 + Status: item.Status,
  31 + OriginFileName: item.Metadata.OriginFileName,
  32 + Ext: item.Metadata.Ext,
  33 + FileId: item.Metadata.FileId,
  34 + FileUrl: item.Metadata.FileUrl,
  35 + FileSize: item.Metadata.FileSize,
  36 + CreatedAt: item.CreatedAt,
  37 + }
  38 +}
  39 +
  40 +func GetFileTypeByExt(ext string) string {
  41 + switch ext {
  42 + case "md":
  43 + return "markdown"
  44 + case "pdf":
  45 + return ext
  46 + case "txt":
  47 + return ext
  48 + case "doc", "docx":
  49 + return "doc"
  50 + default:
  51 + return ""
  52 + }
  53 + return ""
  54 +}
  55 +
  56 +func GetExt(file string) string {
  57 + return strings.TrimPrefix(filepath.Ext(file), ".")
  58 +}
@@ -6,8 +6,10 @@ type ChatSessionGetRequest struct { @@ -6,8 +6,10 @@ type ChatSessionGetRequest struct {
6 } 6 }
7 7
8 type ChatSessionGetResponse struct { 8 type ChatSessionGetResponse struct {
9 - ChatSession ChatSessionItem `json:"session"`  
10 - Records []Record `json:"records"` 9 + ChatSession ChatSessionItem `json:"session"`
  10 + Records []Record `json:"records"`
  11 + Documents []ChatDocumentItem `json:"documents"`
  12 + Dataset *ChatDatasetItem `json:"dataset"`
11 } 13 }
12 14
13 type ChatSessionSaveRequest struct { 15 type ChatSessionSaveRequest struct {
@@ -15,6 +17,7 @@ type ChatSessionSaveRequest struct { @@ -15,6 +17,7 @@ type ChatSessionSaveRequest struct {
15 } 17 }
16 18
17 type ChatSessionSaveResponse struct { 19 type ChatSessionSaveResponse struct {
  20 + ChatSession ChatSessionItem `json:"session"`
18 } 21 }
19 22
20 type ChatSessionDeleteRequest struct { 23 type ChatSessionDeleteRequest struct {
@@ -33,9 +36,10 @@ type ChatSessionUpdateResponse struct { @@ -33,9 +36,10 @@ type ChatSessionUpdateResponse struct {
33 } 36 }
34 37
35 type ChatSessionSearchRequest struct { 38 type ChatSessionSearchRequest struct {
36 - Page int `json:"page,optional"`  
37 - Size int `json:"size,optional"`  
38 - Title string `json:"title,optional"` // 按标题搜索 39 + Page int `json:"page,optional"`
  40 + Size int `json:"size,optional"`
  41 + Title string `json:"title,optional"` // 按标题搜索
  42 + Module int `json:"module,optional"` // 模块 1:openai chat 2:星火文档问答
39 } 43 }
40 44
41 type ChatSessionSearchResponse struct { 45 type ChatSessionSearchResponse struct {
@@ -44,10 +48,26 @@ type ChatSessionSearchResponse struct { @@ -44,10 +48,26 @@ type ChatSessionSearchResponse struct {
44 } 48 }
45 49
46 type ChatSessionItem struct { 50 type ChatSessionItem struct {
47 - Id int64 `json:"id,optional,omitempty"` // 唯一标识  
48 - Title string `json:"title,optional,omitempty"` // 会话标题  
49 - Abstract string `json:"abstract,optional,omitempty"` // 摘要  
50 - CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间 51 + Id int64 `json:"id,optional,omitempty"` // 唯一标识
  52 + Title string `json:"title,optional,omitempty"` // 会话标题
  53 + Abstract string `json:"abstract,optional,omitempty"` // 摘要
  54 + CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
  55 + Module int `json:"module,optional,omitempty,default=1"` // 1:openai chat 2:星火文档问答
  56 + Type string `json:"type,optional,omitempty,default=chat"` // 类型 chat:普通问答 spark_dataset_chat:星火知识库问答 spark_documents_chat:星火多文档问答
  57 + DatasetId int64 `json:"datasetId,optional,omitempty"` // 知识库
  58 + DocumentIds []int64 `json:"documentIds,optional,omitempty"` // 多文档
  59 + Documents []ChatDocumentItem `json:"documents,optional,omitempty"` // 多文档
  60 + Author *User `json:"author,optional,omitempty"` // 提问人
  61 + TotalRecords int64 `json:"totalRecords,optional,omitempty"` // 记录数
  62 + Model *Model `json:"model,optional,omitempty"` // 模型
  63 +}
  64 +
  65 +type ChatSessionRenameRequest struct {
  66 + Id int64 `json:"id"` // 模型ID
  67 + Name string `json:"name"` // 模型名称
  68 +}
  69 +
  70 +type ChatSessionRenameResponse struct {
51 } 71 }
52 72
53 type ChatModelsRequest struct { 73 type ChatModelsRequest struct {
@@ -90,10 +110,10 @@ type ChatSessionConversationResponse struct { @@ -90,10 +110,10 @@ type ChatSessionConversationResponse struct {
90 } 110 }
91 111
92 type ChatSessionConversationRequestWs struct { 112 type ChatSessionConversationRequestWs struct {
93 - SessionId int64 `form:"sessionId"` // 会话ID  
94 - ModelId int64 `form:"modelId"` // 模型ID  
95 - ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document)  
96 - Text string `form:"text"` // 内容文本 113 + SessionId int64 `form:"sessionId"` // 会话ID
  114 + ModelId int64 `form:"modelId"` // 模型ID
  115 + ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
  116 + Text string `form:"text,optional"` // 内容文本
97 } 117 }
98 118
99 type Record struct { 119 type Record struct {
@@ -103,7 +123,7 @@ type Record struct { @@ -103,7 +123,7 @@ type Record struct {
103 ModelId int64 `json:"modelId,omitempty"` // 模型ID 123 ModelId int64 `json:"modelId,omitempty"` // 模型ID
104 AuthorId int64 `json:"authorId,omitempty"` // 作者ID 124 AuthorId int64 `json:"authorId,omitempty"` // 作者ID
105 Author *User `json:"author,omitempty"` // 提问人 125 Author *User `json:"author,omitempty"` // 提问人
106 - Model *Model `json:"model,omitempty"` // 应答人 126 + Model *Model `json:"model,omitempty"` // 模型
107 ContentType string `json:"contentType"` // 内容类型 文本:text (图片:image 文档:document) 127 ContentType string `json:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
108 ProblemText string `json:"problemText"` // 问题文本 128 ProblemText string `json:"problemText"` // 问题文本
109 AnswerText string `json:"answerText"` // 回答文本 129 AnswerText string `json:"answerText"` // 回答文本
@@ -121,3 +141,180 @@ type User struct { @@ -121,3 +141,180 @@ type User struct {
121 Name string `json:"name"` // 名称 141 Name string `json:"name"` // 名称
122 Avatar string `json:"avatar"` // 头像 142 Avatar string `json:"avatar"` // 头像
123 } 143 }
  144 +
  145 +type ChatSessionAddFilesRequest struct {
  146 + Id int64 `json:"id"` // 文档ID
  147 + DocumentIds []int64 `json:"documentIds"` // 文档ID列表
  148 +}
  149 +
  150 +type ChatSessionAddFilesResponse struct {
  151 +}
  152 +
  153 +type ChatDataSessionSearchRequest struct {
  154 + Page int `json:"page,optional"`
  155 + Size int `json:"size,optional"`
  156 + Title string `json:"title,optional"` // 按标题搜索
  157 + UserName string `json:"userName,optional"` // 用户名称
  158 + BeginTime int64 `json:"beginTime,optional"` // 会话创建时间
  159 + EndTime int64 `json:"endTime,optional"` // 会话创建时间
  160 +}
  161 +
  162 +type ChatDataSessionSearchResponse struct {
  163 + List []ChatSessionItem `json:"list"`
  164 + Total int64 `json:"total"`
  165 +}
  166 +
  167 +type ChatDocumentGetRequest struct {
  168 + Id int64 `path:"id"`
  169 +}
  170 +
  171 +type ChatDocumentGetResponse struct {
  172 + ChatDocument ChatDocumentItem `json:"document"`
  173 +}
  174 +
  175 +type ChatDocumentSaveRequest struct {
  176 + FileName string `json:"fileName"`
  177 + Url string `json:"url"`
  178 + Size float64 `json:"size"` // 文件大小(KB)
  179 +}
  180 +
  181 +type ChatDocumentSaveResponse struct {
  182 + ChatDocument ChatDocumentItem `json:"document"`
  183 +}
  184 +
  185 +type ChatDocumentDeleteRequest struct {
  186 + Id int64 `path:"id"`
  187 +}
  188 +
  189 +type ChatDocumentDeleteResponse struct {
  190 +}
  191 +
  192 +type ChatDocumentUpdateRequest struct {
  193 + Id int64 `path:"id"`
  194 + ChatDocument ChatDocumentItem `json:"document"`
  195 +}
  196 +
  197 +type ChatDocumentUpdateResponse struct {
  198 +}
  199 +
  200 +type ChatDocumentSearchRequest struct {
  201 + Page int `json:"page,optional"`
  202 + Size int `json:"size,optional"`
  203 + Name string `json:"name,optional"` // 文件名匹配
  204 + FileType string `json:"fileType,optional"` // 文件类型 markdown\pdf\txt\doc&docx
  205 + Status int `json:"status,optional"` // 文件状态 1.使用中、0.待处理、2.预处理中、3.处理失败
  206 +}
  207 +
  208 +type ChatDocumentSearchResponse struct {
  209 + List []ChatDocumentItem `json:"list"`
  210 + Total int64 `json:"total"`
  211 +}
  212 +
  213 +type ChatDocumentItem struct {
  214 + Id int64 `json:"id"`
  215 + Name string `json:"name,optional"` // 文件名
  216 + FileType string `json:"fileType"` // 文件类型 markdown\pdf\txt\doc&docx
  217 + Status int `json:"status"` // 1.使用中、0.待处理、2.预处理中、3.处理失败
  218 + OriginFileName string `json:"originFileName,omitempty"` // 源文件命
  219 + Ext string `json:"ext,omitempty"` // 格式
  220 + FileId string `json:"fileId,omitempty"` // 星火文件ID
  221 + FileUrl string `json:"fileUrl,omitempty"` // 文件地址
  222 + FileSize float64 `json:"fileSize,omitempty"` // 文件大小KB
  223 + CreatedAt int64 `json:"createdAt,omitempty"` // 创建时间
  224 + UpdatedAt int64 `json:"updatedAt,omitempty"` // 更新时间
  225 +}
  226 +
  227 +type ChatDocumentRenameRequest struct {
  228 + Id int64 `json:"id"` // 文档ID
  229 + Name string `json:"name"` // 新名称
  230 +}
  231 +
  232 +type ChatDocumentRenameResponse struct {
  233 + ChatDocument ChatDocumentItem `json:"document"`
  234 +}
  235 +
  236 +type ChatDocumentBatchSaveRequest struct {
  237 + Files []DocumentFile `json:"files"`
  238 +}
  239 +
  240 +type ChatDocumentBatchSaveResponse struct {
  241 + ChatDocument []ChatDocumentItem `json:"documents"`
  242 +}
  243 +
  244 +type DocumentFile struct {
  245 + FileName string `json:"fileName"`
  246 + Url string `json:"url"`
  247 + Size float64 `json:"size"` // 文件大小(KB)
  248 +}
  249 +
  250 +type ChatDatasetGetRequest struct {
  251 + Id int64 `path:"id"`
  252 +}
  253 +
  254 +type ChatDatasetGetResponse struct {
  255 + ChatDataset ChatDatasetItem `json:"dataset"`
  256 + Documents []ChatDocumentItem `json:"documents"`
  257 +}
  258 +
  259 +type ChatDatasetSaveRequest struct {
  260 + Name string `json:"name"` // 名称
  261 + DocumentIds []int64 `json:"documentIds"` // 文档ID列表
  262 +}
  263 +
  264 +type ChatDatasetSaveResponse struct {
  265 + ChatDataset ChatDatasetItem `json:"dataset"`
  266 +}
  267 +
  268 +type ChatDatasetDeleteRequest struct {
  269 + Id int64 `path:"id"`
  270 +}
  271 +
  272 +type ChatDatasetDeleteResponse struct {
  273 +}
  274 +
  275 +type ChatDatasetUpdateRequest struct {
  276 + Id int64 `path:"id"`
  277 + ChatDataset ChatDatasetItem `json:"dataset"`
  278 +}
  279 +
  280 +type ChatDatasetUpdateResponse struct {
  281 +}
  282 +
  283 +type ChatDatasetSearchRequest struct {
  284 + Page int `json:"page,optional"`
  285 + Size int `json:"size,optional"`
  286 + Name string `json:"name,optional"` // 文件名匹配
  287 + Status int `json:"status,optional,option=0|1|2"` // 1:启用 2:禁用
  288 +}
  289 +
  290 +type ChatDatasetSearchResponse struct {
  291 + List []ChatDatasetItem `json:"list"`
  292 + Total int64 `json:"total"`
  293 +}
  294 +
  295 +type ChatDatasetItem struct {
  296 + Id int64 `json:"id,optional,omitempty"`
  297 + Name *string `json:"name,optional,omitempty"` // 名称
  298 + Desc *string `json:"desc,optional,omitempty"` // 描述
  299 + Status *int `json:"status,optional,omitempty"` // 状态 1:启用 2:禁用
  300 + CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
  301 + UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间
  302 + FileNumber *int `json:"fileNumber,optional,omitempty"` // 文件数量
  303 +}
  304 +
  305 +type ChatDatasetRenameRequest struct {
  306 + Id int64 `json:"id"` // 文档ID
  307 + Name string `json:"name"` // 新名称
  308 +}
  309 +
  310 +type ChatDatasetRenameResponse struct {
  311 + ChatDataset ChatDatasetItem `json:"dataset"`
  312 +}
  313 +
  314 +type ChatDatasetAddFilesRequest struct {
  315 + Id int64 `json:"id"` // 文档ID
  316 + DocumentIds []int64 `json:"documentIds"` // 文档ID列表
  317 +}
  318 +
  319 +type ChatDatasetAddFilesResponse struct {
  320 +}
@@ -15,3 +15,21 @@ CREATE TABLE `chat_model` @@ -15,3 +15,21 @@ CREATE TABLE `chat_model`
15 `id` int(0) NOT NULL COMMENT '唯一标识', 15 `id` int(0) NOT NULL COMMENT '唯一标识',
16 PRIMARY KEY (`id`) USING BTREE 16 PRIMARY KEY (`id`) USING BTREE
17 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; 17 ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
  18 +
  19 +CREATE TABLE `chat_dataset`
  20 +(
  21 + `id` int(0) NOT NULL COMMENT '唯一标识',
  22 + PRIMARY KEY (`id`) USING BTREE
  23 +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
  24 +
  25 +CREATE TABLE `chat_document`
  26 +(
  27 + `id` int(0) NOT NULL COMMENT '唯一标识',
  28 + PRIMARY KEY (`id`) USING BTREE
  29 +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
  30 +
  31 +CREATE TABLE `chat_dataset_document_mapping`
  32 +(
  33 + `id` int(0) NOT NULL COMMENT '唯一标识',
  34 + PRIMARY KEY (`id`) USING BTREE
  35 +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
@@ -39,4 +39,5 @@ COPY --from=builder /build/api/${PROJECT} ./ @@ -39,4 +39,5 @@ COPY --from=builder /build/api/${PROJECT} ./
39 COPY --from=builder /build/cmd/ep/${PROJECTCODE}/api/etc/${CONFIG_FILE} ./etc/ 39 COPY --from=builder /build/cmd/ep/${PROJECTCODE}/api/etc/${CONFIG_FILE} ./etc/
40 40
41 EXPOSE 8080 41 EXPOSE 8080
  42 +EXPOSE 443
42 ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE} 43 ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
1 #!/bin/bash 1 #!/bin/bash
2 export PATH=/root/local/bin:$PATH 2 export PATH=/root/local/bin:$PATH
3 -kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss 3 +kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
4 if [ "$?" == "1" ];then 4 if [ "$?" == "1" ];then
5 - kubectl create -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml --record  
6 - kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss 5 + kubectl create -f /tmp/dev/sumicro-chat/sumicro-chat.yaml --record
  6 + kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
7 if [ "$?" == "0" ];then 7 if [ "$?" == "0" ];then
8 - echo "sumifcc-discuss service install success!" 8 + echo "sumicro-chat service install success!"
9 else 9 else
10 - echo "sumifcc-discuss service install fail!" 10 + echo "sumicro-chat service install fail!"
11 fi 11 fi
12 - kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss 12 + kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
13 if [ "$?" == "0" ];then 13 if [ "$?" == "0" ];then
14 - echo "sumifcc-discuss deployment install success!" 14 + echo "sumicro-chat deployment install success!"
15 else 15 else
16 - echo "sumifcc-discuss deployment install fail!" 16 + echo "sumicro-chat deployment install fail!"
17 fi 17 fi
18 else 18 else
19 - kubectl delete -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml  
20 - kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss 19 + kubectl delete -f /tmp/dev/sumicro-chat/sumicro-chat.yaml
  20 + kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
21 while [ "$?" == "0" ] 21 while [ "$?" == "0" ]
22 do 22 do
23 - kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss 23 + kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
24 done 24 done
25 - kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss 25 + kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
26 while [ "$?" == "0" ] 26 while [ "$?" == "0" ]
27 do 27 do
28 - kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss 28 + kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
29 done 29 done
30 - kubectl create -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml --record  
31 - kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss 30 + kubectl create -f /tmp/dev/sumicro-chat/sumicro-chat.yaml --record
  31 + kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
32 if [ "$?" == "0" ];then 32 if [ "$?" == "0" ];then
33 - echo "sumifcc-discuss service update success!" 33 + echo "sumicro-chat service update success!"
34 else 34 else
35 - echo "sumifcc-discuss service update fail!" 35 + echo "sumicro-chat service update fail!"
36 fi 36 fi
37 - kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss 37 + kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
38 if [ "$?" == "0" ];then 38 if [ "$?" == "0" ];then
39 - echo "sumifcc-discuss deployment update success!" 39 + echo "sumicro-chat deployment update success!"
40 else 40 else
41 - echo "sumifcc-discuss deployment update fail!" 41 + echo "sumicro-chat deployment update fail!"
42 fi 42 fi
43 fi 43 fi
1 apiVersion: v1 1 apiVersion: v1
2 -kind: ConfigMap  
3 -metadata:  
4 - name: sumicro-chat-config-dev  
5 -data:  
6 - core.yaml: |  
7 - Name: sumicro-chat-dev  
8 - Host: 0.0.0.0  
9 - Port: 8080  
10 -  
11 - Verbose: false  
12 - Migrate: true  
13 - Timeout: 30000  
14 - LogRequest: true # 记录详细请求日志  
15 -  
16 - Log:  
17 - #Mode: file  
18 - Encoding: plain  
19 - Level: debug # info  
20 - MaxSize: 1 # 2MB  
21 - TimeFormat: 2006-01-02 15:04:05  
22 - Rotation: size  
23 - MaxContentLength: 10240  
24 -  
25 - SystemAuth:  
26 - AccessSecret: su-platform  
27 - AccessExpire: 360000  
28 -  
29 - Redis:  
30 - Host: 192.168.0.243:6379  
31 - Type: node  
32 - Pass:  
33 - DB:  
34 - DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform port=31543 sslmode=disable TimeZone=Asia/Shanghai  
35 -  
36 ----  
37 -apiVersion: v1  
38 kind: Service 2 kind: Service
39 metadata: 3 metadata:
40 name: sumicro-chat 4 name: sumicro-chat
41 - namespace: mmm-suplus-test 5 + namespace: mmm-suplus-dev
42 labels: 6 labels:
43 k8s-app: sumicro-chat 7 k8s-app: sumicro-chat
44 spec: 8 spec:
@@ -56,7 +20,7 @@ apiVersion: extensions/v1beta1 @@ -56,7 +20,7 @@ apiVersion: extensions/v1beta1
56 kind: Deployment 20 kind: Deployment
57 metadata: 21 metadata:
58 name: sumicro-chat 22 name: sumicro-chat
59 - namespace: mmm-suplus-test 23 + namespace: mmm-suplus-dev
60 labels: 24 labels:
61 k8s-app: sumicro-chat 25 k8s-app: sumicro-chat
62 spec: 26 spec:
@@ -77,7 +41,7 @@ spec: @@ -77,7 +41,7 @@ spec:
77 - key: kubernetes.io/hostname 41 - key: kubernetes.io/hostname
78 operator: In 42 operator: In
79 values: 43 values:
80 - - cn-hangzhou.i-bp1djh1xn7taumbue1ze 44 + - cn-hangzhou.i-bp10pa9isz0xg7nlsuzp
81 45
82 containers: 46 containers:
83 - name: sumicro-chat 47 - name: sumicro-chat
1 syntax = "v1" 1 syntax = "v1"
2 2
3 -import "core/session.api"  
  3 +import "core/session.api"
  4 +import "core/document.api"
  5 +import "core/dataset.api"
  1 +syntax = "v1"
  2 +
  3 +// 后台接口
  4 +@server(
  5 + prefix: v1
  6 + group: dataset
  7 + middleware: LogRequest
  8 + jwt: SystemAuth
  9 +)
  10 +service Core {
  11 + @doc "知识库-详情"
  12 + @handler chatDatasetGet
  13 + get /chat/dataset/:id (ChatDatasetGetRequest) returns (ChatDatasetGetResponse)
  14 + @doc "知识库-保存"
  15 + @handler chatDatasetSave
  16 + post /chat/dataset (ChatDatasetSaveRequest) returns (ChatDatasetSaveResponse)
  17 + @doc "知识库-删除"
  18 + @handler chatDatasetDelete
  19 + delete /chat/dataset/:id (ChatDatasetDeleteRequest) returns (ChatDatasetDeleteResponse)
  20 + @doc "知识库-更新"
  21 + @handler chatDatasetUpdate
  22 + put /chat/dataset/:id (ChatDatasetUpdateRequest) returns (ChatDatasetUpdateResponse)
  23 + @doc "知识库-重命名"
  24 + @handler chatDatasetRename
  25 + post /chat/dataset/rename (ChatDatasetRenameRequest) returns (ChatDatasetRenameResponse)
  26 + @doc "知识库-搜索"
  27 + @handler chatDatasetSearch
  28 + post /chat/dataset/search (ChatDatasetSearchRequest) returns (ChatDatasetSearchResponse)
  29 + @doc "知识库-添加文件"
  30 + @handler chatDatasetAddFiles
  31 + post /chat/dataset/add_files (ChatDatasetAddFilesRequest) returns (ChatDatasetAddFilesResponse)
  32 + @doc "知识库-移除文件"
  33 + @handler chatDatasetRemvoeFiles
  34 + post /chat/dataset/remove_files (ChatDatasetAddFilesRequest) returns (ChatDatasetAddFilesResponse)
  35 +}
  36 +
  37 +type (
  38 + ChatDatasetGetRequest {
  39 + Id int64 `path:"id"`
  40 + }
  41 + ChatDatasetGetResponse {
  42 + ChatDataset ChatDatasetItem `json:"dataset"`
  43 + Documents []ChatDocumentItem `json:"documents"`
  44 + }
  45 +
  46 + ChatDatasetSaveRequest {
  47 + Name string `json:"name"` // 名称
  48 + DocumentIds []int64 `json:"documentIds"` // 文档ID列表
  49 + }
  50 + ChatDatasetSaveResponse {
  51 + ChatDataset ChatDatasetItem `json:"dataset"`
  52 + }
  53 +
  54 + ChatDatasetDeleteRequest {
  55 + Id int64 `path:"id"`
  56 + }
  57 + ChatDatasetDeleteResponse {}
  58 +
  59 + ChatDatasetUpdateRequest {
  60 + Id int64 `path:"id"`
  61 + ChatDataset ChatDatasetItem `json:"dataset"`
  62 + }
  63 + ChatDatasetUpdateResponse {}
  64 +
  65 + ChatDatasetSearchRequest {
  66 + Page int `json:"page,optional"`
  67 + Size int `json:"size,optional"`
  68 + Name string `json:"name,optional"` // 文件名匹配
  69 + Status int `json:"status,optional,option=0|1|2"`// 1:启用 2:禁用
  70 + }
  71 + ChatDatasetSearchResponse{
  72 + List []ChatDatasetItem `json:"list"`
  73 + Total int64 `json:"total"`
  74 + }
  75 + ChatDatasetItem {
  76 + Id int64 `json:"id,optional,omitempty"`
  77 + Name *string `json:"name,optional,omitempty"` // 名称
  78 + Desc *string `json:"desc,optional,omitempty"` // 描述
  79 + Status *int `json:"status,optional,omitempty"`// 状态 1:启用 2:禁用
  80 + CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
  81 + UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间
  82 + FileNumber *int `json:"fileNumber,optional,omitempty"` // 文件数量
  83 + }
  84 +)
  85 +
  86 +// 知识库重命名
  87 +type(
  88 + ChatDatasetRenameRequest{
  89 + Id int64 `json:"id"` // 文档ID
  90 + Name string `json:"name"` // 新名称
  91 + }
  92 + ChatDatasetRenameResponse{
  93 + ChatDataset ChatDatasetItem `json:"dataset"`
  94 + }
  95 +)
  96 +
  97 +// 知识库添加新文档
  98 +type(
  99 + ChatDatasetAddFilesRequest{
  100 + Id int64 `json:"id"` // 文档ID
  101 + DocumentIds []int64 `json:"documentIds"` // 文档ID列表
  102 + }
  103 + ChatDatasetAddFilesResponse{
  104 +
  105 + }
  106 +)
  1 +syntax = "v1"
  2 +
  3 +// 后台接口
  4 +@server(
  5 + prefix: v1
  6 + group: document
  7 + middleware: LogRequest
  8 + jwt: SystemAuth
  9 +)
  10 +service Core {
  11 + @doc "文档-详情"
  12 + @handler chatDocumentGet
  13 + get /chat/document/:id (ChatDocumentGetRequest) returns (ChatDocumentGetResponse)
  14 + @doc "文档-保存"
  15 + @handler chatDocumentSave
  16 + post /chat/document (ChatDocumentSaveRequest) returns (ChatDocumentSaveResponse)
  17 + @doc "文档-批量保存"
  18 + @handler chatDocumentBatchSave
  19 + post /chat/document/batch_save (ChatDocumentBatchSaveRequest) returns (ChatDocumentBatchSaveResponse)
  20 + @doc "文档-删除"
  21 + @handler chatDocumentDelete
  22 + delete /chat/document/:id (ChatDocumentDeleteRequest) returns (ChatDocumentDeleteResponse)
  23 + @doc "文档-删除"
  24 + @handler chatDocumentRename
  25 + post /chat/document/rename (ChatDocumentRenameRequest) returns (ChatDocumentRenameResponse)
  26 +// @doc "文档-更新"
  27 +// @handler chatDocumentUpdate
  28 +// put /chat/document/:id (ChatDocumentUpdateRequest) returns (ChatDocumentUpdateResponse)
  29 + @doc "文档-搜索"
  30 + @handler chatDocumentSearch
  31 + post /chat/document/search (ChatDocumentSearchRequest) returns (ChatDocumentSearchResponse)
  32 +}
  33 +
  34 +type (
  35 + ChatDocumentGetRequest {
  36 + Id int64 `path:"id"`
  37 + }
  38 + ChatDocumentGetResponse {
  39 + ChatDocument ChatDocumentItem `json:"document"`
  40 + }
  41 +
  42 + ChatDocumentSaveRequest {
  43 + FileName string `json:"fileName"`
  44 + Url string `json:"url"`
  45 + Size float64 `json:"size"` // 文件大小(KB)
  46 + }
  47 + ChatDocumentSaveResponse {
  48 + ChatDocument ChatDocumentItem `json:"document"`
  49 + }
  50 +
  51 + ChatDocumentDeleteRequest {
  52 + Id int64 `path:"id"`
  53 + }
  54 + ChatDocumentDeleteResponse {}
  55 +
  56 + ChatDocumentUpdateRequest {
  57 + Id int64 `path:"id"`
  58 + ChatDocument ChatDocumentItem `json:"document"`
  59 + }
  60 + ChatDocumentUpdateResponse {}
  61 +
  62 + ChatDocumentSearchRequest {
  63 + Page int `json:"page,optional"`
  64 + Size int `json:"size,optional"`
  65 + Name string `json:"name,optional"` // 文件名匹配
  66 + FileType string `json:"fileType,optional"` // 文件类型 markdown\pdf\txt\doc&docx
  67 + Status int `json:"status,optional"` // 文件状态 1.使用中、0.待处理、2.预处理中、3.处理失败
  68 + }
  69 + ChatDocumentSearchResponse{
  70 + List []ChatDocumentItem `json:"list"`
  71 + Total int64 `json:"total"`
  72 + }
  73 + ChatDocumentItem {
  74 + Id int64 `json:"id"`
  75 + Name string `json:"name,optional"` // 文件名
  76 + FileType string `json:"fileType"` // 文件类型 markdown\pdf\txt\doc&docx
  77 + Status int `json:"status"` // 1.使用中、0.待处理、2.预处理中、3.处理失败
  78 + OriginFileName string `json:"originFileName,omitempty"` // 源文件命
  79 + Ext string `json:"ext,omitempty"` // 格式
  80 + FileId string `json:"fileId,omitempty"` // 星火文件ID
  81 + FileUrl string `json:"fileUrl,omitempty"` // 文件地址
  82 + FileSize float64 `json:"fileSize,omitempty"` // 文件大小KB
  83 + CreatedAt int64 `json:"createdAt,omitempty"` // 创建时间
  84 + UpdatedAt int64 `json:"updatedAt,omitempty"` // 更新时间
  85 + }
  86 +)
  87 +
  88 +// 文档重命名
  89 +type(
  90 + ChatDocumentRenameRequest{
  91 + Id int64 `json:"id"` // 文档ID
  92 + Name string `json:"name"` // 新名称
  93 + }
  94 + ChatDocumentRenameResponse{
  95 + ChatDocument ChatDocumentItem `json:"document"`
  96 + }
  97 +)
  98 +
  99 +//文档批量添加
  100 +type(
  101 + ChatDocumentBatchSaveRequest {
  102 + Files []DocumentFile `json:"files"`
  103 + }
  104 + ChatDocumentBatchSaveResponse {
  105 + ChatDocument []ChatDocumentItem `json:"documents"`
  106 + }
  107 + DocumentFile{
  108 + FileName string `json:"fileName"`
  109 + Url string `json:"url"`
  110 + Size float64 `json:"size"` // 文件大小(KB)
  111 + }
  112 +)
@@ -20,6 +20,9 @@ service Core { @@ -20,6 +20,9 @@ service Core {
20 @doc "聊天会话-更新" 20 @doc "聊天会话-更新"
21 @handler chatSessionUpdate 21 @handler chatSessionUpdate
22 put /chat/session/:id (ChatSessionUpdateRequest) returns (ChatSessionUpdateResponse) 22 put /chat/session/:id (ChatSessionUpdateRequest) returns (ChatSessionUpdateResponse)
  23 + @doc "聊天会话-重命名"
  24 + @handler chatSessionRename
  25 + post /chat/session/rename (ChatSessionRenameRequest) returns (ChatSessionRenameResponse)
23 @doc "聊天会话-搜索" 26 @doc "聊天会话-搜索"
24 @handler chatSessionSearch 27 @handler chatSessionSearch
25 post /chat/session/search (ChatSessionSearchRequest) returns (ChatSessionSearchResponse) 28 post /chat/session/search (ChatSessionSearchRequest) returns (ChatSessionSearchResponse)
@@ -30,6 +33,20 @@ service Core { @@ -30,6 +33,20 @@ service Core {
30 @handler chatSessionConversationWs 33 @handler chatSessionConversationWs
31 get /chat/session/conversation (ChatSessionConversationRequestWs) returns (ChatSessionConversationResponse) 34 get /chat/session/conversation (ChatSessionConversationRequestWs) returns (ChatSessionConversationResponse)
32 35
  36 + @doc "聊天会话-添加文件"
  37 + @handler chatSessionAddFiles
  38 + post /chat/session/add_files (ChatSessionAddFilesRequest) returns (ChatSessionAddFilesResponse)
  39 + @doc "聊天会话-移除文件"
  40 + @handler chatSessionRemoveFiles
  41 + post /chat/session/remove_files (ChatSessionAddFilesRequest) returns (ChatSessionAddFilesResponse)
  42 +
  43 + @doc "星火聊天会话-我的会话"
  44 + @handler chatMySparkSessions
  45 + post /chat/session/my_spark_sessions (ChatSessionSearchRequest) returns (ChatSessionSearchResponse)
  46 + @doc "星火聊天会话-保存"
  47 + @handler chatSparkSessionSave
  48 + post /chat/spark_session (ChatSessionSaveRequest) returns (ChatSessionSaveResponse)
  49 +
33 @doc "聊天会话-对话记录列表" 50 @doc "聊天会话-对话记录列表"
34 @handler chatSessionRecords 51 @handler chatSessionRecords
35 post /chat/session/records (ChatSessionRecordsRequest) returns (ChatSessionRecordsResponse) 52 post /chat/session/records (ChatSessionRecordsRequest) returns (ChatSessionRecordsResponse)
@@ -39,19 +56,40 @@ service Core { @@ -39,19 +56,40 @@ service Core {
39 get /chat/models (ChatModelsRequest) returns (ChatModelsResponse) 56 get /chat/models (ChatModelsRequest) returns (ChatModelsResponse)
40 } 57 }
41 58
  59 +
  60 +// 数据管理后台接口
  61 +@server(
  62 + prefix: v1
  63 + group: chat
  64 + middleware: LogRequest
  65 + jwt: SystemAuth
  66 +)
  67 +service Core {
  68 + @doc "数据管理-会话搜索"
  69 + @handler chatDataSessionSearch
  70 + post /chat/data/session/search (ChatDataSessionSearchRequest) returns (ChatDataSessionSearchResponse)
  71 + @doc "聊天会话-详情"
  72 + @handler chatDataSessionGet
  73 + get /chat/data/session/:id (ChatSessionGetRequest) returns (ChatSessionGetResponse)
  74 +}
  75 +
42 type ( 76 type (
43 ChatSessionGetRequest { 77 ChatSessionGetRequest {
44 Id int64 `path:"id"` 78 Id int64 `path:"id"`
45 } 79 }
46 ChatSessionGetResponse { 80 ChatSessionGetResponse {
47 - ChatSession ChatSessionItem `json:"session"`  
48 - Records []Record `json:"records"` 81 + ChatSession ChatSessionItem `json:"session"`
  82 + Records []Record `json:"records"`
  83 + Documents []ChatDocumentItem `json:"documents"`
  84 + Dataset *ChatDatasetItem `json:"dataset"`
49 } 85 }
50 86
51 ChatSessionSaveRequest { 87 ChatSessionSaveRequest {
52 ChatSession ChatSessionItem `json:"session"` 88 ChatSession ChatSessionItem `json:"session"`
53 } 89 }
54 - ChatSessionSaveResponse {} 90 + ChatSessionSaveResponse {
  91 + ChatSession ChatSessionItem `json:"session"`
  92 + }
55 93
56 ChatSessionDeleteRequest { 94 ChatSessionDeleteRequest {
57 Id int64 `path:"id"` 95 Id int64 `path:"id"`
@@ -68,6 +106,7 @@ type ( @@ -68,6 +106,7 @@ type (
68 Page int `json:"page,optional"` 106 Page int `json:"page,optional"`
69 Size int `json:"size,optional"` 107 Size int `json:"size,optional"`
70 Title string `json:"title,optional"` // 按标题搜索 108 Title string `json:"title,optional"` // 按标题搜索
  109 + Module int `json:"module,optional"` // 模块 1:openai chat 2:星火文档问答
71 } 110 }
72 ChatSessionSearchResponse{ 111 ChatSessionSearchResponse{
73 List []ChatSessionItem `json:"list"` 112 List []ChatSessionItem `json:"list"`
@@ -78,6 +117,25 @@ type ( @@ -78,6 +117,25 @@ type (
78 Title string `json:"title,optional,omitempty"` // 会话标题 117 Title string `json:"title,optional,omitempty"` // 会话标题
79 Abstract string `json:"abstract,optional,omitempty"` // 摘要 118 Abstract string `json:"abstract,optional,omitempty"` // 摘要
80 CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间 119 CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
  120 +
  121 + Module int `json:"module,optional,omitempty,default=1"` // 1:openai chat 2:星火文档问答
  122 + Type string `json:"type,optional,omitempty,default=chat"` // 类型 chat:普通问答 spark_dataset_chat:星火知识库问答 spark_documents_chat:星火多文档问答
  123 + DatasetId int64 `json:"datasetId,optional,omitempty"` // 知识库
  124 + DocumentIds []int64 `json:"documentIds,optional,omitempty"` // 多文档
  125 + Documents []ChatDocumentItem `json:"documents,optional,omitempty"` // 多文档
  126 + Author *User `json:"author,optional,omitempty"` // 提问人
  127 + TotalRecords int64 `json:"totalRecords,optional,omitempty"` // 记录数
  128 + Model *Model `json:"model,optional,omitempty"` // 模型
  129 + }
  130 +)
  131 +
  132 +type (
  133 + ChatSessionRenameRequest{
  134 + Id int64 `json:"id"` // 模型ID
  135 + Name string `json:"name"` // 模型名称
  136 + }
  137 + ChatSessionRenameResponse{
  138 +
81 } 139 }
82 ) 140 )
83 141
@@ -128,7 +186,7 @@ type( @@ -128,7 +186,7 @@ type(
128 SessionId int64 `form:"sessionId"` // 会话ID 186 SessionId int64 `form:"sessionId"` // 会话ID
129 ModelId int64 `form:"modelId"` // 模型ID 187 ModelId int64 `form:"modelId"` // 模型ID
130 ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document) 188 ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
131 - Text string `form:"text"` // 内容文本 189 + Text string `form:"text,optional"` // 内容文本
132 } 190 }
133 Record{ 191 Record{
134 Id int64 `json:"id"` // 记录ID 192 Id int64 `json:"id"` // 记录ID
@@ -137,7 +195,7 @@ type( @@ -137,7 +195,7 @@ type(
137 ModelId int64 `json:"modelId,omitempty"` // 模型ID 195 ModelId int64 `json:"modelId,omitempty"` // 模型ID
138 AuthorId int64 `json:"authorId,omitempty"` // 作者ID 196 AuthorId int64 `json:"authorId,omitempty"` // 作者ID
139 Author *User `json:"author,omitempty"` // 提问人 197 Author *User `json:"author,omitempty"` // 提问人
140 - Model *Model `json:"model,omitempty"` // 应答人 198 + Model *Model `json:"model,omitempty"` // 模型
141 ContentType string `json:"contentType"` // 内容类型 文本:text (图片:image 文档:document) 199 ContentType string `json:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
142 ProblemText string `json:"problemText"` // 问题文本 200 ProblemText string `json:"problemText"` // 问题文本
143 AnswerText string `json:"answerText"` // 回答文本 201 AnswerText string `json:"answerText"` // 回答文本
@@ -153,4 +211,31 @@ type( @@ -153,4 +211,31 @@ type(
153 Name string `json:"name"` // 名称 211 Name string `json:"name"` // 名称
154 Avatar string `json:"avatar"` // 头像 212 Avatar string `json:"avatar"` // 头像
155 } 213 }
  214 +)
  215 +
  216 +// 会话添加新文档
  217 +type(
  218 + ChatSessionAddFilesRequest{
  219 + Id int64 `json:"id"` // 文档ID
  220 + DocumentIds []int64 `json:"documentIds"` // 文档ID列表
  221 + }
  222 + ChatSessionAddFilesResponse{
  223 +
  224 + }
  225 +)
  226 +
  227 +// 数据管理-会话搜索
  228 +type(
  229 + ChatDataSessionSearchRequest{
  230 + Page int `json:"page,optional"`
  231 + Size int `json:"size,optional"`
  232 + Title string `json:"title,optional"` // 按标题搜索
  233 + UserName string `json:"userName,optional"` // 用户名称
  234 + BeginTime int64 `json:"beginTime,optional"`// 会话创建时间
  235 + EndTime int64 `json:"endTime,optional"` // 会话创建时间
  236 + }
  237 + ChatDataSessionSearchResponse{
  238 + List []ChatSessionItem `json:"list"`
  239 + Total int64 `json:"total"`
  240 + }
156 ) 241 )
@@ -15,6 +15,294 @@ @@ -15,6 +15,294 @@
15 "application/json" 15 "application/json"
16 ], 16 ],
17 "paths": { 17 "paths": {
  18 + "v1/chat/dataset": {
  19 + "post": {
  20 + "summary": "知识库-保存",
  21 + "operationId": "chatDatasetSave",
  22 + "responses": {
  23 + "200": {
  24 + "description": "A successful response.",
  25 + "schema": {
  26 + "$ref": "#/definitions/ChatDatasetSaveResponse"
  27 + }
  28 + }
  29 + },
  30 + "parameters": [
  31 + {
  32 + "name": "body",
  33 + "in": "body",
  34 + "required": true,
  35 + "schema": {
  36 + "$ref": "#/definitions/ChatDatasetSaveRequest"
  37 + }
  38 + }
  39 + ],
  40 + "requestBody": {},
  41 + "tags": [
  42 + "dataset"
  43 + ]
  44 + }
  45 + },
  46 + "v1/chat/dataset/rename": {
  47 + "post": {
  48 + "summary": "知识库-重命名",
  49 + "operationId": "chatDatasetRename",
  50 + "responses": {
  51 + "200": {
  52 + "description": "A successful response.",
  53 + "schema": {
  54 + "$ref": "#/definitions/ChatDatasetUpdateResponse"
  55 + }
  56 + }
  57 + },
  58 + "parameters": [
  59 + {
  60 + "name": "body",
  61 + "in": "body",
  62 + "required": true,
  63 + "schema": {
  64 + "$ref": "#/definitions/ChatDatasetUpdateRequest"
  65 + }
  66 + }
  67 + ],
  68 + "requestBody": {},
  69 + "tags": [
  70 + "dataset"
  71 + ]
  72 + }
  73 + },
  74 + "v1/chat/dataset/search": {
  75 + "post": {
  76 + "summary": "知识库-搜索",
  77 + "operationId": "chatDatasetSearch",
  78 + "responses": {
  79 + "200": {
  80 + "description": "A successful response.",
  81 + "schema": {
  82 + "$ref": "#/definitions/ChatDatasetSearchResponse"
  83 + }
  84 + }
  85 + },
  86 + "parameters": [
  87 + {
  88 + "name": "body",
  89 + "in": "body",
  90 + "required": true,
  91 + "schema": {
  92 + "$ref": "#/definitions/ChatDatasetSearchRequest"
  93 + }
  94 + }
  95 + ],
  96 + "requestBody": {},
  97 + "tags": [
  98 + "dataset"
  99 + ]
  100 + }
  101 + },
  102 + "v1/chat/dataset/{id}": {
  103 + "get": {
  104 + "summary": "知识库-详情",
  105 + "operationId": "chatDatasetGet",
  106 + "responses": {
  107 + "200": {
  108 + "description": "A successful response.",
  109 + "schema": {
  110 + "$ref": "#/definitions/ChatDatasetGetResponse"
  111 + }
  112 + }
  113 + },
  114 + "parameters": [
  115 + {
  116 + "name": "id",
  117 + "in": "path",
  118 + "required": true,
  119 + "type": "string"
  120 + }
  121 + ],
  122 + "requestBody": {},
  123 + "tags": [
  124 + "dataset"
  125 + ]
  126 + },
  127 + "delete": {
  128 + "summary": "知识库-删除",
  129 + "operationId": "chatDatasetDelete",
  130 + "responses": {
  131 + "200": {
  132 + "description": "A successful response.",
  133 + "schema": {
  134 + "$ref": "#/definitions/ChatDatasetDeleteResponse"
  135 + }
  136 + }
  137 + },
  138 + "parameters": [
  139 + {
  140 + "name": "id",
  141 + "in": "path",
  142 + "required": true,
  143 + "type": "string"
  144 + },
  145 + {
  146 + "name": "body",
  147 + "in": "body",
  148 + "required": true,
  149 + "schema": {
  150 + "$ref": "#/definitions/ChatDatasetDeleteRequest"
  151 + }
  152 + }
  153 + ],
  154 + "requestBody": {},
  155 + "tags": [
  156 + "dataset"
  157 + ]
  158 + },
  159 + "put": {
  160 + "summary": "知识库-更新",
  161 + "operationId": "chatDatasetUpdate",
  162 + "responses": {
  163 + "200": {
  164 + "description": "A successful response.",
  165 + "schema": {
  166 + "$ref": "#/definitions/ChatDatasetUpdateResponse"
  167 + }
  168 + }
  169 + },
  170 + "parameters": [
  171 + {
  172 + "name": "id",
  173 + "in": "path",
  174 + "required": true,
  175 + "type": "string"
  176 + },
  177 + {
  178 + "name": "body",
  179 + "in": "body",
  180 + "required": true,
  181 + "schema": {
  182 + "$ref": "#/definitions/ChatDatasetUpdateRequest"
  183 + }
  184 + }
  185 + ],
  186 + "requestBody": {},
  187 + "tags": [
  188 + "dataset"
  189 + ]
  190 + }
  191 + },
  192 + "v1/chat/document": {
  193 + "post": {
  194 + "summary": "文档-保存",
  195 + "operationId": "chatDocumentSave",
  196 + "responses": {
  197 + "200": {
  198 + "description": "A successful response.",
  199 + "schema": {
  200 + "$ref": "#/definitions/ChatDocumentSaveResponse"
  201 + }
  202 + }
  203 + },
  204 + "parameters": [
  205 + {
  206 + "name": "body",
  207 + "in": "body",
  208 + "required": true,
  209 + "schema": {
  210 + "$ref": "#/definitions/ChatDocumentSaveRequest"
  211 + }
  212 + }
  213 + ],
  214 + "requestBody": {},
  215 + "tags": [
  216 + "document"
  217 + ]
  218 + }
  219 + },
  220 + "v1/chat/document/search": {
  221 + "post": {
  222 + "summary": "文档-搜索",
  223 + "operationId": "chatDocumentSearch",
  224 + "responses": {
  225 + "200": {
  226 + "description": "A successful response.",
  227 + "schema": {
  228 + "$ref": "#/definitions/ChatDocumentSearchResponse"
  229 + }
  230 + }
  231 + },
  232 + "parameters": [
  233 + {
  234 + "name": "body",
  235 + "in": "body",
  236 + "required": true,
  237 + "schema": {
  238 + "$ref": "#/definitions/ChatDocumentSearchRequest"
  239 + }
  240 + }
  241 + ],
  242 + "requestBody": {},
  243 + "tags": [
  244 + "document"
  245 + ]
  246 + }
  247 + },
  248 + "v1/chat/document/{id}": {
  249 + "get": {
  250 + "summary": "文档-详情",
  251 + "operationId": "chatDocumentGet",
  252 + "responses": {
  253 + "200": {
  254 + "description": "A successful response.",
  255 + "schema": {
  256 + "$ref": "#/definitions/ChatDocumentGetResponse"
  257 + }
  258 + }
  259 + },
  260 + "parameters": [
  261 + {
  262 + "name": "id",
  263 + "in": "path",
  264 + "required": true,
  265 + "type": "string"
  266 + }
  267 + ],
  268 + "requestBody": {},
  269 + "tags": [
  270 + "document"
  271 + ]
  272 + },
  273 + "delete": {
  274 + "summary": "文档-删除",
  275 + "operationId": "chatDocumentDelete",
  276 + "responses": {
  277 + "200": {
  278 + "description": "A successful response.",
  279 + "schema": {
  280 + "$ref": "#/definitions/ChatDocumentDeleteResponse"
  281 + }
  282 + }
  283 + },
  284 + "parameters": [
  285 + {
  286 + "name": "id",
  287 + "in": "path",
  288 + "required": true,
  289 + "type": "string"
  290 + },
  291 + {
  292 + "name": "body",
  293 + "in": "body",
  294 + "required": true,
  295 + "schema": {
  296 + "$ref": "#/definitions/ChatDocumentDeleteRequest"
  297 + }
  298 + }
  299 + ],
  300 + "requestBody": {},
  301 + "tags": [
  302 + "document"
  303 + ]
  304 + }
  305 + },
18 "v1/chat/models": { 306 "v1/chat/models": {
19 "get": { 307 "get": {
20 "summary": "模型列表", 308 "summary": "模型列表",
@@ -64,7 +352,7 @@ @@ -64,7 +352,7 @@
64 "v1/chat/session/conversation": { 352 "v1/chat/session/conversation": {
65 "get": { 353 "get": {
66 "summary": "聊天会话-对话", 354 "summary": "聊天会话-对话",
67 - "operationId": "chatSessionConversation", 355 + "operationId": "chatSessionConversationWs",
68 "responses": { 356 "responses": {
69 "200": { 357 "200": {
70 "description": "A successful response.", 358 "description": "A successful response.",
@@ -103,54 +391,234 @@ @@ -103,54 +391,234 @@
103 "in": "query", 391 "in": "query",
104 "required": true, 392 "required": true,
105 "type": "string" 393 "type": "string"
106 - },  
107 - {  
108 - "name": "fileUrl",  
109 - "description": " 文件地址",  
110 - "in": "query",  
111 - "required": true,  
112 - "type": "string"  
113 } 394 }
114 ], 395 ],
115 "requestBody": {}, 396 "requestBody": {},
116 "tags": [ 397 "tags": [
117 "chat" 398 "chat"
118 ] 399 ]
119 - }  
120 - },  
121 - "v1/chat/session/records": {  
122 - "get": {  
123 - "summary": "聊天会话-对话记录列表",  
124 - "operationId": "chatSessionRecords", 400 + },
  401 + "post": {
  402 + "summary": "聊天会话-对话",
  403 + "operationId": "chatSessionConversation",
125 "responses": { 404 "responses": {
126 "200": { 405 "200": {
127 "description": "A successful response.", 406 "description": "A successful response.",
128 "schema": { 407 "schema": {
129 - "$ref": "#/definitions/ChatSessionRecordsResponse" 408 + "$ref": "#/definitions/ChatSessionConversationResponse"
130 } 409 }
131 } 410 }
132 }, 411 },
133 "parameters": [ 412 "parameters": [
134 { 413 {
135 - "name": "page",  
136 - "in": "query",  
137 - "required": false,  
138 - "type": "integer",  
139 - "format": "int32"  
140 - },  
141 - {  
142 - "name": "size",  
143 - "in": "query",  
144 - "required": false,  
145 - "type": "integer",  
146 - "format": "int32" 414 + "name": "body",
  415 + "in": "body",
  416 + "required": true,
  417 + "schema": {
  418 + "$ref": "#/definitions/ChatSessionConversationRequest"
  419 + }
  420 + }
  421 + ],
  422 + "requestBody": {},
  423 + "tags": [
  424 + "chat"
  425 + ]
  426 + }
  427 + },
  428 + "v1/chat/session/my_spark_sessions": {
  429 + "post": {
  430 + "summary": "星火聊天会话-我的会话",
  431 + "operationId": "chatMySparkSessions",
  432 + "responses": {
  433 + "200": {
  434 + "description": "A successful response.",
  435 + "schema": {
  436 + "$ref": "#/definitions/ChatSessionSearchResponse"
  437 + }
  438 + }
  439 + },
  440 + "parameters": [
  441 + {
  442 + "name": "body",
  443 + "in": "body",
  444 + "required": true,
  445 + "schema": {
  446 + "$ref": "#/definitions/ChatSessionSearchRequest"
  447 + }
  448 + }
  449 + ],
  450 + "requestBody": {},
  451 + "tags": [
  452 + "chat"
  453 + ]
  454 + }
  455 + },
  456 + "v1/chat/session/records": {
  457 + "post": {
  458 + "summary": "聊天会话-对话记录列表",
  459 + "operationId": "chatSessionRecords",
  460 + "responses": {
  461 + "200": {
  462 + "description": "A successful response.",
  463 + "schema": {
  464 + "$ref": "#/definitions/ChatSessionRecordsResponse"
  465 + }
  466 + }
  467 + },
  468 + "parameters": [
  469 + {
  470 + "name": "body",
  471 + "in": "body",
  472 + "required": true,
  473 + "schema": {
  474 + "$ref": "#/definitions/ChatSessionRecordsRequest"
  475 + }
  476 + }
  477 + ],
  478 + "requestBody": {},
  479 + "tags": [
  480 + "chat"
  481 + ]
  482 + }
  483 + },
  484 + "v1/chat/session/search": {
  485 + "post": {
  486 + "summary": "聊天会话-搜索",
  487 + "operationId": "chatSessionSearch",
  488 + "responses": {
  489 + "200": {
  490 + "description": "A successful response.",
  491 + "schema": {
  492 + "$ref": "#/definitions/ChatSessionSearchResponse"
  493 + }
  494 + }
  495 + },
  496 + "parameters": [
  497 + {
  498 + "name": "body",
  499 + "in": "body",
  500 + "required": true,
  501 + "schema": {
  502 + "$ref": "#/definitions/ChatSessionSearchRequest"
  503 + }
  504 + }
  505 + ],
  506 + "requestBody": {},
  507 + "tags": [
  508 + "chat"
  509 + ]
  510 + }
  511 + },
  512 + "v1/chat/session/{id}": {
  513 + "get": {
  514 + "summary": "聊天会话-详情",
  515 + "operationId": "chatSessionGet",
  516 + "responses": {
  517 + "200": {
  518 + "description": "A successful response.",
  519 + "schema": {
  520 + "$ref": "#/definitions/ChatSessionGetResponse"
  521 + }
  522 + }
  523 + },
  524 + "parameters": [
  525 + {
  526 + "name": "id",
  527 + "in": "path",
  528 + "required": true,
  529 + "type": "string"
  530 + }
  531 + ],
  532 + "requestBody": {},
  533 + "tags": [
  534 + "chat"
  535 + ]
  536 + },
  537 + "delete": {
  538 + "summary": "聊天会话-删除",
  539 + "operationId": "chatSessionDelete",
  540 + "responses": {
  541 + "200": {
  542 + "description": "A successful response.",
  543 + "schema": {
  544 + "$ref": "#/definitions/ChatSessionDeleteResponse"
  545 + }
  546 + }
  547 + },
  548 + "parameters": [
  549 + {
  550 + "name": "id",
  551 + "in": "path",
  552 + "required": true,
  553 + "type": "string"
147 }, 554 },
148 { 555 {
149 - "name": "sessionId",  
150 - "in": "query", 556 + "name": "body",
  557 + "in": "body",
151 "required": true, 558 "required": true,
152 - "type": "integer",  
153 - "format": "int64" 559 + "schema": {
  560 + "$ref": "#/definitions/ChatSessionDeleteRequest"
  561 + }
  562 + }
  563 + ],
  564 + "requestBody": {},
  565 + "tags": [
  566 + "chat"
  567 + ]
  568 + },
  569 + "put": {
  570 + "summary": "聊天会话-更新",
  571 + "operationId": "chatSessionUpdate",
  572 + "responses": {
  573 + "200": {
  574 + "description": "A successful response.",
  575 + "schema": {
  576 + "$ref": "#/definitions/ChatSessionUpdateResponse"
  577 + }
  578 + }
  579 + },
  580 + "parameters": [
  581 + {
  582 + "name": "id",
  583 + "in": "path",
  584 + "required": true,
  585 + "type": "string"
  586 + },
  587 + {
  588 + "name": "body",
  589 + "in": "body",
  590 + "required": true,
  591 + "schema": {
  592 + "$ref": "#/definitions/ChatSessionUpdateRequest"
  593 + }
  594 + }
  595 + ],
  596 + "requestBody": {},
  597 + "tags": [
  598 + "chat"
  599 + ]
  600 + }
  601 + },
  602 + "v1/chat/spark_session": {
  603 + "post": {
  604 + "summary": "星火聊天会话-保存",
  605 + "operationId": "chatSparkSessionSave",
  606 + "responses": {
  607 + "200": {
  608 + "description": "A successful response.",
  609 + "schema": {
  610 + "$ref": "#/definitions/ChatSessionSaveResponse"
  611 + }
  612 + }
  613 + },
  614 + "parameters": [
  615 + {
  616 + "name": "body",
  617 + "in": "body",
  618 + "required": true,
  619 + "schema": {
  620 + "$ref": "#/definitions/ChatSessionSaveRequest"
  621 + }
154 } 622 }
155 ], 623 ],
156 "requestBody": {}, 624 "requestBody": {},
@@ -158,127 +626,414 @@ @@ -158,127 +626,414 @@
158 "chat" 626 "chat"
159 ] 627 ]
160 } 628 }
  629 + }
  630 + },
  631 + "definitions": {
  632 + "ChatDatasetDeleteRequest": {
  633 + "type": "object",
  634 + "properties": {
  635 + "id": {
  636 + "type": "integer",
  637 + "format": "int64"
  638 + }
  639 + },
  640 + "title": "ChatDatasetDeleteRequest",
  641 + "required": [
  642 + "id"
  643 + ]
  644 + },
  645 + "ChatDatasetDeleteResponse": {
  646 + "type": "object",
  647 + "title": "ChatDatasetDeleteResponse"
  648 + },
  649 + "ChatDatasetGetRequest": {
  650 + "type": "object",
  651 + "properties": {
  652 + "id": {
  653 + "type": "integer",
  654 + "format": "int64"
  655 + }
  656 + },
  657 + "title": "ChatDatasetGetRequest",
  658 + "required": [
  659 + "id"
  660 + ]
  661 + },
  662 + "ChatDatasetGetResponse": {
  663 + "type": "object",
  664 + "properties": {
  665 + "dataset": {
  666 + "$ref": "#/definitions/ChatDatasetItem"
  667 + },
  668 + "documents": {
  669 + "type": "array",
  670 + "items": {
  671 + "$ref": "#/definitions/ChatDocumentItem"
  672 + }
  673 + }
  674 + },
  675 + "title": "ChatDatasetGetResponse",
  676 + "required": [
  677 + "dataset",
  678 + "documents"
  679 + ]
  680 + },
  681 + "ChatDatasetItem": {
  682 + "type": "object",
  683 + "properties": {
  684 + "id": {
  685 + "type": "integer",
  686 + "format": "int64"
  687 + },
  688 + "name": {
  689 + "$ref": "#/definitions/string",
  690 + "description": " 名称"
  691 + },
  692 + "desc": {
  693 + "$ref": "#/definitions/string",
  694 + "description": " 描述"
  695 + },
  696 + "status": {
  697 + "$ref": "#/definitions/int",
  698 + "description": " 状态 1:启用 2:禁用"
  699 + },
  700 + "createdAt": {
  701 + "type": "integer",
  702 + "format": "int64",
  703 + "description": " 创建时间"
  704 + },
  705 + "updatedAt": {
  706 + "type": "integer",
  707 + "format": "int64",
  708 + "description": " 更新时间"
  709 + },
  710 + "fileNumber": {
  711 + "$ref": "#/definitions/int",
  712 + "description": " 文件数量"
  713 + }
  714 + },
  715 + "title": "ChatDatasetItem",
  716 + "required": [
  717 + "id",
  718 + "name",
  719 + "desc",
  720 + "status",
  721 + "createdAt",
  722 + "updatedAt",
  723 + "fileNumber"
  724 + ]
  725 + },
  726 + "ChatDatasetSaveRequest": {
  727 + "type": "object",
  728 + "properties": {
  729 + "name": {
  730 + "type": "string",
  731 + "description": " 名称"
  732 + },
  733 + "documentIds": {
  734 + "type": "array",
  735 + "items": {
  736 + "type": "integer",
  737 + "format": "int64"
  738 + },
  739 + "description": " 文档ID列表"
  740 + }
  741 + },
  742 + "title": "ChatDatasetSaveRequest",
  743 + "required": [
  744 + "name",
  745 + "documentIds"
  746 + ]
  747 + },
  748 + "ChatDatasetSaveResponse": {
  749 + "type": "object",
  750 + "properties": {
  751 + "dataset": {
  752 + "$ref": "#/definitions/ChatDatasetItem"
  753 + }
  754 + },
  755 + "title": "ChatDatasetSaveResponse",
  756 + "required": [
  757 + "dataset"
  758 + ]
  759 + },
  760 + "ChatDatasetSearchRequest": {
  761 + "type": "object",
  762 + "properties": {
  763 + "page": {
  764 + "type": "integer",
  765 + "format": "int32"
  766 + },
  767 + "size": {
  768 + "type": "integer",
  769 + "format": "int32"
  770 + },
  771 + "name": {
  772 + "type": "string",
  773 + "description": " 文件名匹配"
  774 + },
  775 + "name": {
  776 + "type": "integer",
  777 + "format": "int32",
  778 + "description": " 1:启用 2:禁用"
  779 + }
  780 + },
  781 + "title": "ChatDatasetSearchRequest",
  782 + "required": [
  783 + "name"
  784 + ]
  785 + },
  786 + "ChatDatasetSearchResponse": {
  787 + "type": "object",
  788 + "properties": {
  789 + "list": {
  790 + "type": "array",
  791 + "items": {
  792 + "$ref": "#/definitions/ChatDatasetItem"
  793 + }
  794 + },
  795 + "total": {
  796 + "type": "integer",
  797 + "format": "int64"
  798 + }
  799 + },
  800 + "title": "ChatDatasetSearchResponse",
  801 + "required": [
  802 + "list",
  803 + "total"
  804 + ]
  805 + },
  806 + "ChatDatasetUpdateRequest": {
  807 + "type": "object",
  808 + "properties": {
  809 + "id": {
  810 + "type": "integer",
  811 + "format": "int64"
  812 + },
  813 + "dataset": {
  814 + "$ref": "#/definitions/ChatDatasetItem"
  815 + }
  816 + },
  817 + "title": "ChatDatasetUpdateRequest",
  818 + "required": [
  819 + "id",
  820 + "dataset"
  821 + ]
  822 + },
  823 + "ChatDatasetUpdateResponse": {
  824 + "type": "object",
  825 + "title": "ChatDatasetUpdateResponse"
  826 + },
  827 + "ChatDocumentDeleteRequest": {
  828 + "type": "object",
  829 + "properties": {
  830 + "id": {
  831 + "type": "integer",
  832 + "format": "int64"
  833 + }
  834 + },
  835 + "title": "ChatDocumentDeleteRequest",
  836 + "required": [
  837 + "id"
  838 + ]
  839 + },
  840 + "ChatDocumentDeleteResponse": {
  841 + "type": "object",
  842 + "title": "ChatDocumentDeleteResponse"
  843 + },
  844 + "ChatDocumentGetRequest": {
  845 + "type": "object",
  846 + "properties": {
  847 + "id": {
  848 + "type": "integer",
  849 + "format": "int64"
  850 + }
  851 + },
  852 + "title": "ChatDocumentGetRequest",
  853 + "required": [
  854 + "id"
  855 + ]
  856 + },
  857 + "ChatDocumentGetResponse": {
  858 + "type": "object",
  859 + "properties": {
  860 + "document": {
  861 + "$ref": "#/definitions/ChatDocumentItem"
  862 + }
  863 + },
  864 + "title": "ChatDocumentGetResponse",
  865 + "required": [
  866 + "document"
  867 + ]
  868 + },
  869 + "ChatDocumentItem": {
  870 + "type": "object",
  871 + "properties": {
  872 + "id": {
  873 + "type": "integer",
  874 + "format": "int64"
  875 + },
  876 + "name": {
  877 + "type": "string",
  878 + "description": " 文件名"
  879 + },
  880 + "fileType": {
  881 + "type": "string",
  882 + "description": " 文件类型 markdown\\pdf\\txt\\doc\u0026docx"
  883 + },
  884 + "status": {
  885 + "type": "integer",
  886 + "format": "int32",
  887 + "description": " 1.使用中、0.待处理、2.预处理中、3.处理失败"
  888 + },
  889 + "originFileName": {
  890 + "type": "string",
  891 + "description": " 源文件命"
  892 + },
  893 + "ext": {
  894 + "type": "string",
  895 + "description": " 格式"
  896 + },
  897 + "fileId": {
  898 + "type": "string",
  899 + "description": " 星火文件ID"
  900 + },
  901 + "fileUrl": {
  902 + "type": "string",
  903 + "description": " 文件地址"
  904 + },
  905 + "fileSize": {
  906 + "type": "number",
  907 + "format": "double",
  908 + "description": " 文件大小KB"
  909 + },
  910 + "createdAt": {
  911 + "type": "integer",
  912 + "format": "int64",
  913 + "description": " 创建时间"
  914 + },
  915 + "updatedAt": {
  916 + "type": "integer",
  917 + "format": "int64",
  918 + "description": " 更新时间"
  919 + }
  920 + },
  921 + "title": "ChatDocumentItem",
  922 + "required": [
  923 + "id",
  924 + "fileType",
  925 + "status",
  926 + "originFileName",
  927 + "ext",
  928 + "fileId",
  929 + "fileUrl",
  930 + "fileSize",
  931 + "createdAt",
  932 + "updatedAt"
  933 + ]
161 }, 934 },
162 - "v1/chat/session/search": {  
163 - "post": {  
164 - "summary": "聊天会话-搜索",  
165 - "operationId": "chatSessionSearch",  
166 - "responses": {  
167 - "200": {  
168 - "description": "A successful response.",  
169 - "schema": {  
170 - "$ref": "#/definitions/ChatSessionSearchResponse"  
171 - }  
172 - } 935 + "ChatDocumentSaveRequest": {
  936 + "type": "object",
  937 + "properties": {
  938 + "fileName": {
  939 + "type": "string"
173 }, 940 },
174 - "parameters": [  
175 - {  
176 - "name": "body",  
177 - "in": "body",  
178 - "required": true,  
179 - "schema": {  
180 - "$ref": "#/definitions/ChatSessionSearchRequest"  
181 - }  
182 - }  
183 - ],  
184 - "requestBody": {},  
185 - "tags": [  
186 - "chat"  
187 - ]  
188 - } 941 + "url": {
  942 + "type": "string"
  943 + },
  944 + "size": {
  945 + "type": "number",
  946 + "format": "double",
  947 + "description": " 文件大小(KB)"
  948 + }
  949 + },
  950 + "title": "ChatDocumentSaveRequest",
  951 + "required": [
  952 + "fileName",
  953 + "url",
  954 + "size"
  955 + ]
189 }, 956 },
190 - "v1/chat/session/{id}": {  
191 - "get": {  
192 - "summary": "聊天会话-详情",  
193 - "operationId": "chatSessionGet",  
194 - "responses": {  
195 - "200": {  
196 - "description": "A successful response.",  
197 - "schema": {  
198 - "$ref": "#/definitions/ChatSessionGetResponse"  
199 - }  
200 - } 957 + "ChatDocumentSaveResponse": {
  958 + "type": "object",
  959 + "properties": {
  960 + "document": {
  961 + "$ref": "#/definitions/ChatDocumentItem"
  962 + }
  963 + },
  964 + "title": "ChatDocumentSaveResponse",
  965 + "required": [
  966 + "document"
  967 + ]
  968 + },
  969 + "ChatDocumentSearchRequest": {
  970 + "type": "object",
  971 + "properties": {
  972 + "page": {
  973 + "type": "integer",
  974 + "format": "int32"
201 }, 975 },
202 - "parameters": [  
203 - {  
204 - "name": "id",  
205 - "in": "path",  
206 - "required": true,  
207 - "type": "string"  
208 - }  
209 - ],  
210 - "requestBody": {},  
211 - "tags": [  
212 - "chat"  
213 - ] 976 + "size": {
  977 + "type": "integer",
  978 + "format": "int32"
  979 + },
  980 + "name": {
  981 + "type": "string",
  982 + "description": " 文件名匹配"
  983 + },
  984 + "fileType": {
  985 + "type": "string",
  986 + "description": " 文件类型 markdown\\pdf\\txt\\doc\u0026docx"
  987 + },
  988 + "status": {
  989 + "type": "integer",
  990 + "format": "int32",
  991 + "description": " 文件状态 1.使用中、0.待处理、2.预处理中、3.处理失败"
  992 + }
214 }, 993 },
215 - "delete": {  
216 - "summary": "聊天会话-删除",  
217 - "operationId": "chatSessionDelete",  
218 - "responses": {  
219 - "200": {  
220 - "description": "A successful response.",  
221 - "schema": {  
222 - "$ref": "#/definitions/ChatSessionDeleteResponse"  
223 - } 994 + "title": "ChatDocumentSearchRequest"
  995 + },
  996 + "ChatDocumentSearchResponse": {
  997 + "type": "object",
  998 + "properties": {
  999 + "list": {
  1000 + "type": "array",
  1001 + "items": {
  1002 + "$ref": "#/definitions/ChatDocumentItem"
224 } 1003 }
225 }, 1004 },
226 - "parameters": [  
227 - {  
228 - "name": "id",  
229 - "in": "path",  
230 - "required": true,  
231 - "type": "string"  
232 - },  
233 - {  
234 - "name": "body",  
235 - "in": "body",  
236 - "required": true,  
237 - "schema": {  
238 - "$ref": "#/definitions/ChatSessionDeleteRequest"  
239 - }  
240 - }  
241 - ],  
242 - "requestBody": {},  
243 - "tags": [  
244 - "chat"  
245 - ] 1005 + "total": {
  1006 + "type": "integer",
  1007 + "format": "int64"
  1008 + }
246 }, 1009 },
247 - "put": {  
248 - "summary": "聊天会话-更新",  
249 - "operationId": "chatSessionUpdate",  
250 - "responses": {  
251 - "200": {  
252 - "description": "A successful response.",  
253 - "schema": {  
254 - "$ref": "#/definitions/ChatSessionUpdateResponse"  
255 - }  
256 - } 1010 + "title": "ChatDocumentSearchResponse",
  1011 + "required": [
  1012 + "list",
  1013 + "total"
  1014 + ]
  1015 + },
  1016 + "ChatDocumentUpdateRequest": {
  1017 + "type": "object",
  1018 + "properties": {
  1019 + "id": {
  1020 + "type": "integer",
  1021 + "format": "int64"
257 }, 1022 },
258 - "parameters": [  
259 - {  
260 - "name": "id",  
261 - "in": "path",  
262 - "required": true,  
263 - "type": "string"  
264 - },  
265 - {  
266 - "name": "body",  
267 - "in": "body",  
268 - "required": true,  
269 - "schema": {  
270 - "$ref": "#/definitions/ChatSessionUpdateRequest"  
271 - }  
272 - }  
273 - ],  
274 - "requestBody": {},  
275 - "tags": [  
276 - "chat"  
277 - ]  
278 - }  
279 - }  
280 - },  
281 - "definitions": { 1023 + "document": {
  1024 + "$ref": "#/definitions/ChatDocumentItem"
  1025 + }
  1026 + },
  1027 + "title": "ChatDocumentUpdateRequest",
  1028 + "required": [
  1029 + "id",
  1030 + "document"
  1031 + ]
  1032 + },
  1033 + "ChatDocumentUpdateResponse": {
  1034 + "type": "object",
  1035 + "title": "ChatDocumentUpdateResponse"
  1036 + },
282 "ChatModelsRequest": { 1037 "ChatModelsRequest": {
283 "type": "object", 1038 "type": "object",
284 "title": "ChatModelsRequest" 1039 "title": "ChatModelsRequest"
@@ -329,13 +1084,62 @@ @@ -329,13 +1084,62 @@
329 "sessionId", 1084 "sessionId",
330 "modelId", 1085 "modelId",
331 "contentType", 1086 "contentType",
332 - "text",  
333 - "fileUrl" 1087 + "text"
  1088 + ]
  1089 + },
  1090 + "ChatSessionConversationRequestWs": {
  1091 + "type": "object",
  1092 + "properties": {
  1093 + "sessionId": {
  1094 + "type": "integer",
  1095 + "format": "int64",
  1096 + "description": " 会话ID"
  1097 + },
  1098 + "modelId": {
  1099 + "type": "integer",
  1100 + "format": "int64",
  1101 + "description": " 模型ID"
  1102 + },
  1103 + "contentType": {
  1104 + "type": "string",
  1105 + "description": " 内容类型 文本:text (图片:image 文档:document)"
  1106 + },
  1107 + "text": {
  1108 + "type": "string",
  1109 + "description": " 内容文本"
  1110 + }
  1111 + },
  1112 + "title": "ChatSessionConversationRequestWs",
  1113 + "required": [
  1114 + "sessionId",
  1115 + "modelId",
  1116 + "contentType",
  1117 + "text"
334 ] 1118 ]
335 }, 1119 },
336 "ChatSessionConversationResponse": { 1120 "ChatSessionConversationResponse": {
337 "type": "object", 1121 "type": "object",
338 - "title": "ChatSessionConversationResponse" 1122 + "properties": {
  1123 + "record": {
  1124 + "$ref": "#/definitions/Record"
  1125 + },
  1126 + "parts": {
  1127 + "type": "array",
  1128 + "items": {
  1129 + "type": "string"
  1130 + }
  1131 + },
  1132 + "finished": {
  1133 + "type": "boolean",
  1134 + "format": "boolean"
  1135 + }
  1136 + },
  1137 + "title": "ChatSessionConversationResponse",
  1138 + "required": [
  1139 + "record",
  1140 + "parts",
  1141 + "finished"
  1142 + ]
339 }, 1143 },
340 "ChatSessionDeleteRequest": { 1144 "ChatSessionDeleteRequest": {
341 "type": "object", 1145 "type": "object",
@@ -406,6 +1210,30 @@ @@ -406,6 +1210,30 @@
406 "type": "integer", 1210 "type": "integer",
407 "format": "int64", 1211 "format": "int64",
408 "description": " 创建时间" 1212 "description": " 创建时间"
  1213 + },
  1214 + "module": {
  1215 + "type": "integer",
  1216 + "format": "int32",
  1217 + "default": "1",
  1218 + "description": " 1:openai chat 2:星火文档问答"
  1219 + },
  1220 + "type": {
  1221 + "type": "string",
  1222 + "default": "chat",
  1223 + "description": " 类型 chat:普通问答 spark_dataset_chat:星火知识库问答 spark_documents_chat:星火多文档问答"
  1224 + },
  1225 + "datasetId": {
  1226 + "type": "integer",
  1227 + "format": "int64",
  1228 + "description": " 知识库"
  1229 + },
  1230 + "documentIds": {
  1231 + "type": "array",
  1232 + "items": {
  1233 + "type": "integer",
  1234 + "format": "int64"
  1235 + },
  1236 + "description": " 多文档"
409 } 1237 }
410 }, 1238 },
411 "title": "ChatSessionItem", 1239 "title": "ChatSessionItem",
@@ -413,7 +1241,11 @@ @@ -413,7 +1241,11 @@
413 "id", 1241 "id",
414 "title", 1242 "title",
415 "abstract", 1243 "abstract",
416 - "createdAt" 1244 + "createdAt",
  1245 + "module",
  1246 + "type",
  1247 + "datasetId",
  1248 + "documentIds"
417 ] 1249 ]
418 }, 1250 },
419 "ChatSessionRecordsRequest": { 1251 "ChatSessionRecordsRequest": {
@@ -471,7 +1303,15 @@ @@ -471,7 +1303,15 @@
471 }, 1303 },
472 "ChatSessionSaveResponse": { 1304 "ChatSessionSaveResponse": {
473 "type": "object", 1305 "type": "object",
474 - "title": "ChatSessionSaveResponse" 1306 + "properties": {
  1307 + "session": {
  1308 + "$ref": "#/definitions/ChatSessionItem"
  1309 + }
  1310 + },
  1311 + "title": "ChatSessionSaveResponse",
  1312 + "required": [
  1313 + "session"
  1314 + ]
475 }, 1315 },
476 "ChatSessionSearchRequest": { 1316 "ChatSessionSearchRequest": {
477 "type": "object", 1317 "type": "object",
@@ -487,6 +1327,11 @@ @@ -487,6 +1327,11 @@
487 "title": { 1327 "title": {
488 "type": "string", 1328 "type": "string",
489 "description": " 按标题搜索" 1329 "description": " 按标题搜索"
  1330 + },
  1331 + "module": {
  1332 + "type": "integer",
  1333 + "format": "int32",
  1334 + "description": " 模块 1:openai chat 2:星火文档问答"
490 } 1335 }
491 }, 1336 },
492 "title": "ChatSessionSearchRequest" 1337 "title": "ChatSessionSearchRequest"
  1 +
  2 +syntax = "v1"
  3 +
  4 +info(
  5 + title: "xx实例"
  6 + desc: "xx实例"
  7 + author: "author"
  8 + email: "email"
  9 + version: "v1"
  10 +)
  11 +
  12 +@server(
  13 + prefix: v1
  14 + group: chat_dataset
  15 + jwt: JwtAuth
  16 +)
  17 +service Core {
  18 + @doc "详情"
  19 + @handler chat_datasetGet
  20 + get /chat_dataset/:id (ChatDatasetGetRequest) returns (ChatDatasetGetResponse)
  21 + @doc "保存"
  22 + @handler chat_datasetSave
  23 + post /chat_dataset (ChatDatasetSaveRequest) returns (ChatDatasetSaveResponse)
  24 + @doc "删除"
  25 + @handler chat_datasetDelete
  26 + delete /chat_dataset/:id (ChatDatasetDeleteRequest) returns (ChatDatasetDeleteResponse)
  27 + @doc "更新"
  28 + @handler chat_datasetUpdate
  29 + put /chat_dataset/:id (ChatDatasetUpdateRequest) returns (ChatDatasetUpdateResponse)
  30 + @doc "搜索"
  31 + @handler chat_datasetSearch
  32 + post /chat_dataset/search (ChatDatasetSearchRequest) returns (ChatDatasetSearchResponse)
  33 +}
  34 +
  35 +type (
  36 + ChatDatasetGetRequest {
  37 + Id int64 `path:"id"`
  38 + }
  39 + ChatDatasetGetResponse {
  40 + ChatDataset ChatDatasetItem `json:"chat_dataset"`
  41 + }
  42 +
  43 + ChatDatasetSaveRequest {
  44 + ChatDataset ChatDatasetItem `json:"chat_dataset"`
  45 + }
  46 + ChatDatasetSaveResponse {}
  47 +
  48 + ChatDatasetDeleteRequest {
  49 + Id int64 `path:"id"`
  50 + }
  51 + ChatDatasetDeleteResponse {}
  52 +
  53 + ChatDatasetUpdateRequest {
  54 + Id int64 `path:"id"`
  55 + ChatDataset ChatDatasetItem `json:"chat_dataset"`
  56 + }
  57 + ChatDatasetUpdateResponse {}
  58 +
  59 + ChatDatasetSearchRequest {
  60 + Page int `json:"page"`
  61 + Size int `json:"size"`
  62 + }
  63 + ChatDatasetSearchResponse{
  64 + List []ChatDatasetItem `json:"list"`
  65 + Total int64 `json:"total"`
  66 + }
  67 + ChatDatasetItem {
  68 +
  69 + }
  70 +)
  71 +
  72 +// logic CRUD
  73 +// Save
  74 + //var (
  75 + // conn = l.svcCtx.DefaultDBConn()
  76 + // dm *domain.ChatDataset
  77 + //)
  78 + //// 唯一判断
  79 +
  80 + //dm = NewDomainChatDataset(req.ChatDataset)
  81 + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  82 + // dm, err = l.svcCtx.ChatDatasetRepository.Insert(l.ctx, conn, dm)
  83 + // return err
  84 + //}, true); err != nil {
  85 + // return nil, xerr.NewErrMsg("保存失败")
  86 + //}
  87 + ////resp = &types.ChatDatasetSaveResponse{}
  88 + //return
  89 +
  90 +//func NewDomainChatDataset(item types.ChatDatasetItem) *domain.ChatDataset {
  91 +// return &domain.ChatDataset{
  92 +
  93 +// }
  94 +//}
  95 +//
  96 +//func NewTypesChatDataset(item *domain.ChatDataset) types.ChatDatasetItem {
  97 +// return types.ChatDatasetItem{
  98 +// Id: item.Id,
  99 +// }
  100 +//}
  101 +
  102 +// Get
  103 + //var (
  104 + // conn = l.svcCtx.DefaultDBConn()
  105 + // dm *domain.ChatDataset
  106 + //)
  107 + //// 货号唯一
  108 + //if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  109 + // return nil, xerr.NewErrMsgErr("不存在", err)
  110 + //}
  111 + //resp = &types.ChatDatasetGetResponse{
  112 + // ChatDataset: NewTypesChatDataset(dm),
  113 + //}
  114 + //return
  115 +
  116 +// Delete
  117 + //var (
  118 + // conn = l.svcCtx.DefaultDBConn()
  119 + // dm *domain.ChatDataset
  120 + //)
  121 + //if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  122 + // return nil, xerr.NewErrMsgErr("不存在", err)
  123 + //}
  124 + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  125 + // if dm, err = l.svcCtx.ChatDatasetRepository.Delete(l.ctx, conn, dm); err != nil {
  126 + // return err
  127 + // }
  128 + // return nil
  129 + //}, true); err != nil {
  130 + // return nil, xerr.NewErrMsgErr("移除失败", err)
  131 + //}
  132 + //return
  133 +
  134 +// Search
  135 + //var (
  136 + // conn = l.svcCtx.DefaultDBConn()
  137 + // dms []*domain.ChatDataset
  138 + // total int64
  139 + //)
  140 + //
  141 + //queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
  142 + // WithKV("", "")
  143 +
  144 + //total, dms, err = l.svcCtx.ChatDatasetRepository.Find(l.ctx, conn, queryOptions)
  145 + //list := make([]types.ChatDatasetItem, 0)
  146 + //for i := range dms {
  147 + // list = append(list, NewTypesChatDataset(dms[i]))
  148 + //}
  149 + //resp = &types.ChatDatasetSearchResponse{
  150 + // List: list,
  151 + // Total: total,
  152 + //}
  153 + //return
  154 +
  155 +// Update
  156 + //var (
  157 + // conn = l.svcCtx.DefaultDBConn()
  158 + // dm *domain.ChatDataset
  159 + //)
  160 + //if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
  161 + // return nil, xerr.NewErrMsgErr("不存在", err)
  162 + //}
  163 + //// 不可编辑判断
  164 +
  165 + //// 赋值
  166 +
  167 + //// 更新
  168 + //if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
  169 + // dm, err = l.svcCtx.ChatDatasetRepository.UpdateWithVersion(l.ctx, conn, dm)
  170 + // return err
  171 + //}, true); err != nil {
  172 + // return nil, xerr.NewErrMsg("更新失败")
  173 + //}
  174 + //resp = &types.ChatDatasetUpdateResponse{}
  175 + //return