chat_session.go 2.0 KB
package domain

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
)

type ChatSession struct {
	Id        int64            `json:",omitempty"` // 唯一标识
	CompanyId int64            `json:",omitempty"` // 公司ID
	UserId    int64            `json:",omitempty"` // 用户ID
	Title     string           `json:",omitempty"` // 会话标题
	Abstract  string           `json:",omitempty"` // 摘要
	Module    int              `json:",omitempty"` // 1:openai chat  2:星火文档问答
	Type      string           `json:",omitempty"` // 类型 chat:普通问答 spark_dataset_chat:星火知识库问答 spark_documents_chat:星火多文档问答
	Metadata  *SessionMetadata `json:",omitempty"` // 元数据
	Rank      int64            `json:",omitempty"` // 排序(时间秒,置顶更新当前会话)
	CreatedAt int64            `json:",omitempty"`
	UpdatedAt int64            `json:",omitempty"`
	DeletedAt int64            `json:",omitempty"`
	Version   int              `json:",omitempty"`
}

const (
	ModuleOpenaiChat = 1
	ModuleSparkChat  = 2
)

const (
	TypeChat               = "chat"
	TypeSparkDatasetChat   = "spark_dataset_chat"
	TypeSparkDocumentsChat = "spark_documents_chat"
)

type SessionMetadata struct {
	DatasetId   int64   `json:",omitempty"` // 知识库
	DocumentIds []int64 `json:",omitempty"` // 多文档
}

type ChatSessionRepository interface {
	Insert(ctx context.Context, conn transaction.Conn, dm *ChatSession) (*ChatSession, error)
	Update(ctx context.Context, conn transaction.Conn, dm *ChatSession) (*ChatSession, error)
	UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ChatSession) (*ChatSession, error)
	Delete(ctx context.Context, conn transaction.Conn, dm *ChatSession) (*ChatSession, error)
	FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ChatSession, error)
	FindOneUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*ChatSession, error)
	Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ChatSession, error)
}