feat: 支持多租户多模型对话及文档去重优化
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"gitea.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/pgvector/pgvector-go"
|
||||
)
|
||||
|
||||
// CreateDocumentReq 创建文件请求
|
||||
@@ -45,7 +46,9 @@ type DeleteDocumentReq struct {
|
||||
type GetDocumentReq struct {
|
||||
g.Meta `path:"/get" method:"get" tags:"文件管理" summary:"获取文件详情" dc:"获取文件详情"`
|
||||
|
||||
Id int64 `json:"id" v:"required#ID不能为空"`
|
||||
Id int64 `json:"id" v:"required#ID不能为空"`
|
||||
DatasetId int64 `json:"datasetId"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type GetDocumentRes struct {
|
||||
@@ -60,6 +63,7 @@ type ListDocumentReq struct {
|
||||
Page *beans.Page `json:"page"`
|
||||
DatasetId int64 `json:"datasetId"`
|
||||
Keyword string `json:"keyword" dc:"关键词搜索"`
|
||||
Title string `json:"title" dc:"文件标题"`
|
||||
Status document.Status `json:"status"`
|
||||
}
|
||||
|
||||
@@ -92,7 +96,9 @@ type DocumentVectorReq struct {
|
||||
}
|
||||
|
||||
type DocumentVectorRPC struct {
|
||||
Id int64 `json:"id" dc:"id"`
|
||||
DatasetId int64 `json:"datasetId" dc:"所属数据集ID"`
|
||||
ContentHash string `json:"contentHash" dc:"内容hash"`
|
||||
Id int64 `json:"id" dc:"id"`
|
||||
DatasetId int64 `json:"datasetId" dc:"所属数据集ID"`
|
||||
DocumentId int64 `json:"documentId" dc:"文件ID"`
|
||||
ContentHash string `json:"contentHash" dc:"内容hash"`
|
||||
Vector pgvector.Vector `json:"vector" dc:"向量"`
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ import (
|
||||
type RAGQueryReq struct {
|
||||
g.Meta `path:"/ragQuery" method:"post" tags:"RAG查询" summary:"执行RAG查询" dc:"执行RAG查询"`
|
||||
|
||||
Content string `json:"content" v:"required#查询内容不能为空" dc:"用户问题"`
|
||||
DatasetIds []int64 `json:"datasetIds" dc:"数据集ID"`
|
||||
History []*Message `json:"history" dc:"历史对话"`
|
||||
TopK int `json:"topK" d:"5" dc:"检索topK,默认5"`
|
||||
Content string `json:"content" v:"required#查询内容不能为空" dc:"用户问题"`
|
||||
DatasetIds []int64 `json:"datasetIds" dc:"数据集ID"`
|
||||
DocumentIds []int64 `json:"documentIds" dc:"文档ID"`
|
||||
History []*Message `json:"history" dc:"历史对话"`
|
||||
TopK int `json:"topK" d:"5" dc:"检索topK,默认5"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
@@ -37,6 +38,13 @@ type UpdateDocumentVectorReq struct {
|
||||
Status document.Status `json:"status"`
|
||||
}
|
||||
|
||||
type DeleteDocumentVectorReq struct {
|
||||
g.Meta `path:"/delete" method:"put" tags:"文件块向量管理" summary:"删除文件块" dc:"删除文件块"`
|
||||
|
||||
Id int64 `json:"id"`
|
||||
DocumentId int64 `json:"documentId"`
|
||||
}
|
||||
|
||||
// ListDocumentVectorReq 文件块向量列表请求
|
||||
type ListDocumentVectorReq struct {
|
||||
g.Meta `path:"/list" method:"get" tags:"文件块向量管理" summary:"获取文件块向量列表" dc:"分页查询文件块向量列表,支持多条件筛选"`
|
||||
@@ -45,6 +53,8 @@ type ListDocumentVectorReq struct {
|
||||
Keyword string `json:"keyword" dc:"关键词搜索"`
|
||||
DatasetId int64 `json:"datasetId"`
|
||||
DocumentId int64 `json:"documentId"`
|
||||
DocumentIds []int64 `json:"documentIds"`
|
||||
ContentHashs []string `json:"contentHash"`
|
||||
Status document.Status `json:"status"`
|
||||
VectorStatus document.VectorStatus `json:"vectorStatus"`
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ type UpdateKeywordReq struct {
|
||||
type DeleteKeywordReq struct {
|
||||
g.Meta `path:"/delete" method:"delete" tags:"关键词管理" summary:"删除关键词" dc:"删除关键词"`
|
||||
|
||||
Id int64 `json:"id" v:"required#ID不能为空"`
|
||||
Id int64 `json:"id"`
|
||||
DocumentId int64 `json:"documentId"`
|
||||
}
|
||||
|
||||
// GetKeywordReq 获取关键词请求
|
||||
|
||||
114
model/dto/model.go
Normal file
114
model/dto/model.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"rag/consts/model"
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type GetModelAllEnumsReq struct {
|
||||
g.Meta `path:"/getAllEnums" method:"get" tags:"模型配置管理" summary:"获取全量模型枚举(类型+配置)"`
|
||||
}
|
||||
|
||||
type GetModelEnumRes struct {
|
||||
Options []ModelEnumOption `json:"options"`
|
||||
}
|
||||
|
||||
// ModelEnumOption 主类型:模型类型(vector/chat)
|
||||
type ModelEnumOption struct {
|
||||
Key interface{} `json:"key"`
|
||||
Value interface{} `json:"value"`
|
||||
ConfigTypes []ModelKeyValue `json:"configTypes"` // 这里统一!
|
||||
}
|
||||
|
||||
// ModelKeyValue 统一的 KV 结构 → 给模型类型 + 配置类型共用
|
||||
type ModelKeyValue struct {
|
||||
Key interface{} `json:"key"`
|
||||
Value interface{} `json:"value"`
|
||||
}
|
||||
|
||||
// GetModelConfigFormFieldsReq 获取模型配置表单请求
|
||||
type GetModelConfigFormFieldsReq struct {
|
||||
g.Meta `path:"/getModelFormField" method:"get" tags:"模型配置管理" summary:"获取模型表单" dc:"获取模型表单列表"`
|
||||
|
||||
ModelType model.ModelType `json:"modelType"` // 模型类型 vector/chat
|
||||
ConfigType model.ModelConfigType `json:"configType"` // 配置类型 ark/ollama/openai...
|
||||
}
|
||||
|
||||
// GetModelConfigFormFieldsRes 获取模型配置表单响应
|
||||
type GetModelConfigFormFieldsRes struct {
|
||||
ModelType model.ModelType `json:"modelType"`
|
||||
ConfigType model.ModelConfigType `json:"configType"`
|
||||
Fields []map[string]interface{} `json:"fields"`
|
||||
}
|
||||
|
||||
// CreateModelReq 创建模型请求
|
||||
type CreateModelReq struct {
|
||||
g.Meta `path:"/create" method:"post" tags:"模型配置管理" summary:"创建模型配置" dc:"创建模型配置"`
|
||||
|
||||
ModelType model.ModelType `json:"modelType" v:"required#模型类型不能为空"`
|
||||
ModelName string `json:"modelName" v:"required#模型名称不能为空"`
|
||||
ModelDesc string `json:"modelDesc"`
|
||||
ConfigType model.ModelConfigType `json:"configType"`
|
||||
ConfigContent map[string]interface{} `json:"configContent"`
|
||||
}
|
||||
|
||||
// CreateModelRes 创建模型响应
|
||||
type CreateModelRes struct {
|
||||
Id int64 `json:"id,string"`
|
||||
}
|
||||
|
||||
// UpdateModelReq 更新模型请求
|
||||
type UpdateModelReq struct {
|
||||
g.Meta `path:"/update" method:"put" tags:"模型配置管理" summary:"更新模型配置" dc:"更新模型配置"`
|
||||
|
||||
Id int64 `json:"id" v:"required#ID不能为空"`
|
||||
ModelType model.ModelType `json:"modelType"`
|
||||
ModelName string `json:"modelName"`
|
||||
ModelDesc string `json:"modelDesc"`
|
||||
ConfigType model.ModelConfigType `json:"configType"`
|
||||
ConfigContent map[string]interface{} `json:"configContent"`
|
||||
}
|
||||
|
||||
// DeleteModelReq 删除模型请求
|
||||
type DeleteModelReq struct {
|
||||
g.Meta `path:"/delete" method:"delete" tags:"模型配置管理" summary:"删除模型配置" dc:"删除模型配置"`
|
||||
|
||||
Id int64 `json:"id" v:"required#ID不能为空"`
|
||||
}
|
||||
|
||||
// GetModelReq 获取模型请求
|
||||
type GetModelReq struct {
|
||||
g.Meta `path:"/get" method:"get" tags:"模型配置管理" summary:"获取模型配置详情" dc:"获取模型配置详情"`
|
||||
|
||||
Id int64 `json:"id"`
|
||||
ModelType model.ModelType `json:"modelType"`
|
||||
}
|
||||
|
||||
// ListModelReq 获取模型列表请求
|
||||
type ListModelReq struct {
|
||||
g.Meta `path:"/list" method:"get" tags:"模型配置管理" summary:"获取模型配置列表" dc:"分页查询模型配置列表,支持多条件筛选"`
|
||||
|
||||
Page *beans.Page `json:"page"`
|
||||
ModelType model.ModelType `json:"modelType"`
|
||||
ModelName string `json:"modelName"`
|
||||
}
|
||||
|
||||
// ListModelRes 获取模型列表响应
|
||||
type ListModelRes struct {
|
||||
List []*ModelVO `json:"list"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
type ModelVO struct {
|
||||
Id int64 `json:"id,string"`
|
||||
ModelType model.ModelType `json:"modelType"`
|
||||
ModelName string `json:"modelName"`
|
||||
ModelDesc string `json:"modelDesc"`
|
||||
ConfigType model.ModelConfigType `json:"configType"`
|
||||
ConfigContent map[string]interface{} `json:"configContent"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UpdateTime time.Time `json:"updateTime"`
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package dto
|
||||
|
||||
import (
|
||||
"rag/consts/task"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// WriteTaskProgressReq 写入任务进度请求
|
||||
@@ -35,9 +37,17 @@ type DeleteTaskByTaskIdReq struct {
|
||||
|
||||
// GetTaskReq 获取任务请求
|
||||
type GetTaskReq struct {
|
||||
Id int64 `json:"id" dc:"任务ID"`
|
||||
TaskId int64 `json:"taskId" dc:"任务ID"`
|
||||
TaskType task.TaskType `json:"taskType" dc:"任务类型"`
|
||||
g.Meta `path:"/get" method:"get" tags:"任务管理" summary:"获取任务详情" dc:"获取任务详情"`
|
||||
|
||||
Id int64 `json:"id" dc:"任务ID"`
|
||||
TaskId int64 `json:"taskId" dc:"任务ID"`
|
||||
TaskType task.TaskType `json:"taskType" dc:"任务类型"`
|
||||
TaskStatus task.TaskStatus `json:"taskStatus" dc:"任务状态"`
|
||||
}
|
||||
|
||||
type ListTaskRes struct {
|
||||
List []*TaskVO `json:"list"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// TaskVO 任务视图对象
|
||||
|
||||
119
model/entity/model.go
Normal file
119
model/entity/model.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"rag/consts/model"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
type modelCol struct {
|
||||
beans.SQLBaseCol
|
||||
DatasetId string
|
||||
ModelType string
|
||||
ModelName string
|
||||
ModelDesc string
|
||||
ConfigType string
|
||||
ConfigContent string
|
||||
}
|
||||
|
||||
var ModelCol = modelCol{
|
||||
SQLBaseCol: beans.DefSQLBaseCol,
|
||||
DatasetId: "dataset_id",
|
||||
ModelType: "model_type",
|
||||
ModelName: "model_name",
|
||||
ModelDesc: "model_desc",
|
||||
ConfigType: "config_type",
|
||||
ConfigContent: "config_content",
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
beans.SQLBaseDO `orm:",inline"`
|
||||
DatasetId int64 `orm:"dataset_id" json:"datasetId" dc:"数据集ID"`
|
||||
ModelType model.ModelType `orm:"model_type" json:"modelType" dc:"模型类型"` // 向量/对话
|
||||
ModelName string `orm:"model_name" json:"modelName" dc:"模型名称"`
|
||||
ModelDesc string `orm:"model_desc" json:"modelDesc" dc:"模型描述"`
|
||||
ConfigType model.ModelConfigType `orm:"config_type" json:"configType" dc:"配置类型"` // ark/ollama等
|
||||
ConfigContent map[string]interface{} `orm:"config_content" json:"configContent" dc:"配置详情"` // 存JSON
|
||||
}
|
||||
|
||||
// -------------------------- 通用配置结构体(抽离重复字段)--------------------------
|
||||
|
||||
// OllamaConfig 通用配置(向量/对话完全一致)
|
||||
type OllamaConfig struct {
|
||||
BaseURL string `json:"base_url"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
// OpenAIConfig 通用配置
|
||||
type OpenAIConfig struct {
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
ByAzure bool `json:"by_azure"`
|
||||
BaseURL string `json:"base_url"`
|
||||
APIVersion string `json:"api_version"`
|
||||
}
|
||||
|
||||
// QianfanConfig 千帆通用配置
|
||||
type QianfanConfig struct {
|
||||
AccessKey string `json:"access_key"`
|
||||
SecretKey string `json:"secret_key"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
// ArkConfig 通用配置
|
||||
type ArkConfig struct {
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
// -------------------------- 向量模型配置 --------------------------
|
||||
|
||||
type VectorModelConfigOllama = OllamaConfig // 直接复用
|
||||
type VectorModelConfigOpenAI = OpenAIConfig // 直接复用
|
||||
type VectorModelConfigQianfan = QianfanConfig // 直接复用
|
||||
|
||||
type VectorModelConfigArk struct {
|
||||
ArkConfig
|
||||
APIType string `json:"api_type"`
|
||||
}
|
||||
|
||||
type VectorModelConfigTencentCloud struct {
|
||||
SecretID string `json:"secret_id"`
|
||||
SecretKey string `json:"secret_key"`
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
type VectorModelConfigDashScope struct {
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
// -------------------------- 对话模型配置 --------------------------
|
||||
|
||||
type ChatModelConfigArk = ArkConfig // 直接复用
|
||||
type ChatModelConfigArkBot = ArkConfig // 直接复用
|
||||
type ChatModelConfigOllama = OllamaConfig // 直接复用
|
||||
type ChatModelConfigOpenAI = OpenAIConfig // 直接复用
|
||||
type ChatModelConfigQianfan = QianfanConfig // 直接复用
|
||||
|
||||
type ChatModelConfigClaude struct {
|
||||
ByBedrock bool `json:"by_bedrock"`
|
||||
AccessKey string `json:"access_key"`
|
||||
SecretAccessKey string `json:"secret_access_key"`
|
||||
Region string `json:"region"`
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
BaseURL string `json:"base_url"`
|
||||
}
|
||||
|
||||
type ChatModelConfigDeepSeek struct {
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
BaseURL string `json:"base_url"`
|
||||
}
|
||||
|
||||
type ChatModelConfigQwen struct {
|
||||
APIKey string `json:"api_key"`
|
||||
Model string `json:"model"`
|
||||
BaseURL string `json:"base_url"`
|
||||
}
|
||||
Reference in New Issue
Block a user