mirror of https://github.com/chaitin/PandaWiki.git
chore: 更新模型设置模式及相关配置,移除冗余迁移功能
This commit is contained in:
parent
c88bd58b6b
commit
1ff013ac47
|
|
@ -70,11 +70,9 @@ func createApp() (*App, error) {
|
|||
}
|
||||
migrationNodeVersion := fns.NewMigrationNodeVersion(logger, nodeUsecase, knowledgeBaseUsecase, ragRepository)
|
||||
migrationCreateBotAuth := fns.NewMigrationCreateBotAuth(logger)
|
||||
migrationAddModelSettingMode := fns.NewMigrationAddModelSettingMode(logger)
|
||||
migrationFuncs := &migration.MigrationFuncs{
|
||||
NodeMigration: migrationNodeVersion,
|
||||
BotAuthMigration: migrationCreateBotAuth,
|
||||
ModelSettingMigration: migrationAddModelSettingMode,
|
||||
NodeMigration: migrationNodeVersion,
|
||||
BotAuthMigration: migrationCreateBotAuth,
|
||||
}
|
||||
manager, err := migration.NewManager(db, logger, migrationFuncs)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package consts
|
|||
type AutoModeDefaultModel string
|
||||
|
||||
const (
|
||||
AutoModeDefaultChatModel AutoModeDefaultModel = "qwen-vl-max-latest"
|
||||
AutoModeDefaultChatModel AutoModeDefaultModel = "deepseek-chat"
|
||||
AutoModeDefaultEmbeddingModel AutoModeDefaultModel = "bge-m3"
|
||||
AutoModeDefaultRerankModel AutoModeDefaultModel = "bge-reranker-v2-m3"
|
||||
AutoModeDefaultAnalysisModel AutoModeDefaultModel = "qwen2.5-3b-instruct"
|
||||
|
|
|
|||
|
|
@ -6361,6 +6361,10 @@ const docTemplate = `{
|
|||
"description": "自定义对话模型名称",
|
||||
"type": "string"
|
||||
},
|
||||
"is_manual_embedding_updated": {
|
||||
"description": "手动模式下嵌入模型是否更新",
|
||||
"type": "boolean"
|
||||
},
|
||||
"mode": {
|
||||
"description": "模式: manual 或 auto",
|
||||
"allOf": [
|
||||
|
|
@ -8469,12 +8473,17 @@ const docTemplate = `{
|
|||
},
|
||||
"v1.NodeRestudyReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kb_id",
|
||||
"node_ids"
|
||||
],
|
||||
"properties": {
|
||||
"kb_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"node_ids": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6354,6 +6354,10 @@
|
|||
"description": "自定义对话模型名称",
|
||||
"type": "string"
|
||||
},
|
||||
"is_manual_embedding_updated": {
|
||||
"description": "手动模式下嵌入模型是否更新",
|
||||
"type": "boolean"
|
||||
},
|
||||
"mode": {
|
||||
"description": "模式: manual 或 auto",
|
||||
"allOf": [
|
||||
|
|
@ -8462,12 +8466,17 @@
|
|||
},
|
||||
"v1.NodeRestudyReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"kb_id",
|
||||
"node_ids"
|
||||
],
|
||||
"properties": {
|
||||
"kb_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"node_ids": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1644,6 +1644,9 @@ definitions:
|
|||
chat_model:
|
||||
description: 自定义对话模型名称
|
||||
type: string
|
||||
is_manual_embedding_updated:
|
||||
description: 手动模式下嵌入模型是否更新
|
||||
type: boolean
|
||||
mode:
|
||||
allOf:
|
||||
- $ref: '#/definitions/consts.ModelSettingMode'
|
||||
|
|
@ -3035,7 +3038,11 @@ definitions:
|
|||
node_ids:
|
||||
items:
|
||||
type: string
|
||||
minItems: 1
|
||||
type: array
|
||||
required:
|
||||
- kb_id
|
||||
- node_ids
|
||||
type: object
|
||||
v1.NodeRestudyResp:
|
||||
type: object
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
package fns
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/chaitin/panda-wiki/consts"
|
||||
"github.com/chaitin/panda-wiki/domain"
|
||||
"github.com/chaitin/panda-wiki/log"
|
||||
)
|
||||
|
||||
type MigrationAddModelSettingMode struct {
|
||||
Name string
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
func NewMigrationAddModelSettingMode(logger *log.Logger) *MigrationAddModelSettingMode {
|
||||
return &MigrationAddModelSettingMode{
|
||||
Name: "0003_add_model_setting_mode",
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MigrationAddModelSettingMode) Execute(tx *gorm.DB) error {
|
||||
ctx := context.Background()
|
||||
|
||||
// 检查是否已存在该设置
|
||||
var existingSetting domain.SystemSetting
|
||||
err := tx.WithContext(ctx).Where("key = ?", consts.SystemSettingModelMode).First(&existingSetting).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return fmt.Errorf("failed to check existing model_setting_mode setting: %w", err)
|
||||
}
|
||||
|
||||
// 如果记录不存在,则创建新记录
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
// 老用户设置手动模型, 新用户设置自动模式
|
||||
mode := string(consts.ModelSettingModeManual)
|
||||
var kbs []*domain.KnowledgeBase
|
||||
if err := tx.WithContext(ctx).
|
||||
Model(&domain.KnowledgeBase{}).
|
||||
Find(&kbs).Error; err != nil {
|
||||
return fmt.Errorf("get kb list failed: %w", err)
|
||||
}
|
||||
if len(kbs) == 0 {
|
||||
mode = string(consts.ModelSettingModeAuto)
|
||||
}
|
||||
|
||||
// 定义model_setting_mode的值结构
|
||||
modelSettingValue := map[string]interface{}{
|
||||
"mode": mode,
|
||||
"auto_mode_api_key": "", // 默认没有api key
|
||||
"chat_model": "", // 对话模型,默认为空
|
||||
"is_manual_embedding_updated": false, // 手动模式下嵌入模型是否更新,默认false
|
||||
}
|
||||
|
||||
// 将值转换为JSON字节数组
|
||||
valueBytes, err := json.Marshal(modelSettingValue)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal model setting value: %w", err)
|
||||
}
|
||||
|
||||
// 创建setting记录
|
||||
setting := &domain.SystemSetting{
|
||||
Key: consts.SystemSettingModelMode,
|
||||
Value: valueBytes,
|
||||
Description: "Model setting mode configuration",
|
||||
}
|
||||
if err := tx.WithContext(ctx).Create(setting).Error; err != nil {
|
||||
return fmt.Errorf("failed to create model_setting_mode setting: %w", err)
|
||||
}
|
||||
m.logger.Info("successfully created model_setting_mode setting")
|
||||
} else {
|
||||
m.logger.Info("model_setting_mode setting already exists, skipping creation")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -7,5 +7,4 @@ import (
|
|||
var ProviderSet = wire.NewSet(
|
||||
NewMigrationNodeVersion,
|
||||
NewMigrationCreateBotAuth,
|
||||
NewMigrationAddModelSettingMode,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ import (
|
|||
)
|
||||
|
||||
type MigrationFuncs struct {
|
||||
NodeMigration *fns.MigrationNodeVersion
|
||||
BotAuthMigration *fns.MigrationCreateBotAuth
|
||||
ModelSettingMigration *fns.MigrationAddModelSettingMode
|
||||
NodeMigration *fns.MigrationNodeVersion
|
||||
BotAuthMigration *fns.MigrationCreateBotAuth
|
||||
}
|
||||
|
||||
func (mf *MigrationFuncs) GetMigrationFuncs() []MigrationFunc {
|
||||
|
|
@ -20,9 +19,5 @@ func (mf *MigrationFuncs) GetMigrationFuncs() []MigrationFunc {
|
|||
Name: mf.BotAuthMigration.Name,
|
||||
Fn: mf.BotAuthMigration.Execute,
|
||||
})
|
||||
funcs = append(funcs, MigrationFunc{
|
||||
Name: mf.ModelSettingMigration.Name,
|
||||
Fn: mf.ModelSettingMigration.Execute,
|
||||
})
|
||||
return funcs
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,23 @@ CREATE TABLE IF NOT EXISTS system_settings (
|
|||
updated_at timestamptz NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_system_settings_key ON system_settings(key);
|
||||
CREATE UNIQUE INDEX idx_uniq_system_settings_key ON system_settings(key);
|
||||
|
||||
-- Insert model_setting_mode setting
|
||||
-- If there are existing knowledge bases, set mode to 'manual', otherwise set to 'auto'
|
||||
INSERT INTO system_settings (key, value, description)
|
||||
SELECT
|
||||
'model_setting_mode',
|
||||
jsonb_build_object(
|
||||
'mode', CASE
|
||||
WHEN EXISTS (SELECT 1 FROM knowledge_bases LIMIT 1) THEN 'manual'
|
||||
ELSE 'auto'
|
||||
END,
|
||||
'auto_mode_api_key', '',
|
||||
'chat_model', '',
|
||||
'is_manual_embedding_updated', false
|
||||
),
|
||||
'Model setting mode configuration'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM system_settings WHERE key = 'model_setting_mode'
|
||||
);
|
||||
|
|
@ -43,7 +43,7 @@ const AutoModelConfig = forwardRef<AutoModelConfigRef, AutoModelConfigProps>(
|
|||
|
||||
// 默认百智云 Chat 模型列表
|
||||
const DEFAULT_BAIZHI_CLOUD_CHAT_MODELS: string[] = [
|
||||
'deepseek-v3.1',
|
||||
'deepseek-chat',
|
||||
'deepseek-r1',
|
||||
'kimi-k2-0711-preview',
|
||||
'qwen-vl-max-latest',
|
||||
|
|
|
|||
Loading…
Reference in New Issue