mirror of
https://github.com/yangjian102621/geekai.git
synced 2026-04-30 23:14:28 +08:00
修复模型添加报数据库字段不存在的 bug
This commit is contained in:
@@ -40,8 +40,8 @@ func (h *ChatModelHandler) Save(c *gin.Context) {
|
|||||||
Power int `json:"power"`
|
Power int `json:"power"`
|
||||||
MaxTokens int `json:"max_tokens"` // 最大响应长度
|
MaxTokens int `json:"max_tokens"` // 最大响应长度
|
||||||
MaxContext int `json:"max_context"` // 最大上下文长度
|
MaxContext int `json:"max_context"` // 最大上下文长度
|
||||||
Description string `json:"description"` //模型描述
|
Desc string `json:"desc"` //模型描述
|
||||||
Category string `json:"category"` //模型类别
|
Tag string `json:"tag"` //模型标签
|
||||||
Temperature float32 `json:"temperature"` // 模型温度
|
Temperature float32 `json:"temperature"` // 模型温度
|
||||||
KeyId int `json:"key_id,omitempty"`
|
KeyId int `json:"key_id,omitempty"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
@@ -66,8 +66,8 @@ func (h *ChatModelHandler) Save(c *gin.Context) {
|
|||||||
item.Power = data.Power
|
item.Power = data.Power
|
||||||
item.MaxTokens = data.MaxTokens
|
item.MaxTokens = data.MaxTokens
|
||||||
item.MaxContext = data.MaxContext
|
item.MaxContext = data.MaxContext
|
||||||
item.Description = data.Description
|
item.Desc = data.Desc
|
||||||
item.Category = data.Category
|
item.Tag = data.Tag
|
||||||
item.Temperature = data.Temperature
|
item.Temperature = data.Temperature
|
||||||
item.KeyId = uint(data.KeyId)
|
item.KeyId = uint(data.KeyId)
|
||||||
item.Type = data.Type
|
item.Type = data.Type
|
||||||
@@ -100,12 +100,16 @@ func (h *ChatModelHandler) List(c *gin.Context) {
|
|||||||
session := h.DB.Session(&gorm.Session{})
|
session := h.DB.Session(&gorm.Session{})
|
||||||
enable := h.GetBool(c, "enable")
|
enable := h.GetBool(c, "enable")
|
||||||
name := h.GetTrim(c, "name")
|
name := h.GetTrim(c, "name")
|
||||||
|
modelType := h.GetTrim(c, "type")
|
||||||
if enable {
|
if enable {
|
||||||
session = session.Where("enabled", enable)
|
session = session.Where("enabled", enable)
|
||||||
}
|
}
|
||||||
if name != "" {
|
if name != "" {
|
||||||
session = session.Where("name LIKE ?", name+"%")
|
session = session.Where("name LIKE ?", name+"%")
|
||||||
}
|
}
|
||||||
|
if modelType != "" {
|
||||||
|
session = session.Where("type", modelType)
|
||||||
|
}
|
||||||
var items []model.ChatModel
|
var items []model.ChatModel
|
||||||
var cms = make([]vo.ChatModel, 0)
|
var cms = make([]vo.ChatModel, 0)
|
||||||
res := session.Order("sort_num ASC").Find(&items)
|
res := session.Order("sort_num ASC").Find(&items)
|
||||||
|
|||||||
@@ -5,20 +5,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ChatModel struct {
|
type ChatModel struct {
|
||||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||||
Description string `gorm:"column:description;type:varchar(1024);not null;default:'';comment:模型类型描述" json:"description"`
|
Desc string `gorm:"column:desc;type:varchar(1024);not null;default:'';comment:模型类型描述" json:"desc"`
|
||||||
Category string `gorm:"column:category;type:varchar(1024);not null;default:'';comment:模型类别" json:"category"`
|
Tag string `gorm:"column:tag;type:varchar(1024);not null;default:'';comment:模型标签" json:"tag"`
|
||||||
Type string `gorm:"column:type;type:varchar(10);not null;default:chat;comment:模型类型(chat,img)" json:"type"`
|
Type string `gorm:"column:type;type:varchar(10);not null;default:chat;comment:模型类型(chat,img)" json:"type"`
|
||||||
Name string `gorm:"column:name;type:varchar(255);not null;comment:模型名称" json:"name"`
|
Name string `gorm:"column:name;type:varchar(255);not null;comment:模型名称" json:"name"`
|
||||||
Value string `gorm:"column:value;type:varchar(255);not null;comment:模型值" json:"value"`
|
Value string `gorm:"column:value;type:varchar(255);not null;comment:模型值" json:"value"`
|
||||||
SortNum int `gorm:"column:sort_num;type:tinyint(1);not null;comment:排序数字" json:"sort_num"`
|
SortNum int `gorm:"column:sort_num;type:tinyint(1);not null;comment:排序数字" json:"sort_num"`
|
||||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;default:0;comment:是否启用模型" json:"enabled"`
|
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;default:0;comment:是否启用模型" json:"enabled"`
|
||||||
Power int `gorm:"column:power;type:smallint;not null;comment:消耗算力点数" json:"power"`
|
Power int `gorm:"column:power;type:smallint;not null;comment:消耗算力点数" json:"power"`
|
||||||
Temperature float32 `gorm:"column:temperature;type:float(3,1);not null;default:1.0;comment:模型创意度" json:"temperature"`
|
Temperature float32 `gorm:"column:temperature;type:float(3,1);not null;default:1.0;comment:模型创意度" json:"temperature"`
|
||||||
MaxTokens int `gorm:"column:max_tokens;type:int;not null;default:1024;comment:最大响应长度" json:"max_tokens"`
|
MaxTokens int `gorm:"column:max_tokens;type:int;not null;default:1024;comment:最大响应长度" json:"max_tokens"`
|
||||||
MaxContext int `gorm:"column:max_context;type:int;not null;default:4096;comment:最大上下文长度" json:"max_context"`
|
MaxContext int `gorm:"column:max_context;type:int;not null;default:4096;comment:最大上下文长度" json:"max_context"`
|
||||||
Open bool `gorm:"column:open;type:tinyint(1);not null;comment:是否开放模型" json:"open"`
|
Open bool `gorm:"column:open;type:tinyint(1);not null;comment:是否开放模型" json:"open"`
|
||||||
KeyId uint `gorm:"column:key_id;type:int;not null;comment:绑定API KEY ID" json:"key_id"`
|
KeyId uint `gorm:"column:key_id;type:int;not null;comment:绑定API KEY ID" json:"key_id"`
|
||||||
Options string `gorm:"column:options;type:text;not null;comment:模型自定义选项" json:"options"`
|
Options string `gorm:"column:options;type:text;not null;comment:模型自定义选项" json:"options"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
func NewGormConfig() *gorm.Config {
|
func NewGormConfig() *gorm.Config {
|
||||||
return &gorm.Config{
|
return &gorm.Config{
|
||||||
Logger: logger.Default.LogMode(logger.Error),
|
Logger: logger.Default.LogMode(logger.Warn),
|
||||||
NamingStrategy: schema.NamingStrategy{
|
NamingStrategy: schema.NamingStrategy{
|
||||||
TablePrefix: "chatgpt_", // 设置表前缀
|
TablePrefix: "chatgpt_", // 设置表前缀
|
||||||
SingularTable: false, // 使用单数表名形式
|
SingularTable: false, // 使用单数表名形式
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ type ChatModel struct {
|
|||||||
Open bool `json:"open"`
|
Open bool `json:"open"`
|
||||||
MaxTokens int `json:"max_tokens"` // 最大响应长度
|
MaxTokens int `json:"max_tokens"` // 最大响应长度
|
||||||
MaxContext int `json:"max_context"` // 最大上下文长度
|
MaxContext int `json:"max_context"` // 最大上下文长度
|
||||||
Description string `json:"description"` // 模型描述
|
Desc string `json:"desc"` // 模型描述
|
||||||
Category string `json:"category"` //模型类别
|
Tag string `json:"tag"` //模型标签
|
||||||
Temperature float32 `json:"temperature"` // 模型温度
|
Temperature float32 `json:"temperature"` // 模型温度
|
||||||
KeyId uint `json:"key_id,omitempty"`
|
KeyId uint `json:"key_id,omitempty"`
|
||||||
KeyName string `json:"key_name"`
|
KeyName string `json:"key_name"`
|
||||||
|
|||||||
@@ -3,6 +3,12 @@
|
|||||||
<div class="handle-box">
|
<div class="handle-box">
|
||||||
<el-input v-model="query.name" placeholder="模型名称" class="handle-input" />
|
<el-input v-model="query.name" placeholder="模型名称" class="handle-input" />
|
||||||
|
|
||||||
|
<el-select v-model="query.type" placeholder="模型类型" class="handle-input" clearable>
|
||||||
|
<el-option v-for="v in modelTypes" :value="v.value" :label="v.label" :key="v.value">
|
||||||
|
{{ v.label }}
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
|
||||||
<el-button :icon="Search" @click="fetchData">搜索</el-button>
|
<el-button :icon="Search" @click="fetchData">搜索</el-button>
|
||||||
<el-button type="primary" :icon="Plus" @click="add">新增</el-button>
|
<el-button type="primary" :icon="Plus" @click="add">新增</el-button>
|
||||||
</div>
|
</div>
|
||||||
@@ -25,7 +31,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column prop="category" label="标签" />
|
<el-table-column prop="tag" label="标签" />
|
||||||
<el-table-column prop="value" label="模型值">
|
<el-table-column prop="value" label="模型值">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<span>{{ scope.row.value }}</span>
|
<span>{{ scope.row.value }}</span>
|
||||||
@@ -34,13 +40,6 @@
|
|||||||
</el-icon>
|
</el-icon>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="description" label="模型描述" width="180">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-tooltip :content="scope.row.description || ''" placement="top" :show-after="200">
|
|
||||||
<div class="description-cell">{{ scope.row.description }}</div>
|
|
||||||
</el-tooltip>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column prop="power" label="费率" />
|
<el-table-column prop="power" label="费率" />
|
||||||
<el-table-column prop="max_tokens" label="最大响应长度" />
|
<el-table-column prop="max_tokens" label="最大响应长度" />
|
||||||
<el-table-column prop="max_context" label="最大上下文长度" />
|
<el-table-column prop="max_context" label="最大上下文长度" />
|
||||||
@@ -79,7 +78,7 @@
|
|||||||
<el-form :model="item" label-width="120px" ref="formRef" :rules="rules">
|
<el-form :model="item" label-width="120px" ref="formRef" :rules="rules">
|
||||||
<el-form-item label="模型类型:" prop="type">
|
<el-form-item label="模型类型:" prop="type">
|
||||||
<el-select v-model="item.type" placeholder="请选择模型类型">
|
<el-select v-model="item.type" placeholder="请选择模型类型">
|
||||||
<el-option v-for="v in type" :value="v.value" :label="v.label" :key="v.value">
|
<el-option v-for="v in modelTypes" :value="v.value" :label="v.label" :key="v.value">
|
||||||
{{ v.label }}
|
{{ v.label }}
|
||||||
</el-option>
|
</el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
@@ -92,8 +91,8 @@
|
|||||||
<el-input v-model="item.value" autocomplete="off" />
|
<el-input v-model="item.value" autocomplete="off" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="模型标签" prop="category">
|
<el-form-item label="模型标签" prop="tag">
|
||||||
<el-input v-model="item.category" autocomplete="off" />
|
<el-input v-model="item.tag" autocomplete="off" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="消耗算力:" prop="power">
|
<el-form-item label="消耗算力:" prop="power">
|
||||||
@@ -137,8 +136,8 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="模型描述" prop="description">
|
<el-form-item label="模型简介" prop="desc">
|
||||||
<el-input v-model="item.description" autocomplete="off" />
|
<el-input v-model="item.desc" type="textarea" :rows="3" autocomplete="off" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="创意度:" prop="temperature">
|
<el-form-item label="创意度:" prop="temperature">
|
||||||
@@ -237,7 +236,7 @@ const rules = reactive({
|
|||||||
})
|
})
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const formRef = ref(null)
|
const formRef = ref(null)
|
||||||
const type = ref([
|
const modelTypes = ref([
|
||||||
{ label: '聊天', value: 'chat' },
|
{ label: '聊天', value: 'chat' },
|
||||||
{ label: '绘图', value: 'img' },
|
{ label: '绘图', value: 'img' },
|
||||||
{ label: '语音', value: 'tts' },
|
{ label: '语音', value: 'tts' },
|
||||||
@@ -344,7 +343,7 @@ const add = function () {
|
|||||||
const edit = function (row) {
|
const edit = function (row) {
|
||||||
title.value = '修改模型'
|
title.value = '修改模型'
|
||||||
showDialog.value = true
|
showDialog.value = true
|
||||||
item.value = row
|
item.value = Object.assign({}, row)
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = function () {
|
const save = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user