作者 yangfu

feat-1.0 chat doc

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

要显示太多修改。

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

... ... @@ -8,7 +8,7 @@ Timeout: 30000
LogRequest: true # 记录详细请求日志
Log:
Mode: file
#Mode: file
Encoding: plain
Level: debug # info
MaxSize: 1 # 2MB
... ... @@ -25,5 +25,5 @@ Redis:
Type: node
Pass:
DB:
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform port=31543 sslmode=disable TimeZone=Asia/Shanghai
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform_preonline port=31543 sslmode=disable TimeZone=Asia/Shanghai
... ...
package chat
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDataSessionGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatSessionGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewChatDataSessionGetLogic(r.Context(), svcCtx)
resp, err := l.ChatDataSessionGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package chat
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDataSessionSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDataSessionSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewChatDataSessionSearchLogic(r.Context(), svcCtx)
resp, err := l.ChatDataSessionSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package chat
import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatMySparkSessionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatSessionSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewChatSessionSearchLogic(r.Context(), svcCtx)
req.Module = domain.ModuleSparkChat
resp, err := l.ChatSessionSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package chat
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatSessionAddFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatSessionAddFilesRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewChatSessionAddFilesLogic(r.Context(), svcCtx)
resp, err := l.ChatSessionAddFiles(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package chat
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatSessionRemoveFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatSessionAddFilesRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewChatSessionRemoveFilesLogic(r.Context(), svcCtx)
resp, err := l.ChatSessionRemoveFiles(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package chat
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatSessionRenameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatSessionRenameRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewChatSessionRenameLogic(r.Context(), svcCtx)
resp, err := l.ChatSessionRename(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package chat
import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -18,6 +19,8 @@ func ChatSessionSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := chat.NewChatSessionSaveLogic(r.Context(), svcCtx)
req.ChatSession.Module = domain.ModuleOpenaiChat
req.ChatSession.Type = domain.TypeChat
resp, err := l.ChatSessionSave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
... ...
package chat
import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -18,6 +19,7 @@ func ChatSessionSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := chat.NewChatSessionSearchLogic(r.Context(), svcCtx)
req.Module = domain.ModuleOpenaiChat
resp, err := l.ChatSessionSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
... ...
package chat
import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/chat"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatSparkSessionSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatSessionSaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chat.NewChatSessionSaveLogic(r.Context(), svcCtx)
req.ChatSession.Module = domain.ModuleSparkChat
if req.ChatSession.DatasetId > 0 {
req.ChatSession.Type = domain.TypeSparkDatasetChat
} else if len(req.ChatSession.DocumentIds) > 0 {
req.ChatSession.Type = domain.TypeSparkDocumentsChat
} else {
httpx.ErrorCtx(r.Context(), w, xerr.NewErrMsgErr("知识库、文档至少选一个", nil))
return
}
resp, err := l.ChatSessionSave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetAddFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetAddFilesRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetAddFilesLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetAddFiles(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetDeleteLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetDelete(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetGetLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetRemvoeFilesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetAddFilesRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetRemvoeFilesLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetRemvoeFiles(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetRenameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetRenameRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetRenameLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetRename(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetSaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetSaveLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetSave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetSearchLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package dataset
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/dataset"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDatasetUpdateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDatasetUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := dataset.NewChatDatasetUpdateLogic(r.Context(), svcCtx)
resp, err := l.ChatDatasetUpdate(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package document
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDocumentBatchSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDocumentBatchSaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := document.NewChatDocumentBatchSaveLogic(r.Context(), svcCtx)
resp, err := l.ChatDocumentBatchSave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package document
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDocumentDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDocumentDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := document.NewChatDocumentDeleteLogic(r.Context(), svcCtx)
resp, err := l.ChatDocumentDelete(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package document
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDocumentGetHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDocumentGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := document.NewChatDocumentGetLogic(r.Context(), svcCtx)
resp, err := l.ChatDocumentGet(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package document
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDocumentRenameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDocumentRenameRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := document.NewChatDocumentRenameLogic(r.Context(), svcCtx)
resp, err := l.ChatDocumentRename(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package document
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDocumentSaveHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDocumentSaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := document.NewChatDocumentSaveLogic(r.Context(), svcCtx)
resp, err := l.ChatDocumentSave(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package document
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/document"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
)
func ChatDocumentSearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChatDocumentSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := document.NewChatDocumentSearchLogic(r.Context(), svcCtx)
resp, err := l.ChatDocumentSearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
... ... @@ -5,6 +5,8 @@ import (
"net/http"
chat "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/handler/chat"
dataset "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/handler/dataset"
document "gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/handler/document"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
... ... @@ -37,6 +39,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/chat/session/rename",
Handler: chat.ChatSessionRenameHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/session/search",
Handler: chat.ChatSessionSearchHandler(serverCtx),
},
... ... @@ -52,6 +59,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/chat/session/add_files",
Handler: chat.ChatSessionAddFilesHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/session/remove_files",
Handler: chat.ChatSessionRemoveFilesHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/session/my_spark_sessions",
Handler: chat.ChatMySparkSessionsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/spark_session",
Handler: chat.ChatSparkSessionSaveHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/session/records",
Handler: chat.ChatSessionRecordsHandler(serverCtx),
},
... ... @@ -65,4 +92,114 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/chat/data/session/search",
Handler: chat.ChatDataSessionSearchHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/chat/data/session/:id",
Handler: chat.ChatDataSessionGetHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/chat/document/:id",
Handler: document.ChatDocumentGetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/document",
Handler: document.ChatDocumentSaveHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/document/batch_save",
Handler: document.ChatDocumentBatchSaveHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/chat/document/:id",
Handler: document.ChatDocumentDeleteHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/document/rename",
Handler: document.ChatDocumentRenameHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/document/search",
Handler: document.ChatDocumentSearchHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
Path: "/chat/dataset/:id",
Handler: dataset.ChatDatasetGetHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/dataset",
Handler: dataset.ChatDatasetSaveHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/chat/dataset/:id",
Handler: dataset.ChatDatasetDeleteHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/chat/dataset/:id",
Handler: dataset.ChatDatasetUpdateHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/dataset/rename",
Handler: dataset.ChatDatasetRenameHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/dataset/search",
Handler: dataset.ChatDatasetSearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/dataset/add_files",
Handler: dataset.ChatDatasetAddFilesHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chat/dataset/remove_files",
Handler: dataset.ChatDatasetRemvoeFilesHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
}
... ...
package chat
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDataSessionGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDataSessionGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDataSessionGetLogic {
return &ChatDataSessionGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDataSessionGetLogic) ChatDataSessionGet(req *types.ChatSessionGetRequest) (resp *types.ChatSessionGetResponse, err error) {
logic := NewChatSessionGetLogic(l.ctx, l.svcCtx)
return logic.ChatSessionGet(req)
}
... ...
package chat
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDataSessionSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDataSessionSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDataSessionSearchLogic {
return &ChatDataSessionSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDataSessionSearchLogic) ChatDataSessionSearch(req *types.ChatDataSessionSearchRequest) (resp *types.ChatDataSessionSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
sessions []*domain.ChatSession
total int64
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().
//WithKV("module", domain.ModuleOpenaiChat).
WithKV("companyId", token.CompanyId).
LikeKV("title", req.Title).
WithKV("beginTime", req.BeginTime).WithKV("endTime", req.EndTime)
if len(req.UserName) > 0 {
users, _ := l.svcCtx.SystemOpen.UserByName(l.ctx, conn, token.CompanyId, req.UserName)
userIds := make([]int64, 0)
for _, user := range users {
userIds = append(userIds, user.Id)
}
if len(userIds) > 0 {
queryOptions.WithKV("inUserIds", userIds)
}
}
if req.Page != 0 && req.Size != 0 {
queryOptions.WithOffsetLimit(req.Page, req.Size)
}
total, sessions, err = l.svcCtx.ChatSessionRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErr(err)
}
// 查询对话数量
sessionIdList := domain.Values(sessions, func(item *domain.ChatSession) int64 {
return item.Id
})
countSessionRecords, _ := l.svcCtx.ChatSessionRecordRepository.CountRecordsBySessions(l.ctx, conn, token.CompanyId, sessionIdList...)
countSessionRecordMap := lo.SliceToMap(countSessionRecords, func(item *domain.CountRecordsBySessionResult) (int64, *domain.CountRecordsBySessionResult) {
return item.SessionId, item
})
list := make([]types.ChatSessionItem, 0)
userLazyLoad := tool.NewLazyLoadService(l.svcCtx.SystemOpen.User)
for i := range sessions {
typesSession := NewTypesChatSession(sessions[i])
user, _ := userLazyLoad.Load(l.ctx, conn, sessions[i].UserId)
typesSession.Author = NewTypesUser(user)
if v, ok := countSessionRecordMap[sessions[i].Id]; ok {
typesSession.TotalRecords = v.Count
typesSession.Model = NewTypesModel(v.ModelId)
}
// 默认模型星火问答
if sessions[i].Module == domain.ModuleSparkChat {
typesSession.Model = NewTypesModel(domain.SparkChatDocModelId)
}
list = append(list, typesSession)
}
resp = &types.ChatDataSessionSearchResponse{
List: list,
Total: total,
}
return
}
... ...
... ... @@ -28,6 +28,9 @@ func NewChatModelsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatMo
func (l *ChatModelsLogic) ChatModels(req *types.ChatModelsRequest) (resp *types.ChatModelsResponse, err error) {
var models = make([]types.Model, 0)
lo.ForEach(domain.DefaultChatModels, func(item *domain.ChatModel, index int) {
if item.Id == domain.SparkChatDocModelId {
return
}
models = append(models, types.Model{
Id: item.Id,
Name: item.Name,
... ...
package chat
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatMySparkSessionsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatMySparkSessionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatMySparkSessionsLogic {
return &ChatMySparkSessionsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatMySparkSessionsLogic) ChatMySparkSessions(req *types.ChatSessionSearchRequest) (resp *types.ChatSessionSearchResponse, err error) {
logic := NewChatSessionSearchLogic(l.ctx, l.svcCtx)
req.Module = domain.ModuleSparkChat
resp, err = logic.ChatSessionSearch(req)
//resp.List =
return
}
... ...
package chat
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatSessionAddFilesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatSessionAddFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSessionAddFilesLogic {
return &ChatSessionAddFilesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatSessionAddFilesLogic) ChatSessionAddFiles(req *types.ChatSessionAddFilesRequest) (resp *types.ChatSessionAddFilesResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatSession
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if dm.UserId != token.UserId {
return nil, xerr.NewErrMsgErr("无权限", err)
}
// 赋值
if dm.Module != domain.ModuleSparkChat {
return nil, xerr.NewErrMsgErr("类型有误,星火文档类型才可以添加文档", err)
}
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// 知识库移除
if dm.Type == domain.TypeSparkDatasetChat {
if err = core.DatasetAddFiles(l.ctx, l.svcCtx, conn, dm.Metadata.DatasetId, req.DocumentIds); err != nil {
return err
}
return nil
}
// 普通多文档移除
dm.Metadata.DocumentIds = lo.Union(dm.Metadata.DocumentIds, req.DocumentIds)
dm, err = l.svcCtx.ChatSessionRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ChatSessionAddFilesResponse{}
return
}
... ...
... ... @@ -2,10 +2,13 @@ package chat
import (
"context"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/fx"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"net/http"
... ... @@ -38,7 +41,6 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
token = contextdata.GetUserTokenFromCtx(l.ctx)
session *domain.ChatSession
user open.User
model *domain.ChatModel
ok bool
beginUnix = time.Now().UnixMilli()
)
... ... @@ -51,8 +53,8 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
if user.Id != session.UserId {
return nil, xerr.NewErrMsgErr("无权限", err)
}
if model, ok = domain.DefaultChatModels.Match(req.ModelId); !ok {
return nil, xerr.NewErrMsgErr("模型不存在", err)
if session.Module == domain.ModuleSparkChat {
req.ModelId = domain.SparkChatDocModelId
}
dm = &domain.ChatSessionRecord{
CompanyId: token.CompanyId,
... ... @@ -69,15 +71,16 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
var answer string
var channel = make(chan string, 5)
// 异步访问AI接口
go func() {
// 异步访问AI接口
answer, err = Conversation(model, req.Text, channel)
}()
fx.Parallel(func() {
answer, err = Conversation(l.ctx, l.svcCtx, session, req.ModelId, req.Text, channel)
}, func() {
for {
if _, ok = <-channel; !ok {
break
}
logx.Info(1)
}
})
if err != nil {
return nil, xerr.NewErrMsgErr("AI模型异常,稍后再试", err)
}
... ... @@ -101,17 +104,63 @@ func (l *ChatSessionConversationLogic) ChatSessionConversation(w http.ResponseWr
return
}
func Conversation(m *domain.ChatModel, text string, channel chan string) (answer string, err error) {
// Conversation 普通对话
func Conversation(ctx context.Context, svc *svc.ServiceContext, session *domain.ChatSession, modelId int64, text string, channel chan string) (answer string, err error) {
var (
m *domain.ChatModel
ok bool
)
defer close(channel)
if m, ok = domain.DefaultChatModels.Match(modelId); !ok {
err = xerr.NewErrMsgErr("模型不存在", err)
return
}
if session.Module == domain.ModuleSparkChat {
return SparkDocumentConversation(ctx, svc, session, m, text, channel)
}
switch m.Id {
// 星火3.5
case 1, 2, 3:
answer, err = ai.ChatGPT(m.Code, m.Config.AppKey, text, channel)
case 4:
answer, err = ai.Spark(m.Config.AppId, m.Config.AppKey, m.Config.AppSecret, text, channel)
answer, err = ai.ChatSpark(m.Config.AppId, m.Config.AppKey, m.Config.AppSecret, text, channel)
}
if err != nil {
return "", err
}
return
}
// SparkDocumentConversation 星火文档对话
func SparkDocumentConversation(ctx context.Context, svcCtx *svc.ServiceContext, session *domain.ChatSession, m *domain.ChatModel, text string, channel chan string) (answer string, err error) {
var (
conn = svcCtx.DefaultDBConn()
)
// 获取文件ID列表
fileIds := make([]string, 0)
lazyDocument := tool.NewLazyLoadService(svcCtx.ChatDocumentRepository.FindOne)
if session.Type == domain.TypeSparkDatasetChat { // 知识库
_, documentMapping, _ := svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(ctx, conn, session.Metadata.DatasetId)
lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
if document, _ := lazyDocument.Load(ctx, conn, item.DocumentId); document != nil {
if len(document.Metadata.FileId) == 0 {
return
}
fileIds = append(fileIds, document.Metadata.FileId)
}
})
} else if session.Type == domain.TypeSparkDocumentsChat { // 多文档
lo.ForEach(session.Metadata.DocumentIds, func(item int64, index int) {
if document, _ := lazyDocument.Load(ctx, conn, item); document != nil {
if len(document.Metadata.FileId) == 0 {
return
}
fileIds = append(fileIds, document.Metadata.FileId)
}
})
}
// 对话
c := m.Config
return ai.ChatSparkDocument(c.AppId, c.AppKey, c.AppSecret, fileIds, text, channel)
}
... ...
... ... @@ -40,7 +40,6 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon
token = contextdata.GetUserTokenFromCtx(l.ctx)
session *domain.ChatSession
user open.User
model *domain.ChatModel
ok bool
)
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
if user.Id != session.UserId {
return nil, xerr.NewErrMsgErr("无权限", err)
}
if model, ok = domain.DefaultChatModels.Match(req.ModelId); !ok {
return nil, xerr.NewErrMsgErr("模型不存在", err)
if session.Module == domain.ModuleSparkChat {
req.ModelId = domain.SparkChatDocModelId
}
var answer string
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
... ... @@ -96,7 +93,7 @@ func (l *ChatSessionConversationWsLogic) ChatSessionConversationWs(w http.Respon
}
fx.Parallel(func() {
// 异步访问AI接口
answer, err = Conversation(model, string(text), channel)
answer, err = Conversation(l.ctx, l.svcCtx, session, req.ModelId, string(text), channel)
}, func() {
for {
var v string
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/system/open"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"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
func (l *ChatSessionGetLogic) ChatSessionGet(req *types.ChatSessionGetRequest) (resp *types.ChatSessionGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatSession
session *domain.ChatSession
records []*domain.ChatSessionRecord
token = contextdata.GetUserTokenFromCtx(l.ctx)
user open.User
)
// 货号唯一
if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
if session, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if user, err = l.svcCtx.SystemOpen.User(l.ctx, conn, dm.UserId); err != nil {
if user, err = l.svcCtx.SystemOpen.User(l.ctx, conn, session.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
if _, records, err = l.svcCtx.ChatSessionRecordRepository.FindByCompanyUser(l.ctx, conn, token.CompanyId, token.UserId, domain.NewQueryOptions().MustWithKV("sessionId", dm.Id)); err != nil {
if _, records, err = l.svcCtx.ChatSessionRecordRepository.FindByCompanyUser(l.ctx, conn, token.CompanyId, token.UserId, domain.NewQueryOptions().MustWithKV("sessionId", session.Id)); err != nil {
return nil, xerr.NewErr(err)
}
var typesRecords []types.Record
lo.ForEach(records, func(item *domain.ChatSessionRecord, index int) {
typesRecords = append(typesRecords, NewTypesChatRecord(item, user))
})
var documents []types.ChatDocumentItem
var dataset types.ChatDatasetItem
if session.Type == domain.TypeSparkDocumentsChat && len(session.Metadata.DocumentIds) > 0 {
for _, id := range session.Metadata.DocumentIds {
if item, _ := l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, id); item != nil {
documents = append(documents, types.NewTypesChatDocument(item))
}
}
} else if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
_, documentMapping, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, session.Metadata.DatasetId)
lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne)
lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil {
documents = append(documents, types.NewTypesChatDocument(document))
}
})
if item, _ := l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, session.Metadata.DatasetId); item != nil {
dataset = types.NewTypesChatDataset(item, lo.ToPtr(len(documents)))
}
}
resp = &types.ChatSessionGetResponse{
ChatSession: NewTypesChatSession(dm),
ChatSession: NewTypesChatSession(session),
Records: typesRecords,
Documents: documents,
Dataset: &dataset,
}
return
}
func NewTypesChatRecord(item *domain.ChatSessionRecord, user open.User) types.Record {
model, ok := domain.DefaultChatModels.Match(item.ModelId)
var typesModel *types.Model
if !ok {
typesModel = &types.Model{}
} else {
typesModel = &types.Model{
Name: model.Name,
Id: model.Id,
Logo: model.Logo,
}
}
var typesModel *types.Model = NewTypesModel(item.ModelId)
return types.Record{
Id: item.Id,
SessionId: item.SessionId,
... ... @@ -84,6 +97,21 @@ func NewTypesChatRecord(item *domain.ChatSessionRecord, user open.User) types.Re
}
}
func NewTypesModel(modelId int64) *types.Model {
model, ok := domain.DefaultChatModels.Match(modelId)
var typesModel *types.Model
if !ok {
typesModel = &types.Model{}
} else {
typesModel = &types.Model{
Name: model.Name,
Id: model.Id,
Logo: model.Logo,
}
}
return typesModel
}
func NewTypesUser(user open.User) *types.User {
if user.Id == 0 && user.Name == "" {
return nil
... ...
package chat
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatSessionRemoveFilesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatSessionRemoveFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSessionRemoveFilesLogic {
return &ChatSessionRemoveFilesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatSessionRemoveFilesLogic) ChatSessionRemoveFiles(req *types.ChatSessionAddFilesRequest) (resp *types.ChatSessionAddFilesResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatSession
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if dm.UserId != token.UserId {
return nil, xerr.NewErrMsgErr("无权限", err)
}
// 赋值
if dm.Module != domain.ModuleSparkChat {
return nil, xerr.NewErrMsgErr("类型有误,星火文档类型才可以添加文档", err)
}
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// 知识库移除
if dm.Type == domain.TypeSparkDatasetChat {
if err = core.DatasetRemoveFiles(l.ctx, l.svcCtx, conn, dm.Metadata.DatasetId, req.DocumentIds); err != nil {
return err
}
return nil
}
dm.Metadata.DocumentIds = lo.Without(dm.Metadata.DocumentIds, req.DocumentIds...)
dm, err = l.svcCtx.ChatSessionRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ChatSessionAddFilesResponse{}
return
}
... ...
package chat
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatSessionRenameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatSessionRenameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSessionRenameLogic {
return &ChatSessionRenameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatSessionRenameLogic) ChatSessionRename(req *types.ChatSessionRenameRequest) (resp *types.ChatSessionRenameResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatSession
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if dm, err = l.svcCtx.ChatSessionRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if dm.UserId != token.UserId {
return nil, xerr.NewErrMsgErr("无权限", err)
}
// 赋值
dm.Title = req.Name
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ChatSessionRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ChatSessionRenameResponse{}
return
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"time"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
... ... @@ -39,7 +40,9 @@ func (l *ChatSessionSaveLogic) ChatSessionSave(req *types.ChatSessionSaveRequest
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
resp = &types.ChatSessionSaveResponse{}
resp = &types.ChatSessionSaveResponse{
ChatSession: NewTypesChatSession(dm),
}
return
}
... ... @@ -53,14 +56,31 @@ func NewDomainChatSession(token contextdata.UserToken, item types.ChatSessionIte
UserId: token.UserId,
Title: title,
Abstract: title,
Module: item.Module,
Type: item.Type,
Metadata: &domain.SessionMetadata{
DatasetId: item.DatasetId,
DocumentIds: item.DocumentIds,
},
Rank: time.Now().Unix(),
}
}
func NewTypesChatSession(item *domain.ChatSession) types.ChatSessionItem {
var documentIds []int64
var datasetId int64
if item.Metadata != nil {
datasetId = item.Metadata.DatasetId
documentIds = item.Metadata.DocumentIds
}
return types.ChatSessionItem{
Id: item.Id,
Title: item.Title,
Abstract: item.Abstract,
CreatedAt: item.CreatedAt,
Module: item.Module,
Type: item.Type,
DatasetId: datasetId,
DocumentIds: documentIds,
}
}
... ...
... ... @@ -3,7 +3,10 @@ package chat
import (
"context"
"fmt"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
... ... @@ -30,19 +33,61 @@ func (l *ChatSessionSearchLogic) ChatSessionSearch(req *types.ChatSessionSearchR
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ChatSession
total int64
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().
WithKV("title", fmt.Sprintf("%%%v%%", req.Title))
WithKV("module", req.Module).
WithKV("companyId", token.CompanyId).
WithKV("userId", token.UserId)
if req.Title != "" {
queryOptions.WithKV("title", fmt.Sprintf("%%%v%%", req.Title))
}
if req.Page != 0 && req.Size != 0 {
queryOptions.WithOffsetLimit(req.Page, req.Size)
}
total, dms, err = l.svcCtx.ChatSessionRepository.Find(l.ctx, conn, queryOptions)
list := make([]types.ChatSessionItem, 0)
for i := range dms {
list = append(list, NewTypesChatSession(dms[i]))
// 1.分组dataset document mapping
var datasetIds []int64
for _, session := range dms {
if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
datasetIds = append(datasetIds, session.Metadata.DatasetId)
}
datasetIds = lo.Uniq(datasetIds)
}
var groupDocumentMappings map[int64][]*domain.ChatDatasetDocumentMapping
if len(datasetIds) > 0 {
_, documentMapping, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, datasetIds...)
groupDocumentMappings = lo.GroupBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) int64 {
return item.DatasetId
})
}
// 2. 加载documents
lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne)
for i, session := range dms {
var documents []types.ChatDocumentItem
if session.Type == domain.TypeSparkDocumentsChat && len(session.Metadata.DocumentIds) > 0 {
for _, id := range session.Metadata.DocumentIds {
if document, _ := lazyDocument.Load(l.ctx, conn, id); document != nil {
documents = append(documents, types.NewTypesChatDocument(document))
}
}
} else if session.Type == domain.TypeSparkDatasetChat && session.Metadata.DatasetId > 0 {
if documentMapping, ok := groupDocumentMappings[session.Metadata.DatasetId]; ok {
lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil {
documents = append(documents, types.NewTypesChatDocument(document))
}
})
}
}
typesSession := NewTypesChatSession(dms[i])
typesSession.Documents = documents
list = append(list, typesSession)
}
resp = &types.ChatSessionSearchResponse{
List: list,
... ...
package chat
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatSparkSessionSaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatSparkSessionSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatSparkSessionSaveLogic {
return &ChatSparkSessionSaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatSparkSessionSaveLogic) ChatSparkSessionSave(req *types.ChatSessionSaveRequest) (resp *types.ChatSessionSaveResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package core
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
)
func DatasetAddFiles(ctx context.Context, svcCtx *svc.ServiceContext, conn transaction.Conn, datasetId int64, documents []int64) error {
var (
documentMapping []*domain.ChatDatasetDocumentMapping
err error
)
_, documentMapping, _ = svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(ctx, conn, datasetId)
for _, id := range documents {
if lo.ContainsBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) bool {
return item.DocumentId == id
}) {
continue
}
if _, err = svcCtx.ChatDatasetDocumentMappingRepository.Insert(ctx, conn, &domain.ChatDatasetDocumentMapping{
DatasetId: datasetId,
DocumentId: id,
}); err != nil {
return err
}
}
return nil
}
... ...
package core
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
)
func DatasetRemoveFiles(ctx context.Context, svcCtx *svc.ServiceContext, conn transaction.Conn, datasetId int64, documents []int64) error {
var (
documentMapping []*domain.ChatDatasetDocumentMapping
err error
)
_, documentMapping, _ = svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(ctx, conn, datasetId)
for _, id := range documents {
var found *domain.ChatDatasetDocumentMapping
if !lo.ContainsBy(documentMapping, func(item *domain.ChatDatasetDocumentMapping) bool {
if item.DocumentId == id {
found = item
}
return item.DocumentId == id
}) {
continue
}
if _, err = svcCtx.ChatDatasetDocumentMappingRepository.Delete(ctx, conn, found); err != nil {
return err
}
}
return nil
}
... ...
package dataset
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetAddFilesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetAddFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetAddFilesLogic {
return &ChatDatasetAddFilesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetAddFilesLogic) ChatDatasetAddFiles(req *types.ChatDatasetAddFilesRequest) (resp *types.ChatDatasetAddFilesResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDataset
)
// 货号唯一
if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("知识库不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if err = core.DatasetAddFiles(l.ctx, l.svcCtx, conn, dm.Id, req.DocumentIds); err != nil {
return err
}
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("添加文档失败")
}
resp = &types.ChatDatasetAddFilesResponse{}
return
}
... ...
package dataset
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetDeleteLogic {
return &ChatDatasetDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetDeleteLogic) ChatDatasetDelete(req *types.ChatDatasetDeleteRequest) (resp *types.ChatDatasetDeleteResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDataset
)
if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if dm, err = l.svcCtx.ChatDatasetRepository.Delete(l.ctx, conn, dm); err != nil {
return err
}
// 删除document & dataset 关联
if err = l.svcCtx.ChatDatasetDocumentMappingRepository.DeleteByDataset(l.ctx, conn, dm.Id); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("移除失败", err)
}
resp = &types.ChatDatasetDeleteResponse{}
return
}
... ...
package dataset
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetGetLogic {
return &ChatDatasetGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetGetLogic) ChatDatasetGet(req *types.ChatDatasetGetRequest) (resp *types.ChatDatasetGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDataset
documentMapping []*domain.ChatDatasetDocumentMapping
)
// 货号唯一
if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
documents := make([]types.ChatDocumentItem, 0)
_, documentMapping, _ = l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, dm.Id)
lazyDocument := tool.NewLazyLoadService(l.svcCtx.ChatDocumentRepository.FindOne)
lo.ForEach(documentMapping, func(item *domain.ChatDatasetDocumentMapping, index int) {
if document, _ := lazyDocument.Load(l.ctx, conn, item.DocumentId); document != nil {
documents = append(documents, types.NewTypesChatDocument(document))
}
})
resp = &types.ChatDatasetGetResponse{
ChatDataset: NewTypesChatDataset(dm, nil),
Documents: documents,
}
return
}
... ...
package dataset
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/logic/core"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetRemvoeFilesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetRemvoeFilesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetRemvoeFilesLogic {
return &ChatDatasetRemvoeFilesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetRemvoeFilesLogic) ChatDatasetRemvoeFiles(req *types.ChatDatasetAddFilesRequest) (resp *types.ChatDatasetAddFilesResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDataset
)
// 货号唯一
if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if err = core.DatasetRemoveFiles(l.ctx, l.svcCtx, conn, dm.Id, req.DocumentIds); err != nil {
return err
}
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("添加文档失败")
}
resp = &types.ChatDatasetAddFilesResponse{}
return
}
... ...
package dataset
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetRenameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetRenameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetRenameLogic {
return &ChatDatasetRenameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetRenameLogic) ChatDatasetRename(req *types.ChatDatasetRenameRequest) (resp *types.ChatDatasetRenameResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDataset
)
if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 赋值
if req.Name != "" {
dm.Name = req.Name
}
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ChatDatasetRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ChatDatasetRenameResponse{
ChatDataset: NewTypesChatDataset(dm, nil),
}
return
}
... ...
package dataset
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetSaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetSaveLogic {
return &ChatDatasetSaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetSaveLogic) ChatDatasetSave(req *types.ChatDatasetSaveRequest) (resp *types.ChatDatasetSaveResponse, err error) {
var (
dm *domain.ChatDataset
token = contextdata.GetUserTokenFromCtx(l.ctx)
)
if req.Name == "" {
req.Name = "新知识库"
}
dm = &domain.ChatDataset{
UserId: token.UserId,
CompanyId: token.CompanyId,
Name: req.Name,
Status: domain.Enable,
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if dm, err = l.svcCtx.ChatDatasetRepository.Insert(l.ctx, conn, dm); err != nil {
return err
}
if len(req.DocumentIds) > 0 {
for _, id := range req.DocumentIds {
l.svcCtx.ChatDatasetDocumentMappingRepository.Insert(l.ctx, conn, &domain.ChatDatasetDocumentMapping{
DatasetId: dm.Id,
DocumentId: id,
})
}
}
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
resp = &types.ChatDatasetSaveResponse{
ChatDataset: NewTypesChatDataset(dm, lo.ToPtr(len(req.DocumentIds))),
}
return
}
//func NewDomainChatDataset(item types.ChatDatasetItem) *domain.ChatDataset {
// return &domain.ChatDataset{
// }
// }
func NewTypesChatDataset(item *domain.ChatDataset, fileNum *int) types.ChatDatasetItem {
return types.ChatDatasetItem{
Id: item.Id,
Name: lo.ToPtr(item.Name),
Desc: lo.ToPtr(item.Desc),
Status: lo.ToPtr(item.Status),
CreatedAt: item.CreatedAt,
UpdatedAt: item.UpdatedAt,
FileNumber: fileNum,
}
}
... ...
package dataset
import (
"context"
"fmt"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetSearchLogic {
return &ChatDatasetSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetSearchLogic) ChatDatasetSearch(req *types.ChatDatasetSearchRequest) (resp *types.ChatDatasetSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ChatDataset
total int64
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
WithKV("status", req.Status)
if req.Name != "" {
queryOptions.WithKV("name", fmt.Sprintf("%%%v%%", req.Name))
}
total, dms, err = l.svcCtx.ChatDatasetRepository.Find(l.ctx, conn, queryOptions)
list := make([]types.ChatDatasetItem, 0)
// 知识库关联的文档
ids := domain.Values(dms, domain.ChatDatasetId)
_, documentMappings, _ := l.svcCtx.ChatDatasetDocumentMappingRepository.FindByDataset(l.ctx, conn, ids...)
documentGroups := lo.GroupBy(documentMappings, func(item *domain.ChatDatasetDocumentMapping) int64 {
return item.DatasetId
})
for i := range dms {
var num = 0
if v, ok := documentGroups[dms[i].Id]; ok {
num = len(v)
}
list = append(list, NewTypesChatDataset(dms[i], lo.ToPtr(num)))
}
resp = &types.ChatDatasetSearchResponse{
List: list,
Total: total,
}
return
}
... ...
package dataset
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDatasetUpdateLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDatasetUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDatasetUpdateLogic {
return &ChatDatasetUpdateLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDatasetUpdateLogic) ChatDatasetUpdate(req *types.ChatDatasetUpdateRequest) (resp *types.ChatDatasetUpdateResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDataset
)
if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 赋值
if req.ChatDataset.Name != nil {
dm.Name = *req.ChatDataset.Name
}
if req.ChatDataset.Desc != nil {
dm.Desc = *req.ChatDataset.Desc
}
if req.ChatDataset.Status != nil {
dm.Status = *req.ChatDataset.Status
}
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ChatDatasetRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ChatDatasetUpdateResponse{}
return
}
... ...
package document
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDocumentBatchSaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDocumentBatchSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentBatchSaveLogic {
return &ChatDocumentBatchSaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDocumentBatchSaveLogic) ChatDocumentBatchSave(req *types.ChatDocumentBatchSaveRequest) (resp *types.ChatDocumentBatchSaveResponse, err error) {
var (
model *domain.ChatModel
fileId string
documents = make([]types.ChatDocumentItem, 0)
fileMap = make(map[string]string)
)
model, _ = domain.DefaultChatModels.Match(4)
for _, file := range req.Files {
if ext := types.GetFileTypeByExt(types.GetExt(file.FileName)); ext == "" {
return nil, xerr.NewErrMsgErr(fmt.Sprintf("%v文件格式不支持,目前仅支持格式txt/markdown/pdf/doc/docx", file.FileName), nil)
}
}
for _, file := range req.Files {
// 文件上传星火文档
// 设置回调
if fileId, err = ai.SparkUploadFile(model.Config.AppId, model.Config.AppKey, model.Config.AppSecret, ai.SparkFileRequest{
Url: file.Url,
FileName: file.FileName,
CallbackUrl: "",
}); err != nil {
return nil, xerr.NewErrMsgErr("上传文件到星火文档失败", err)
}
fileMap[file.Url] = fileId
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
for _, file := range req.Files {
var ok bool
if fileId, ok = fileMap[file.Url]; !ok {
continue
}
var dm *domain.ChatDocument
// 唯一判断
dm = types.NewDomainChatDocument(file.FileName, file.Url, file.Size, fileId)
if dm, err = l.svcCtx.ChatDocumentRepository.Insert(l.ctx, conn, dm); err != nil {
return err
}
documents = append(documents, types.NewTypesChatDocument(dm))
}
return err
}, true); err != nil {
return nil, xerr.NewErrMsgErr("保存失败", err)
}
resp = &types.ChatDocumentBatchSaveResponse{
ChatDocument: documents,
}
return
}
... ...
package document
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDocumentDeleteLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDocumentDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentDeleteLogic {
return &ChatDocumentDeleteLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDocumentDeleteLogic) ChatDocumentDelete(req *types.ChatDocumentDeleteRequest) (resp *types.ChatDocumentDeleteResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDocument
)
if dm, err = l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if dm, err = l.svcCtx.ChatDocumentRepository.Delete(l.ctx, conn, dm); err != nil {
return err
}
// 删除document & dataset 关联
if err = l.svcCtx.ChatDatasetDocumentMappingRepository.DeleteByDocument(l.ctx, conn, dm.Id); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("移除失败", err)
}
return
}
... ...
package document
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDocumentGetLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDocumentGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentGetLogic {
return &ChatDocumentGetLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDocumentGetLogic) ChatDocumentGet(req *types.ChatDocumentGetRequest) (resp *types.ChatDocumentGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDocument
)
// 货号唯一
if dm, err = l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
resp = &types.ChatDocumentGetResponse{
ChatDocument: types.NewTypesChatDocument(dm),
}
return
}
... ...
package document
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDocumentRenameLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDocumentRenameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentRenameLogic {
return &ChatDocumentRenameLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDocumentRenameLogic) ChatDocumentRename(req *types.ChatDocumentRenameRequest) (resp *types.ChatDocumentRenameResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDocument
)
if dm, err = l.svcCtx.ChatDocumentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErrMsgErr("不存在", err)
}
// 赋值
dm.Name = req.Name
// 更新
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ChatDocumentRepository.UpdateWithVersion(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("更新失败")
}
resp = &types.ChatDocumentRenameResponse{
ChatDocument: types.NewTypesChatDocument(dm),
}
return
}
... ...
package document
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/ai"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDocumentSaveLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDocumentSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentSaveLogic {
return &ChatDocumentSaveLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDocumentSaveLogic) ChatDocumentSave(req *types.ChatDocumentSaveRequest) (resp *types.ChatDocumentSaveResponse, err error) {
var (
//conn = l.svcCtx.DefaultDBConn()
dm *domain.ChatDocument
model *domain.ChatModel
fileId string
)
if ext := types.GetFileTypeByExt(types.GetExt(req.FileName)); ext == "" {
return nil, xerr.NewErrMsgErr(fmt.Sprintf("%v文件格式不支持,目前仅支持格式txt/markdown/pdf/doc/docx", req.FileName), nil)
}
model, _ = domain.DefaultChatModels.Match(domain.SparkChatDocModelId)
// 文件上传星火文档
// 设置回调
if fileId, err = ai.SparkUploadFile(model.Config.AppId, model.Config.AppKey, model.Config.AppSecret, ai.SparkFileRequest{
Url: req.Url,
FileName: req.FileName,
CallbackUrl: "",
}); err != nil {
return nil, xerr.NewErrMsgErr("上传文档失败", err)
}
// 唯一判断
dm = types.NewDomainChatDocument(req.FileName, req.Url, req.Size, fileId)
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
dm, err = l.svcCtx.ChatDocumentRepository.Insert(l.ctx, conn, dm)
return err
}, true); err != nil {
return nil, xerr.NewErrMsg("保存失败")
}
resp = &types.ChatDocumentSaveResponse{
ChatDocument: types.NewTypesChatDocument(dm),
}
return
}
... ...
package document
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ChatDocumentSearchLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewChatDocumentSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatDocumentSearchLogic {
return &ChatDocumentSearchLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ChatDocumentSearchLogic) ChatDocumentSearch(req *types.ChatDocumentSearchRequest) (resp *types.ChatDocumentSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
dms []*domain.ChatDocument
total int64
)
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
WithKV("fileType", req.FileType).
WithKV("status", req.Status)
if req.Name != "" {
queryOptions.WithKV("name", fmt.Sprintf("%%%v%%", req.Name))
}
total, dms, err = l.svcCtx.ChatDocumentRepository.Find(l.ctx, conn, queryOptions)
list := make([]types.ChatDocumentItem, 0)
for i := range dms {
list = append(list, types.NewTypesChatDocument(dms[i]))
}
resp = &types.ChatDocumentSearchResponse{
List: list,
Total: total,
}
return
}
... ...
... ... @@ -21,6 +21,9 @@ type ServiceContext struct {
DB *gorm.DB
ChatSessionRepository domain.ChatSessionRepository
ChatSessionRecordRepository domain.ChatSessionRecordRepository
ChatDocumentRepository domain.ChatDocumentRepository
ChatDatasetRepository domain.ChatDatasetRepository
ChatDatasetDocumentMappingRepository domain.ChatDatasetDocumentMappingRepository
SystemOpen open.SystemOpen
}
... ... @@ -36,7 +39,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
ChatSessionRepository: repository.NewChatSessionRepository(cache.NewCachedRepository(mlCache)),
ChatSessionRecordRepository: repository.NewChatSessionRecordRepository(cache.NewCachedRepository(mlCache)),
ChatDocumentRepository: repository.NewChatDocumentRepository(cache.NewCachedRepository(mlCache)),
ChatDatasetRepository: repository.NewChatDatasetRepository(cache.NewCachedRepository(mlCache)),
ChatDatasetDocumentMappingRepository: repository.NewChatDatasetDocumentMappingRepository(cache.NewCachedRepository(mlCache)),
SystemOpen: open.NewSystemOpen(c.Redis),
}
}
... ...
package types
import (
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
)
func NewTypesChatDataset(item *domain.ChatDataset, fileNum *int) ChatDatasetItem {
return ChatDatasetItem{
Id: item.Id,
Name: lo.ToPtr(item.Name),
Desc: lo.ToPtr(item.Desc),
Status: lo.ToPtr(item.Status),
CreatedAt: item.CreatedAt,
UpdatedAt: item.UpdatedAt,
FileNumber: fileNum,
}
}
... ...
package types
import (
"gitlab.fjmaimaimai.com/allied-creation/su-micro/cmd/ep/chat/internal/pkg/domain"
"path/filepath"
"strings"
)
func NewDomainChatDocument(name, url string, size float64, fileId string) *domain.ChatDocument {
ext := GetExt(name)
return &domain.ChatDocument{
Name: name,
Status: domain.StatusInUsed,
FileType: GetFileTypeByExt(ext),
Metadata: domain.DocumentMetadata{
OriginFileName: filepath.Base(name),
Ext: ext,
FileId: fileId,
FileUrl: url,
FileSize: size,
},
}
}
func NewTypesChatDocument(item *domain.ChatDocument) ChatDocumentItem {
return ChatDocumentItem{
Id: item.Id,
Name: item.Name,
FileType: item.FileType,
Status: item.Status,
OriginFileName: item.Metadata.OriginFileName,
Ext: item.Metadata.Ext,
FileId: item.Metadata.FileId,
FileUrl: item.Metadata.FileUrl,
FileSize: item.Metadata.FileSize,
CreatedAt: item.CreatedAt,
}
}
func GetFileTypeByExt(ext string) string {
switch ext {
case "md":
return "markdown"
case "pdf":
return ext
case "txt":
return ext
case "doc", "docx":
return "doc"
default:
return ""
}
return ""
}
func GetExt(file string) string {
return strings.TrimPrefix(filepath.Ext(file), ".")
}
... ...
... ... @@ -8,6 +8,8 @@ type ChatSessionGetRequest struct {
type ChatSessionGetResponse struct {
ChatSession ChatSessionItem `json:"session"`
Records []Record `json:"records"`
Documents []ChatDocumentItem `json:"documents"`
Dataset *ChatDatasetItem `json:"dataset"`
}
type ChatSessionSaveRequest struct {
... ... @@ -15,6 +17,7 @@ type ChatSessionSaveRequest struct {
}
type ChatSessionSaveResponse struct {
ChatSession ChatSessionItem `json:"session"`
}
type ChatSessionDeleteRequest struct {
... ... @@ -36,6 +39,7 @@ type ChatSessionSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Title string `json:"title,optional"` // 按标题搜索
Module int `json:"module,optional"` // 模块 1:openai chat 2:星火文档问答
}
type ChatSessionSearchResponse struct {
... ... @@ -48,6 +52,22 @@ type ChatSessionItem struct {
Title string `json:"title,optional,omitempty"` // 会话标题
Abstract string `json:"abstract,optional,omitempty"` // 摘要
CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
Module int `json:"module,optional,omitempty,default=1"` // 1:openai chat 2:星火文档问答
Type string `json:"type,optional,omitempty,default=chat"` // 类型 chat:普通问答 spark_dataset_chat:星火知识库问答 spark_documents_chat:星火多文档问答
DatasetId int64 `json:"datasetId,optional,omitempty"` // 知识库
DocumentIds []int64 `json:"documentIds,optional,omitempty"` // 多文档
Documents []ChatDocumentItem `json:"documents,optional,omitempty"` // 多文档
Author *User `json:"author,optional,omitempty"` // 提问人
TotalRecords int64 `json:"totalRecords,optional,omitempty"` // 记录数
Model *Model `json:"model,optional,omitempty"` // 模型
}
type ChatSessionRenameRequest struct {
Id int64 `json:"id"` // 模型ID
Name string `json:"name"` // 模型名称
}
type ChatSessionRenameResponse struct {
}
type ChatModelsRequest struct {
... ... @@ -93,7 +113,7 @@ type ChatSessionConversationRequestWs struct {
SessionId int64 `form:"sessionId"` // 会话ID
ModelId int64 `form:"modelId"` // 模型ID
ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
Text string `form:"text"` // 内容文本
Text string `form:"text,optional"` // 内容文本
}
type Record struct {
... ... @@ -103,7 +123,7 @@ type Record struct {
ModelId int64 `json:"modelId,omitempty"` // 模型ID
AuthorId int64 `json:"authorId,omitempty"` // 作者ID
Author *User `json:"author,omitempty"` // 提问人
Model *Model `json:"model,omitempty"` // 应答人
Model *Model `json:"model,omitempty"` // 模型
ContentType string `json:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
ProblemText string `json:"problemText"` // 问题文本
AnswerText string `json:"answerText"` // 回答文本
... ... @@ -121,3 +141,180 @@ type User struct {
Name string `json:"name"` // 名称
Avatar string `json:"avatar"` // 头像
}
type ChatSessionAddFilesRequest struct {
Id int64 `json:"id"` // 文档ID
DocumentIds []int64 `json:"documentIds"` // 文档ID列表
}
type ChatSessionAddFilesResponse struct {
}
type ChatDataSessionSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Title string `json:"title,optional"` // 按标题搜索
UserName string `json:"userName,optional"` // 用户名称
BeginTime int64 `json:"beginTime,optional"` // 会话创建时间
EndTime int64 `json:"endTime,optional"` // 会话创建时间
}
type ChatDataSessionSearchResponse struct {
List []ChatSessionItem `json:"list"`
Total int64 `json:"total"`
}
type ChatDocumentGetRequest struct {
Id int64 `path:"id"`
}
type ChatDocumentGetResponse struct {
ChatDocument ChatDocumentItem `json:"document"`
}
type ChatDocumentSaveRequest struct {
FileName string `json:"fileName"`
Url string `json:"url"`
Size float64 `json:"size"` // 文件大小(KB)
}
type ChatDocumentSaveResponse struct {
ChatDocument ChatDocumentItem `json:"document"`
}
type ChatDocumentDeleteRequest struct {
Id int64 `path:"id"`
}
type ChatDocumentDeleteResponse struct {
}
type ChatDocumentUpdateRequest struct {
Id int64 `path:"id"`
ChatDocument ChatDocumentItem `json:"document"`
}
type ChatDocumentUpdateResponse struct {
}
type ChatDocumentSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Name string `json:"name,optional"` // 文件名匹配
FileType string `json:"fileType,optional"` // 文件类型 markdown\pdf\txt\doc&docx
Status int `json:"status,optional"` // 文件状态 1.使用中、0.待处理、2.预处理中、3.处理失败
}
type ChatDocumentSearchResponse struct {
List []ChatDocumentItem `json:"list"`
Total int64 `json:"total"`
}
type ChatDocumentItem struct {
Id int64 `json:"id"`
Name string `json:"name,optional"` // 文件名
FileType string `json:"fileType"` // 文件类型 markdown\pdf\txt\doc&docx
Status int `json:"status"` // 1.使用中、0.待处理、2.预处理中、3.处理失败
OriginFileName string `json:"originFileName,omitempty"` // 源文件命
Ext string `json:"ext,omitempty"` // 格式
FileId string `json:"fileId,omitempty"` // 星火文件ID
FileUrl string `json:"fileUrl,omitempty"` // 文件地址
FileSize float64 `json:"fileSize,omitempty"` // 文件大小KB
CreatedAt int64 `json:"createdAt,omitempty"` // 创建时间
UpdatedAt int64 `json:"updatedAt,omitempty"` // 更新时间
}
type ChatDocumentRenameRequest struct {
Id int64 `json:"id"` // 文档ID
Name string `json:"name"` // 新名称
}
type ChatDocumentRenameResponse struct {
ChatDocument ChatDocumentItem `json:"document"`
}
type ChatDocumentBatchSaveRequest struct {
Files []DocumentFile `json:"files"`
}
type ChatDocumentBatchSaveResponse struct {
ChatDocument []ChatDocumentItem `json:"documents"`
}
type DocumentFile struct {
FileName string `json:"fileName"`
Url string `json:"url"`
Size float64 `json:"size"` // 文件大小(KB)
}
type ChatDatasetGetRequest struct {
Id int64 `path:"id"`
}
type ChatDatasetGetResponse struct {
ChatDataset ChatDatasetItem `json:"dataset"`
Documents []ChatDocumentItem `json:"documents"`
}
type ChatDatasetSaveRequest struct {
Name string `json:"name"` // 名称
DocumentIds []int64 `json:"documentIds"` // 文档ID列表
}
type ChatDatasetSaveResponse struct {
ChatDataset ChatDatasetItem `json:"dataset"`
}
type ChatDatasetDeleteRequest struct {
Id int64 `path:"id"`
}
type ChatDatasetDeleteResponse struct {
}
type ChatDatasetUpdateRequest struct {
Id int64 `path:"id"`
ChatDataset ChatDatasetItem `json:"dataset"`
}
type ChatDatasetUpdateResponse struct {
}
type ChatDatasetSearchRequest struct {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Name string `json:"name,optional"` // 文件名匹配
Status int `json:"status,optional,option=0|1|2"` // 1:启用 2:禁用
}
type ChatDatasetSearchResponse struct {
List []ChatDatasetItem `json:"list"`
Total int64 `json:"total"`
}
type ChatDatasetItem struct {
Id int64 `json:"id,optional,omitempty"`
Name *string `json:"name,optional,omitempty"` // 名称
Desc *string `json:"desc,optional,omitempty"` // 描述
Status *int `json:"status,optional,omitempty"` // 状态 1:启用 2:禁用
CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间
FileNumber *int `json:"fileNumber,optional,omitempty"` // 文件数量
}
type ChatDatasetRenameRequest struct {
Id int64 `json:"id"` // 文档ID
Name string `json:"name"` // 新名称
}
type ChatDatasetRenameResponse struct {
ChatDataset ChatDatasetItem `json:"dataset"`
}
type ChatDatasetAddFilesRequest struct {
Id int64 `json:"id"` // 文档ID
DocumentIds []int64 `json:"documentIds"` // 文档ID列表
}
type ChatDatasetAddFilesResponse struct {
}
... ...
... ... @@ -15,3 +15,21 @@ CREATE TABLE `chat_model`
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `chat_dataset`
(
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `chat_document`
(
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `chat_dataset_document_mapping`
(
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
... ...
... ... @@ -39,4 +39,5 @@ COPY --from=builder /build/api/${PROJECT} ./
COPY --from=builder /build/cmd/ep/${PROJECTCODE}/api/etc/${CONFIG_FILE} ./etc/
EXPOSE 8080
EXPOSE 443
ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
if [ "$?" == "1" ];then
kubectl create -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
kubectl create -f /tmp/dev/sumicro-chat/sumicro-chat.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
if [ "$?" == "0" ];then
echo "sumifcc-discuss service install success!"
echo "sumicro-chat service install success!"
else
echo "sumifcc-discuss service install fail!"
echo "sumicro-chat service install fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
if [ "$?" == "0" ];then
echo "sumifcc-discuss deployment install success!"
echo "sumicro-chat deployment install success!"
else
echo "sumifcc-discuss deployment install fail!"
echo "sumicro-chat deployment install fail!"
fi
else
kubectl delete -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
kubectl delete -f /tmp/dev/sumicro-chat/sumicro-chat.yaml
kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
done
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
done
kubectl create -f /tmp/test/sumifcc-discuss/sumifcc-discuss.yaml --record
kubectl -n mmm-suplus-test get svc | grep -q sumifcc-discuss
kubectl create -f /tmp/dev/sumicro-chat/sumicro-chat.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sumicro-chat
if [ "$?" == "0" ];then
echo "sumifcc-discuss service update success!"
echo "sumicro-chat service update success!"
else
echo "sumifcc-discuss service update fail!"
echo "sumicro-chat service update fail!"
fi
kubectl -n mmm-suplus-test get pods | grep -q sumifcc-discuss
kubectl -n mmm-suplus-dev get pods | grep -q sumicro-chat
if [ "$?" == "0" ];then
echo "sumifcc-discuss deployment update success!"
echo "sumicro-chat deployment update success!"
else
echo "sumifcc-discuss deployment update fail!"
echo "sumicro-chat deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: ConfigMap
metadata:
name: sumicro-chat-config-dev
data:
core.yaml: |
Name: sumicro-chat-dev
Host: 0.0.0.0
Port: 8080
Verbose: false
Migrate: true
Timeout: 30000
LogRequest: true # 记录详细请求日志
Log:
#Mode: file
Encoding: plain
Level: debug # info
MaxSize: 1 # 2MB
TimeFormat: 2006-01-02 15:04:05
Rotation: size
MaxContentLength: 10240
SystemAuth:
AccessSecret: su-platform
AccessExpire: 360000
Redis:
Host: 192.168.0.243:6379
Type: node
Pass:
DB:
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=su_enterprise_platform port=31543 sslmode=disable TimeZone=Asia/Shanghai
---
apiVersion: v1
kind: Service
metadata:
name: sumicro-chat
namespace: mmm-suplus-test
namespace: mmm-suplus-dev
labels:
k8s-app: sumicro-chat
spec:
... ... @@ -56,7 +20,7 @@ apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sumicro-chat
namespace: mmm-suplus-test
namespace: mmm-suplus-dev
labels:
k8s-app: sumicro-chat
spec:
... ... @@ -77,7 +41,7 @@ spec:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp10pa9isz0xg7nlsuzp
containers:
- name: sumicro-chat
... ...
syntax = "v1"
import "core/session.api"
import "core/document.api"
import "core/dataset.api"
\ No newline at end of file
... ...
syntax = "v1"
// 后台接口
@server(
prefix: v1
group: dataset
middleware: LogRequest
jwt: SystemAuth
)
service Core {
@doc "知识库-详情"
@handler chatDatasetGet
get /chat/dataset/:id (ChatDatasetGetRequest) returns (ChatDatasetGetResponse)
@doc "知识库-保存"
@handler chatDatasetSave
post /chat/dataset (ChatDatasetSaveRequest) returns (ChatDatasetSaveResponse)
@doc "知识库-删除"
@handler chatDatasetDelete
delete /chat/dataset/:id (ChatDatasetDeleteRequest) returns (ChatDatasetDeleteResponse)
@doc "知识库-更新"
@handler chatDatasetUpdate
put /chat/dataset/:id (ChatDatasetUpdateRequest) returns (ChatDatasetUpdateResponse)
@doc "知识库-重命名"
@handler chatDatasetRename
post /chat/dataset/rename (ChatDatasetRenameRequest) returns (ChatDatasetRenameResponse)
@doc "知识库-搜索"
@handler chatDatasetSearch
post /chat/dataset/search (ChatDatasetSearchRequest) returns (ChatDatasetSearchResponse)
@doc "知识库-添加文件"
@handler chatDatasetAddFiles
post /chat/dataset/add_files (ChatDatasetAddFilesRequest) returns (ChatDatasetAddFilesResponse)
@doc "知识库-移除文件"
@handler chatDatasetRemvoeFiles
post /chat/dataset/remove_files (ChatDatasetAddFilesRequest) returns (ChatDatasetAddFilesResponse)
}
type (
ChatDatasetGetRequest {
Id int64 `path:"id"`
}
ChatDatasetGetResponse {
ChatDataset ChatDatasetItem `json:"dataset"`
Documents []ChatDocumentItem `json:"documents"`
}
ChatDatasetSaveRequest {
Name string `json:"name"` // 名称
DocumentIds []int64 `json:"documentIds"` // 文档ID列表
}
ChatDatasetSaveResponse {
ChatDataset ChatDatasetItem `json:"dataset"`
}
ChatDatasetDeleteRequest {
Id int64 `path:"id"`
}
ChatDatasetDeleteResponse {}
ChatDatasetUpdateRequest {
Id int64 `path:"id"`
ChatDataset ChatDatasetItem `json:"dataset"`
}
ChatDatasetUpdateResponse {}
ChatDatasetSearchRequest {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Name string `json:"name,optional"` // 文件名匹配
Status int `json:"status,optional,option=0|1|2"`// 1:启用 2:禁用
}
ChatDatasetSearchResponse{
List []ChatDatasetItem `json:"list"`
Total int64 `json:"total"`
}
ChatDatasetItem {
Id int64 `json:"id,optional,omitempty"`
Name *string `json:"name,optional,omitempty"` // 名称
Desc *string `json:"desc,optional,omitempty"` // 描述
Status *int `json:"status,optional,omitempty"`// 状态 1:启用 2:禁用
CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
UpdatedAt int64 `json:"updatedAt,optional,omitempty"` // 更新时间
FileNumber *int `json:"fileNumber,optional,omitempty"` // 文件数量
}
)
// 知识库重命名
type(
ChatDatasetRenameRequest{
Id int64 `json:"id"` // 文档ID
Name string `json:"name"` // 新名称
}
ChatDatasetRenameResponse{
ChatDataset ChatDatasetItem `json:"dataset"`
}
)
// 知识库添加新文档
type(
ChatDatasetAddFilesRequest{
Id int64 `json:"id"` // 文档ID
DocumentIds []int64 `json:"documentIds"` // 文档ID列表
}
ChatDatasetAddFilesResponse{
}
)
\ No newline at end of file
... ...
syntax = "v1"
// 后台接口
@server(
prefix: v1
group: document
middleware: LogRequest
jwt: SystemAuth
)
service Core {
@doc "文档-详情"
@handler chatDocumentGet
get /chat/document/:id (ChatDocumentGetRequest) returns (ChatDocumentGetResponse)
@doc "文档-保存"
@handler chatDocumentSave
post /chat/document (ChatDocumentSaveRequest) returns (ChatDocumentSaveResponse)
@doc "文档-批量保存"
@handler chatDocumentBatchSave
post /chat/document/batch_save (ChatDocumentBatchSaveRequest) returns (ChatDocumentBatchSaveResponse)
@doc "文档-删除"
@handler chatDocumentDelete
delete /chat/document/:id (ChatDocumentDeleteRequest) returns (ChatDocumentDeleteResponse)
@doc "文档-删除"
@handler chatDocumentRename
post /chat/document/rename (ChatDocumentRenameRequest) returns (ChatDocumentRenameResponse)
// @doc "文档-更新"
// @handler chatDocumentUpdate
// put /chat/document/:id (ChatDocumentUpdateRequest) returns (ChatDocumentUpdateResponse)
@doc "文档-搜索"
@handler chatDocumentSearch
post /chat/document/search (ChatDocumentSearchRequest) returns (ChatDocumentSearchResponse)
}
type (
ChatDocumentGetRequest {
Id int64 `path:"id"`
}
ChatDocumentGetResponse {
ChatDocument ChatDocumentItem `json:"document"`
}
ChatDocumentSaveRequest {
FileName string `json:"fileName"`
Url string `json:"url"`
Size float64 `json:"size"` // 文件大小(KB)
}
ChatDocumentSaveResponse {
ChatDocument ChatDocumentItem `json:"document"`
}
ChatDocumentDeleteRequest {
Id int64 `path:"id"`
}
ChatDocumentDeleteResponse {}
ChatDocumentUpdateRequest {
Id int64 `path:"id"`
ChatDocument ChatDocumentItem `json:"document"`
}
ChatDocumentUpdateResponse {}
ChatDocumentSearchRequest {
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Name string `json:"name,optional"` // 文件名匹配
FileType string `json:"fileType,optional"` // 文件类型 markdown\pdf\txt\doc&docx
Status int `json:"status,optional"` // 文件状态 1.使用中、0.待处理、2.预处理中、3.处理失败
}
ChatDocumentSearchResponse{
List []ChatDocumentItem `json:"list"`
Total int64 `json:"total"`
}
ChatDocumentItem {
Id int64 `json:"id"`
Name string `json:"name,optional"` // 文件名
FileType string `json:"fileType"` // 文件类型 markdown\pdf\txt\doc&docx
Status int `json:"status"` // 1.使用中、0.待处理、2.预处理中、3.处理失败
OriginFileName string `json:"originFileName,omitempty"` // 源文件命
Ext string `json:"ext,omitempty"` // 格式
FileId string `json:"fileId,omitempty"` // 星火文件ID
FileUrl string `json:"fileUrl,omitempty"` // 文件地址
FileSize float64 `json:"fileSize,omitempty"` // 文件大小KB
CreatedAt int64 `json:"createdAt,omitempty"` // 创建时间
UpdatedAt int64 `json:"updatedAt,omitempty"` // 更新时间
}
)
// 文档重命名
type(
ChatDocumentRenameRequest{
Id int64 `json:"id"` // 文档ID
Name string `json:"name"` // 新名称
}
ChatDocumentRenameResponse{
ChatDocument ChatDocumentItem `json:"document"`
}
)
//文档批量添加
type(
ChatDocumentBatchSaveRequest {
Files []DocumentFile `json:"files"`
}
ChatDocumentBatchSaveResponse {
ChatDocument []ChatDocumentItem `json:"documents"`
}
DocumentFile{
FileName string `json:"fileName"`
Url string `json:"url"`
Size float64 `json:"size"` // 文件大小(KB)
}
)
\ No newline at end of file
... ...
... ... @@ -20,6 +20,9 @@ service Core {
@doc "聊天会话-更新"
@handler chatSessionUpdate
put /chat/session/:id (ChatSessionUpdateRequest) returns (ChatSessionUpdateResponse)
@doc "聊天会话-重命名"
@handler chatSessionRename
post /chat/session/rename (ChatSessionRenameRequest) returns (ChatSessionRenameResponse)
@doc "聊天会话-搜索"
@handler chatSessionSearch
post /chat/session/search (ChatSessionSearchRequest) returns (ChatSessionSearchResponse)
... ... @@ -30,6 +33,20 @@ service Core {
@handler chatSessionConversationWs
get /chat/session/conversation (ChatSessionConversationRequestWs) returns (ChatSessionConversationResponse)
@doc "聊天会话-添加文件"
@handler chatSessionAddFiles
post /chat/session/add_files (ChatSessionAddFilesRequest) returns (ChatSessionAddFilesResponse)
@doc "聊天会话-移除文件"
@handler chatSessionRemoveFiles
post /chat/session/remove_files (ChatSessionAddFilesRequest) returns (ChatSessionAddFilesResponse)
@doc "星火聊天会话-我的会话"
@handler chatMySparkSessions
post /chat/session/my_spark_sessions (ChatSessionSearchRequest) returns (ChatSessionSearchResponse)
@doc "星火聊天会话-保存"
@handler chatSparkSessionSave
post /chat/spark_session (ChatSessionSaveRequest) returns (ChatSessionSaveResponse)
@doc "聊天会话-对话记录列表"
@handler chatSessionRecords
post /chat/session/records (ChatSessionRecordsRequest) returns (ChatSessionRecordsResponse)
... ... @@ -39,6 +56,23 @@ service Core {
get /chat/models (ChatModelsRequest) returns (ChatModelsResponse)
}
// 数据管理后台接口
@server(
prefix: v1
group: chat
middleware: LogRequest
jwt: SystemAuth
)
service Core {
@doc "数据管理-会话搜索"
@handler chatDataSessionSearch
post /chat/data/session/search (ChatDataSessionSearchRequest) returns (ChatDataSessionSearchResponse)
@doc "聊天会话-详情"
@handler chatDataSessionGet
get /chat/data/session/:id (ChatSessionGetRequest) returns (ChatSessionGetResponse)
}
type (
ChatSessionGetRequest {
Id int64 `path:"id"`
... ... @@ -46,12 +80,16 @@ type (
ChatSessionGetResponse {
ChatSession ChatSessionItem `json:"session"`
Records []Record `json:"records"`
Documents []ChatDocumentItem `json:"documents"`
Dataset *ChatDatasetItem `json:"dataset"`
}
ChatSessionSaveRequest {
ChatSession ChatSessionItem `json:"session"`
}
ChatSessionSaveResponse {}
ChatSessionSaveResponse {
ChatSession ChatSessionItem `json:"session"`
}
ChatSessionDeleteRequest {
Id int64 `path:"id"`
... ... @@ -68,6 +106,7 @@ type (
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Title string `json:"title,optional"` // 按标题搜索
Module int `json:"module,optional"` // 模块 1:openai chat 2:星火文档问答
}
ChatSessionSearchResponse{
List []ChatSessionItem `json:"list"`
... ... @@ -78,6 +117,25 @@ type (
Title string `json:"title,optional,omitempty"` // 会话标题
Abstract string `json:"abstract,optional,omitempty"` // 摘要
CreatedAt int64 `json:"createdAt,optional,omitempty"` // 创建时间
Module int `json:"module,optional,omitempty,default=1"` // 1:openai chat 2:星火文档问答
Type string `json:"type,optional,omitempty,default=chat"` // 类型 chat:普通问答 spark_dataset_chat:星火知识库问答 spark_documents_chat:星火多文档问答
DatasetId int64 `json:"datasetId,optional,omitempty"` // 知识库
DocumentIds []int64 `json:"documentIds,optional,omitempty"` // 多文档
Documents []ChatDocumentItem `json:"documents,optional,omitempty"` // 多文档
Author *User `json:"author,optional,omitempty"` // 提问人
TotalRecords int64 `json:"totalRecords,optional,omitempty"` // 记录数
Model *Model `json:"model,optional,omitempty"` // 模型
}
)
type (
ChatSessionRenameRequest{
Id int64 `json:"id"` // 模型ID
Name string `json:"name"` // 模型名称
}
ChatSessionRenameResponse{
}
)
... ... @@ -128,7 +186,7 @@ type(
SessionId int64 `form:"sessionId"` // 会话ID
ModelId int64 `form:"modelId"` // 模型ID
ContentType string `form:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
Text string `form:"text"` // 内容文本
Text string `form:"text,optional"` // 内容文本
}
Record{
Id int64 `json:"id"` // 记录ID
... ... @@ -137,7 +195,7 @@ type(
ModelId int64 `json:"modelId,omitempty"` // 模型ID
AuthorId int64 `json:"authorId,omitempty"` // 作者ID
Author *User `json:"author,omitempty"` // 提问人
Model *Model `json:"model,omitempty"` // 应答人
Model *Model `json:"model,omitempty"` // 模型
ContentType string `json:"contentType"` // 内容类型 文本:text (图片:image 文档:document)
ProblemText string `json:"problemText"` // 问题文本
AnswerText string `json:"answerText"` // 回答文本
... ... @@ -154,3 +212,30 @@ type(
Avatar string `json:"avatar"` // 头像
}
)
// 会话添加新文档
type(
ChatSessionAddFilesRequest{
Id int64 `json:"id"` // 文档ID
DocumentIds []int64 `json:"documentIds"` // 文档ID列表
}
ChatSessionAddFilesResponse{
}
)
// 数据管理-会话搜索
type(
ChatDataSessionSearchRequest{
Page int `json:"page,optional"`
Size int `json:"size,optional"`
Title string `json:"title,optional"` // 按标题搜索
UserName string `json:"userName,optional"` // 用户名称
BeginTime int64 `json:"beginTime,optional"`// 会话创建时间
EndTime int64 `json:"endTime,optional"` // 会话创建时间
}
ChatDataSessionSearchResponse{
List []ChatSessionItem `json:"list"`
Total int64 `json:"total"`
}
)
\ No newline at end of file
... ...
... ... @@ -15,6 +15,294 @@
"application/json"
],
"paths": {
"v1/chat/dataset": {
"post": {
"summary": "知识库-保存",
"operationId": "chatDatasetSave",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDatasetSaveResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDatasetSaveRequest"
}
}
],
"requestBody": {},
"tags": [
"dataset"
]
}
},
"v1/chat/dataset/rename": {
"post": {
"summary": "知识库-重命名",
"operationId": "chatDatasetRename",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDatasetUpdateResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDatasetUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"dataset"
]
}
},
"v1/chat/dataset/search": {
"post": {
"summary": "知识库-搜索",
"operationId": "chatDatasetSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDatasetSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDatasetSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"dataset"
]
}
},
"v1/chat/dataset/{id}": {
"get": {
"summary": "知识库-详情",
"operationId": "chatDatasetGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDatasetGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"dataset"
]
},
"delete": {
"summary": "知识库-删除",
"operationId": "chatDatasetDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDatasetDeleteResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDatasetDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"dataset"
]
},
"put": {
"summary": "知识库-更新",
"operationId": "chatDatasetUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDatasetUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDatasetUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"dataset"
]
}
},
"v1/chat/document": {
"post": {
"summary": "文档-保存",
"operationId": "chatDocumentSave",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDocumentSaveResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDocumentSaveRequest"
}
}
],
"requestBody": {},
"tags": [
"document"
]
}
},
"v1/chat/document/search": {
"post": {
"summary": "文档-搜索",
"operationId": "chatDocumentSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDocumentSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDocumentSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"document"
]
}
},
"v1/chat/document/{id}": {
"get": {
"summary": "文档-详情",
"operationId": "chatDocumentGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDocumentGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"document"
]
},
"delete": {
"summary": "文档-删除",
"operationId": "chatDocumentDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatDocumentDeleteResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatDocumentDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"document"
]
}
},
"v1/chat/models": {
"get": {
"summary": "模型列表",
... ... @@ -64,7 +352,7 @@
"v1/chat/session/conversation": {
"get": {
"summary": "聊天会话-对话",
"operationId": "chatSessionConversation",
"operationId": "chatSessionConversationWs",
"responses": {
"200": {
"description": "A successful response.",
... ... @@ -90,195 +378,662 @@
"type": "integer",
"format": "int64"
},
{
"name": "contentType",
"description": " 内容类型 文本:text (图片:image 文档:document)",
"in": "query",
"required": true,
{
"name": "contentType",
"description": " 内容类型 文本:text (图片:image 文档:document)",
"in": "query",
"required": true,
"type": "string"
},
{
"name": "text",
"description": " 内容文本",
"in": "query",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"chat"
]
},
"post": {
"summary": "聊天会话-对话",
"operationId": "chatSessionConversation",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionConversationResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionConversationRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
}
},
"v1/chat/session/my_spark_sessions": {
"post": {
"summary": "星火聊天会话-我的会话",
"operationId": "chatMySparkSessions",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
}
},
"v1/chat/session/records": {
"post": {
"summary": "聊天会话-对话记录列表",
"operationId": "chatSessionRecords",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionRecordsResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionRecordsRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
}
},
"v1/chat/session/search": {
"post": {
"summary": "聊天会话-搜索",
"operationId": "chatSessionSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
}
},
"v1/chat/session/{id}": {
"get": {
"summary": "聊天会话-详情",
"operationId": "chatSessionGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"chat"
]
},
"delete": {
"summary": "聊天会话-删除",
"operationId": "chatSessionDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionDeleteResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
},
"put": {
"summary": "聊天会话-更新",
"operationId": "chatSessionUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
}
},
"v1/chat/spark_session": {
"post": {
"summary": "星火聊天会话-保存",
"operationId": "chatSparkSessionSave",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionSaveResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionSaveRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
}
}
},
"definitions": {
"ChatDatasetDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "ChatDatasetDeleteRequest",
"required": [
"id"
]
},
"ChatDatasetDeleteResponse": {
"type": "object",
"title": "ChatDatasetDeleteResponse"
},
"ChatDatasetGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "ChatDatasetGetRequest",
"required": [
"id"
]
},
"ChatDatasetGetResponse": {
"type": "object",
"properties": {
"dataset": {
"$ref": "#/definitions/ChatDatasetItem"
},
"documents": {
"type": "array",
"items": {
"$ref": "#/definitions/ChatDocumentItem"
}
}
},
"title": "ChatDatasetGetResponse",
"required": [
"dataset",
"documents"
]
},
"ChatDatasetItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"$ref": "#/definitions/string",
"description": " 名称"
},
"desc": {
"$ref": "#/definitions/string",
"description": " 描述"
},
"status": {
"$ref": "#/definitions/int",
"description": " 状态 1:启用 2:禁用"
},
"createdAt": {
"type": "integer",
"format": "int64",
"description": " 创建时间"
},
"updatedAt": {
"type": "integer",
"format": "int64",
"description": " 更新时间"
},
"fileNumber": {
"$ref": "#/definitions/int",
"description": " 文件数量"
}
},
"title": "ChatDatasetItem",
"required": [
"id",
"name",
"desc",
"status",
"createdAt",
"updatedAt",
"fileNumber"
]
},
"ChatDatasetSaveRequest": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": " 名称"
},
"documentIds": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 文档ID列表"
}
},
"title": "ChatDatasetSaveRequest",
"required": [
"name",
"documentIds"
]
},
"ChatDatasetSaveResponse": {
"type": "object",
"properties": {
"dataset": {
"$ref": "#/definitions/ChatDatasetItem"
}
},
"title": "ChatDatasetSaveResponse",
"required": [
"dataset"
]
},
"ChatDatasetSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string",
"description": " 文件名匹配"
},
"name": {
"type": "integer",
"format": "int32",
"description": " 1:启用 2:禁用"
}
},
"title": "ChatDatasetSearchRequest",
"required": [
"name"
]
},
"ChatDatasetSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/ChatDatasetItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "ChatDatasetSearchResponse",
"required": [
"list",
"total"
]
},
"ChatDatasetUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"dataset": {
"$ref": "#/definitions/ChatDatasetItem"
}
},
"title": "ChatDatasetUpdateRequest",
"required": [
"id",
"dataset"
]
},
"ChatDatasetUpdateResponse": {
"type": "object",
"title": "ChatDatasetUpdateResponse"
},
"ChatDocumentDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "ChatDocumentDeleteRequest",
"required": [
"id"
]
},
"ChatDocumentDeleteResponse": {
"type": "object",
"title": "ChatDocumentDeleteResponse"
},
"ChatDocumentGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "ChatDocumentGetRequest",
"required": [
"id"
]
},
"ChatDocumentGetResponse": {
"type": "object",
"properties": {
"document": {
"$ref": "#/definitions/ChatDocumentItem"
}
},
"title": "ChatDocumentGetResponse",
"required": [
"document"
]
},
"ChatDocumentItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string",
"description": " 文件名"
},
"fileType": {
"type": "string",
"description": " 文件类型 markdown\\pdf\\txt\\doc\u0026docx"
},
"status": {
"type": "integer",
"format": "int32",
"description": " 1.使用中、0.待处理、2.预处理中、3.处理失败"
},
"originFileName": {
"type": "string",
"description": " 源文件命"
},
"ext": {
"type": "string",
"description": " 格式"
},
"fileId": {
"type": "string",
"description": " 星火文件ID"
},
"fileUrl": {
"type": "string",
"description": " 文件地址"
},
"fileSize": {
"type": "number",
"format": "double",
"description": " 文件大小KB"
},
"createdAt": {
"type": "integer",
"format": "int64",
"description": " 创建时间"
},
"updatedAt": {
"type": "integer",
"format": "int64",
"description": " 更新时间"
}
},
"title": "ChatDocumentItem",
"required": [
"id",
"fileType",
"status",
"originFileName",
"ext",
"fileId",
"fileUrl",
"fileSize",
"createdAt",
"updatedAt"
]
},
"ChatDocumentSaveRequest": {
"type": "object",
"properties": {
"fileName": {
"type": "string"
},
{
"name": "text",
"description": " 内容文本",
"in": "query",
"required": true,
"url": {
"type": "string"
},
{
"name": "fileUrl",
"description": " 文件地址",
"in": "query",
"required": true,
"type": "string"
"size": {
"type": "number",
"format": "double",
"description": " 文件大小(KB)"
}
],
"requestBody": {},
"tags": [
"chat"
},
"title": "ChatDocumentSaveRequest",
"required": [
"fileName",
"url",
"size"
]
}
},
"v1/chat/session/records": {
"get": {
"summary": "聊天会话-对话记录列表",
"operationId": "chatSessionRecords",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionRecordsResponse"
}
"ChatDocumentSaveResponse": {
"type": "object",
"properties": {
"document": {
"$ref": "#/definitions/ChatDocumentItem"
}
},
"parameters": [
{
"name": "page",
"in": "query",
"required": false,
"title": "ChatDocumentSaveResponse",
"required": [
"document"
]
},
"ChatDocumentSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
{
"name": "size",
"in": "query",
"required": false,
"size": {
"type": "integer",
"format": "int32"
},
{
"name": "sessionId",
"in": "query",
"required": true,
"type": "integer",
"format": "int64"
}
],
"requestBody": {},
"tags": [
"chat"
]
}
"name": {
"type": "string",
"description": " 文件名匹配"
},
"v1/chat/session/search": {
"post": {
"summary": "聊天会话-搜索",
"operationId": "chatSessionSearch",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionSearchResponse"
}
}
"fileType": {
"type": "string",
"description": " 文件类型 markdown\\pdf\\txt\\doc\u0026docx"
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
]
"status": {
"type": "integer",
"format": "int32",
"description": " 文件状态 1.使用中、0.待处理、2.预处理中、3.处理失败"
}
},
"v1/chat/session/{id}": {
"get": {
"summary": "聊天会话-详情",
"operationId": "chatSessionGet",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionGetResponse"
}
}
"title": "ChatDocumentSearchRequest"
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
"ChatDocumentSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/ChatDocumentItem"
}
],
"requestBody": {},
"tags": [
"chat"
]
},
"delete": {
"summary": "聊天会话-删除",
"operationId": "chatSessionDelete",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionDeleteResponse"
}
"total": {
"type": "integer",
"format": "int64"
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"chat"
"title": "ChatDocumentSearchResponse",
"required": [
"list",
"total"
]
},
"put": {
"summary": "聊天会话-更新",
"operationId": "chatSessionUpdate",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChatSessionUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
"ChatDocumentUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChatSessionUpdateRequest"
"document": {
"$ref": "#/definitions/ChatDocumentItem"
}
}
],
"requestBody": {},
"tags": [
"chat"
},
"title": "ChatDocumentUpdateRequest",
"required": [
"id",
"document"
]
}
}
},
"definitions": {
"ChatDocumentUpdateResponse": {
"type": "object",
"title": "ChatDocumentUpdateResponse"
},
"ChatModelsRequest": {
"type": "object",
"title": "ChatModelsRequest"
... ... @@ -329,13 +1084,62 @@
"sessionId",
"modelId",
"contentType",
"text",
"fileUrl"
"text"
]
},
"ChatSessionConversationRequestWs": {
"type": "object",
"properties": {
"sessionId": {
"type": "integer",
"format": "int64",
"description": " 会话ID"
},
"modelId": {
"type": "integer",
"format": "int64",
"description": " 模型ID"
},
"contentType": {
"type": "string",
"description": " 内容类型 文本:text (图片:image 文档:document)"
},
"text": {
"type": "string",
"description": " 内容文本"
}
},
"title": "ChatSessionConversationRequestWs",
"required": [
"sessionId",
"modelId",
"contentType",
"text"
]
},
"ChatSessionConversationResponse": {
"type": "object",
"title": "ChatSessionConversationResponse"
"properties": {
"record": {
"$ref": "#/definitions/Record"
},
"parts": {
"type": "array",
"items": {
"type": "string"
}
},
"finished": {
"type": "boolean",
"format": "boolean"
}
},
"title": "ChatSessionConversationResponse",
"required": [
"record",
"parts",
"finished"
]
},
"ChatSessionDeleteRequest": {
"type": "object",
... ... @@ -406,6 +1210,30 @@
"type": "integer",
"format": "int64",
"description": " 创建时间"
},
"module": {
"type": "integer",
"format": "int32",
"default": "1",
"description": " 1:openai chat 2:星火文档问答"
},
"type": {
"type": "string",
"default": "chat",
"description": " 类型 chat:普通问答 spark_dataset_chat:星火知识库问答 spark_documents_chat:星火多文档问答"
},
"datasetId": {
"type": "integer",
"format": "int64",
"description": " 知识库"
},
"documentIds": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 多文档"
}
},
"title": "ChatSessionItem",
... ... @@ -413,7 +1241,11 @@
"id",
"title",
"abstract",
"createdAt"
"createdAt",
"module",
"type",
"datasetId",
"documentIds"
]
},
"ChatSessionRecordsRequest": {
... ... @@ -471,7 +1303,15 @@
},
"ChatSessionSaveResponse": {
"type": "object",
"title": "ChatSessionSaveResponse"
"properties": {
"session": {
"$ref": "#/definitions/ChatSessionItem"
}
},
"title": "ChatSessionSaveResponse",
"required": [
"session"
]
},
"ChatSessionSearchRequest": {
"type": "object",
... ... @@ -487,6 +1327,11 @@
"title": {
"type": "string",
"description": " 按标题搜索"
},
"module": {
"type": "integer",
"format": "int32",
"description": " 模块 1:openai chat 2:星火文档问答"
}
},
"title": "ChatSessionSearchRequest"
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: chat_dataset
jwt: JwtAuth
)
service Core {
@doc "详情"
@handler chat_datasetGet
get /chat_dataset/:id (ChatDatasetGetRequest) returns (ChatDatasetGetResponse)
@doc "保存"
@handler chat_datasetSave
post /chat_dataset (ChatDatasetSaveRequest) returns (ChatDatasetSaveResponse)
@doc "删除"
@handler chat_datasetDelete
delete /chat_dataset/:id (ChatDatasetDeleteRequest) returns (ChatDatasetDeleteResponse)
@doc "更新"
@handler chat_datasetUpdate
put /chat_dataset/:id (ChatDatasetUpdateRequest) returns (ChatDatasetUpdateResponse)
@doc "搜索"
@handler chat_datasetSearch
post /chat_dataset/search (ChatDatasetSearchRequest) returns (ChatDatasetSearchResponse)
}
type (
ChatDatasetGetRequest {
Id int64 `path:"id"`
}
ChatDatasetGetResponse {
ChatDataset ChatDatasetItem `json:"chat_dataset"`
}
ChatDatasetSaveRequest {
ChatDataset ChatDatasetItem `json:"chat_dataset"`
}
ChatDatasetSaveResponse {}
ChatDatasetDeleteRequest {
Id int64 `path:"id"`
}
ChatDatasetDeleteResponse {}
ChatDatasetUpdateRequest {
Id int64 `path:"id"`
ChatDataset ChatDatasetItem `json:"chat_dataset"`
}
ChatDatasetUpdateResponse {}
ChatDatasetSearchRequest {
Page int `json:"page"`
Size int `json:"size"`
}
ChatDatasetSearchResponse{
List []ChatDatasetItem `json:"list"`
Total int64 `json:"total"`
}
ChatDatasetItem {
}
)
// logic CRUD
// Save
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ChatDataset
//)
//// 唯一判断
//dm = NewDomainChatDataset(req.ChatDataset)
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.ChatDatasetRepository.Insert(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("保存失败")
//}
////resp = &types.ChatDatasetSaveResponse{}
//return
//func NewDomainChatDataset(item types.ChatDatasetItem) *domain.ChatDataset {
// return &domain.ChatDataset{
// }
//}
//
//func NewTypesChatDataset(item *domain.ChatDataset) types.ChatDatasetItem {
// return types.ChatDatasetItem{
// Id: item.Id,
// }
//}
// Get
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ChatDataset
//)
//// 货号唯一
//if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//resp = &types.ChatDatasetGetResponse{
// ChatDataset: NewTypesChatDataset(dm),
//}
//return
// Delete
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ChatDataset
//)
//if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// if dm, err = l.svcCtx.ChatDatasetRepository.Delete(l.ctx, conn, dm); err != nil {
// return err
// }
// return nil
//}, true); err != nil {
// return nil, xerr.NewErrMsgErr("移除失败", err)
//}
//return
// Search
//var (
// conn = l.svcCtx.DefaultDBConn()
// dms []*domain.ChatDataset
// total int64
//)
//
//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
// WithKV("", "")
//total, dms, err = l.svcCtx.ChatDatasetRepository.Find(l.ctx, conn, queryOptions)
//list := make([]types.ChatDatasetItem, 0)
//for i := range dms {
// list = append(list, NewTypesChatDataset(dms[i]))
//}
//resp = &types.ChatDatasetSearchResponse{
// List: list,
// Total: total,
//}
//return
// Update
//var (
// conn = l.svcCtx.DefaultDBConn()
// dm *domain.ChatDataset
//)
//if dm, err = l.svcCtx.ChatDatasetRepository.FindOne(l.ctx, conn, req.Id); err != nil {
// return nil, xerr.NewErrMsgErr("不存在", err)
//}
//// 不可编辑判断
//// 赋值
//// 更新
//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
// dm, err = l.svcCtx.ChatDatasetRepository.UpdateWithVersion(l.ctx, conn, dm)
// return err
//}, true); err != nil {
// return nil, xerr.NewErrMsg("更新失败")
//}
//resp = &types.ChatDatasetUpdateResponse{}
//return
... ...