feat: 植物识别百科ai助手迁移
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"sundynix-micro-go/common/model"
|
||||
"time"
|
||||
)
|
||||
@@ -247,19 +250,6 @@ type Topic struct {
|
||||
|
||||
func (Topic) TableName() string { return "sundynix_plant_topic" }
|
||||
|
||||
// ========== OCR ==========
|
||||
|
||||
// OcrLog OCR识别记录
|
||||
type OcrLog struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
ImageUrl string `gorm:"size:500;column:image_url" json:"imageUrl"`
|
||||
Result string `gorm:"type:text;column:result" json:"result"`
|
||||
LogID uint64 `gorm:"column:log_id;index" json:"logId"`
|
||||
}
|
||||
|
||||
func (OcrLog) TableName() string { return "sundynix_plant_ocr_log" }
|
||||
|
||||
// ========== 积分商城 ==========
|
||||
|
||||
// ExchangeItem status: 1=上架 2=下架
|
||||
@@ -391,3 +381,75 @@ type MediaCheckResult struct {
|
||||
}
|
||||
|
||||
func (MediaCheckResult) TableName() string { return "sundynix_plant_media_check_result" }
|
||||
|
||||
// ========== AI RAG 配置 ==========
|
||||
|
||||
type SysAiConfig struct {
|
||||
model.BaseModel
|
||||
IsActive int `gorm:"column:is_active;type:tinyint;default:0;comment:是否激活(1是0否)" json:"isActive"`
|
||||
QdrantUrl string `gorm:"column:qdrant_url;type:varchar(255);comment:Qdrant接口地址" json:"qdrantUrl"`
|
||||
QdrantApiKey string `gorm:"column:qdrant_api_key;type:varchar(255);comment:Qdrant密钥" json:"qdrantApiKey"`
|
||||
QdrantCollection string `gorm:"column:qdrant_collection;type:varchar(100);comment:Qdrant集合名" json:"qdrantCollection"`
|
||||
VectorDimension int `gorm:"column:vector_dimension;type:int;comment:向量维度" json:"vectorDimension"`
|
||||
ChatProvider string `gorm:"column:chat_provider;type:varchar(50);comment:对话模型供应商" json:"chatProvider"`
|
||||
ChatApiUrl string `gorm:"column:chat_api_url;type:varchar(255);comment:对话模型接口地址" json:"chatApiUrl"`
|
||||
ChatApiKey string `gorm:"column:chat_api_key;type:varchar(255);comment:对话模型ApiKey" json:"chatApiKey"`
|
||||
ChatModelName string `gorm:"column:chat_model_name;type:varchar(100);comment:对话模型名称" json:"chatModelName"`
|
||||
EmbeddingProvider string `gorm:"column:embedding_provider;type:varchar(50);comment:Embedding模型供应商" json:"embeddingProvider"`
|
||||
EmbeddingApiUrl string `gorm:"column:embedding_api_url;type:varchar(255);comment:Embedding模型接口地址" json:"embeddingApiUrl"`
|
||||
EmbeddingApiKey string `gorm:"column:embedding_api_key;type:varchar(255);comment:Embedding模型ApiKey" json:"embeddingApiKey"`
|
||||
EmbeddingModelName string `gorm:"column:embedding_model_name;type:varchar(100);comment:Embedding模型名称" json:"embeddingModelName"`
|
||||
DailyQueryLimit int `gorm:"column:daily_query_limit;type:int;default:20;comment:每用户每日问答上限(0=不限)" json:"dailyQueryLimit"`
|
||||
}
|
||||
|
||||
func (SysAiConfig) TableName() string { return "sundynix_plant_ai_config" }
|
||||
|
||||
// ========== 植物识别记录 ==========
|
||||
|
||||
type BaikeInfo struct {
|
||||
BaikeUrl string `json:"baike_url"` // 百度百科链接
|
||||
ImageUrl string `json:"image_url"` // 植物图片链接
|
||||
Description string `json:"description"` // 植物百科描述文本
|
||||
}
|
||||
|
||||
type ResultItem struct {
|
||||
Score float64 `json:"score"` // 匹配相似度得分(0-1)
|
||||
Name string `json:"name"` // 植物名称
|
||||
BaikeInfo *BaikeInfo `json:"baike_info"` // 植物百科信息
|
||||
}
|
||||
|
||||
type ResultsArray []ResultItem
|
||||
|
||||
// Scan 实现 sql.Scanner 接口:JSON String -> Go Struct (读库)
|
||||
func (r *ResultsArray) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
*r = make([]ResultItem, 0)
|
||||
return nil
|
||||
}
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
if str, ok := value.(string); ok {
|
||||
bytes = []byte(str)
|
||||
} else {
|
||||
return errors.New("type assertion to []byte/string failed")
|
||||
}
|
||||
}
|
||||
return json.Unmarshal(bytes, r)
|
||||
}
|
||||
|
||||
// Value 实现 driver.Valuer 接口:Go Struct -> JSON String (存库)
|
||||
func (r ResultsArray) Value() (driver.Value, error) {
|
||||
if len(r) == 0 {
|
||||
return "[]", nil
|
||||
}
|
||||
return json.Marshal(r)
|
||||
}
|
||||
|
||||
type ClassifyRecord struct {
|
||||
model.BaseModel
|
||||
UserID string `gorm:"size:50;index;column:user_id" json:"userId"`
|
||||
LogID uint64 `gorm:"column:log_id;index" json:"logId"`
|
||||
AllResults ResultsArray `gorm:"type:json;column:all_results" json:"allResults"`
|
||||
}
|
||||
|
||||
func (ClassifyRecord) TableName() string { return "sundynix_plant_classify_record" }
|
||||
|
||||
Reference in New Issue
Block a user