feat: 完善知识库数据模型和服务
- 添加知识库更多字段配置 - 优化知识库服务逻辑 - 添加文档解析相关接口 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,19 +32,47 @@ func (p ParsingConfig) Value() (driver.Value, error) {
|
||||
return json.Marshal(p)
|
||||
}
|
||||
|
||||
// StorageConfig 存储配置
|
||||
type StorageConfig struct {
|
||||
Type string `json:"type"` // local / minio / s3
|
||||
Endpoint string `json:"endpoint"` // MinIO/S3 endpoint
|
||||
Bucket string `json:"bucket"` // MinIO/S3 bucket
|
||||
AccessKeyID string `json:"access_key_id"` // MinIO/S3 access key
|
||||
SecretAccessKey string `json:"secret_access_key"` // MinIO/S3 secret key
|
||||
UseSSL bool `json:"use_ssl"` // MinIO/S3 use SSL
|
||||
}
|
||||
|
||||
// Scan 实现 sql.Scanner 接口
|
||||
func (s *StorageConfig) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return errors.New("type assertion to []byte failed")
|
||||
}
|
||||
return json.Unmarshal(bytes, s)
|
||||
}
|
||||
|
||||
// Value 实现 driver.Valuer 接口
|
||||
func (s StorageConfig) Value() (driver.Value, error) {
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
// KnowledgeBase 知识库
|
||||
type KnowledgeBase struct {
|
||||
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
|
||||
Name string `json:"name" gorm:"type:varchar(255);not null"`
|
||||
Description string `json:"description" gorm:"type:text"`
|
||||
LLMModelID string `json:"llm_model_id" gorm:"type:varchar(36);not null"`
|
||||
EmbeddingModelID string `json:"embedding_model_id" gorm:"type:varchar(36);not null"`
|
||||
ParsingConfig ParsingConfig `json:"parsing_config" gorm:"type:json"`
|
||||
Status string `json:"status" gorm:"type:varchar(20);default:active"` // active / inactive
|
||||
DocumentCount int `json:"document_count" gorm:"default:0"`
|
||||
ChunkCount int `json:"chunk_count" gorm:"default:0"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ID string `json:"id" gorm:"primaryKey;type:varchar(36)"`
|
||||
Name string `json:"name" gorm:"type:varchar(255);not null"`
|
||||
Description string `json:"description" gorm:"type:text"`
|
||||
LLMModelID string `json:"llm_model_id" gorm:"type:varchar(36);not null"`
|
||||
EmbeddingModelID string `json:"embedding_model_id" gorm:"type:varchar(36);not null"`
|
||||
ParsingConfig ParsingConfig `json:"parsing_config" gorm:"type:json"`
|
||||
StorageConfig StorageConfig `json:"storage_config" gorm:"type:json"` // 存储配置
|
||||
Status string `json:"status" gorm:"type:varchar(20);default:active"` // active / inactive
|
||||
DocumentCount int `json:"document_count" gorm:"default:0"`
|
||||
ChunkCount int `json:"chunk_count" gorm:"default:0"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (KnowledgeBase) TableName() string {
|
||||
@@ -72,21 +100,23 @@ func (KnowledgeDocument) TableName() string {
|
||||
|
||||
// CreateKnowledgeRequest 创建知识库请求
|
||||
type CreateKnowledgeRequest struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
LLMModelID string `json:"llm_model_id" binding:"required"`
|
||||
EmbeddingModelID string `json:"embedding_model_id" binding:"required"`
|
||||
ParsingConfig ParsingConfig `json:"parsing_config" binding:"required"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
Description string `json:"description"`
|
||||
LLMModelID string `json:"llm_model_id" binding:"required"`
|
||||
EmbeddingModelID string `json:"embedding_model_id" binding:"required"`
|
||||
ParsingConfig ParsingConfig `json:"parsing_config" binding:"required"`
|
||||
StorageConfig StorageConfig `json:"storage_config"` // 存储配置,不传则使用全局配置
|
||||
}
|
||||
|
||||
// UpdateKnowledgeRequest 更新知识库请求
|
||||
type UpdateKnowledgeRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
LLMModelID string `json:"llm_model_id"`
|
||||
EmbeddingModelID string `json:"embedding_model_id"`
|
||||
ParsingConfig ParsingConfig `json:"parsing_config"`
|
||||
Status string `json:"status"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
LLMModelID string `json:"llm_model_id"`
|
||||
EmbeddingModelID string `json:"embedding_model_id"`
|
||||
ParsingConfig ParsingConfig `json:"parsing_config"`
|
||||
StorageConfig StorageConfig `json:"storage_config"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// KnowledgeListResponse 知识库列表响应
|
||||
|
||||
Reference in New Issue
Block a user