mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	show license info in admin active page, optimize markdown generate prompt
This commit is contained in:
		@@ -119,11 +119,11 @@ type RedisConfig struct {
 | 
			
		||||
const LicenseKey = "Geek-AI-License"
 | 
			
		||||
 | 
			
		||||
type License struct {
 | 
			
		||||
	Key       string // 许可证书密钥
 | 
			
		||||
	MachineId string // 机器码
 | 
			
		||||
	UserNum   int    // 用户数量
 | 
			
		||||
	ExpiredAt int64  // 过期时间
 | 
			
		||||
	IsActive  bool   // 是否激活
 | 
			
		||||
	Key       string `json:"key"`        // 许可证书密钥
 | 
			
		||||
	MachineId string `json:"machine_id"` // 机器码
 | 
			
		||||
	UserNum   int    `json:"user_num"`   // 用户数量
 | 
			
		||||
	ExpiredAt int64  `json:"expired_at"` // 过期时间
 | 
			
		||||
	IsActive  bool   `json:"is_active"`  // 是否激活
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c RedisConfig) Url() string {
 | 
			
		||||
 
 | 
			
		||||
@@ -115,3 +115,9 @@ func (h *ConfigHandler) Active(c *gin.Context) {
 | 
			
		||||
 | 
			
		||||
	resp.SUCCESS(c, info.HostID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetLicense 获取 License 信息
 | 
			
		||||
func (h *ConfigHandler) GetLicense(c *gin.Context) {
 | 
			
		||||
	license := h.licenseService.GetLicense()
 | 
			
		||||
	resp.SUCCESS(c, license)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -103,7 +103,26 @@ func (h *MarkMapHandler) sendMessage(client *types.WsClient, prompt string, mode
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	messages := make([]interface{}, 0)
 | 
			
		||||
	messages = append(messages, types.Message{Role: "system", Content: "你是一位非常优秀的思维导图助手,你会把用户的所有提问都总结成思维导图,然后以 Markdown 格式输出。不要输出任何解释性的语句。"})
 | 
			
		||||
	messages = append(messages, types.Message{Role: "system", Content: `
 | 
			
		||||
你是一位非常优秀的思维导图助手,你会把用户的所有提问都总结成思维导图,然后以 Markdown 格式输出。markdown 只需要输出一级标题,二级标题,三级标题,四级标题,最多输出四级,除此之外不要输出任何其他 markdown 标记。下面是一个合格的例子:
 | 
			
		||||
# Geek-AI 助手
 | 
			
		||||
 | 
			
		||||
## 完整的开源系统
 | 
			
		||||
### 前端开源
 | 
			
		||||
### 后端开源
 | 
			
		||||
 | 
			
		||||
## 支持各种大模型
 | 
			
		||||
### OpenAI 
 | 
			
		||||
### Azure 
 | 
			
		||||
### 文心一言
 | 
			
		||||
### 通义千问
 | 
			
		||||
 | 
			
		||||
## 集成多种收费方式
 | 
			
		||||
### 支付宝
 | 
			
		||||
### 微信
 | 
			
		||||
 | 
			
		||||
另外,除此之外不要任何解释性语句。
 | 
			
		||||
`})
 | 
			
		||||
	messages = append(messages, types.Message{Role: "user", Content: prompt})
 | 
			
		||||
	var req = types.ApiRequest{
 | 
			
		||||
		Model:    chatModel.Value,
 | 
			
		||||
 
 | 
			
		||||
@@ -291,6 +291,7 @@ func main() {
 | 
			
		||||
			group.POST("config/update", h.Update)
 | 
			
		||||
			group.GET("config/get", h.Get)
 | 
			
		||||
			group.POST("active", h.Active)
 | 
			
		||||
			group.GET("config/get/license", h.GetLicense)
 | 
			
		||||
		}),
 | 
			
		||||
		fx.Invoke(func(s *core.AppServer, h *admin.ManagerHandler) {
 | 
			
		||||
			group := s.Engine.Group("/api/admin/")
 | 
			
		||||
 
 | 
			
		||||
@@ -64,13 +64,14 @@ func (s *LicenseService) ActiveLicense(license string, machineId string) error {
 | 
			
		||||
		return fmt.Errorf("激活失败:%v", res.Message)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = s.levelDB.Put(types.LicenseKey, types.License{
 | 
			
		||||
	s.license = types.License{
 | 
			
		||||
		Key:       license,
 | 
			
		||||
		MachineId: machineId,
 | 
			
		||||
		UserNum:   res.Data.UserNum,
 | 
			
		||||
		ExpiredAt: res.Data.ExpiredAt,
 | 
			
		||||
		IsActive:  true,
 | 
			
		||||
	})
 | 
			
		||||
	}
 | 
			
		||||
	err = s.levelDB.Put(types.LicenseKey, s.license)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return fmt.Errorf("保存许可证书失败:%v", err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -260,9 +260,42 @@
 | 
			
		||||
 | 
			
		||||
      <el-tab-pane label="授权激活" name="license">
 | 
			
		||||
        <div class="container">
 | 
			
		||||
          <el-descriptions
 | 
			
		||||
              v-if="license.is_active"
 | 
			
		||||
              class="margin-top"
 | 
			
		||||
              title="授权信息"
 | 
			
		||||
              :column="3"
 | 
			
		||||
              border
 | 
			
		||||
          >
 | 
			
		||||
            <el-descriptions-item :span="3" :width="150">
 | 
			
		||||
              <template #label>
 | 
			
		||||
                <div class="cell-item">License Key</div>
 | 
			
		||||
              </template>
 | 
			
		||||
              {{ license.key }}
 | 
			
		||||
            </el-descriptions-item>
 | 
			
		||||
            <el-descriptions-item>
 | 
			
		||||
              <template #label>
 | 
			
		||||
                <div class="cell-item">到期时间</div>
 | 
			
		||||
              </template>
 | 
			
		||||
              {{ dateFormat(license.expired_at) }}
 | 
			
		||||
            </el-descriptions-item>
 | 
			
		||||
            <el-descriptions-item>
 | 
			
		||||
              <template #label>
 | 
			
		||||
                <div class="cell-item">用户人数</div>
 | 
			
		||||
              </template>
 | 
			
		||||
              {{ license.user_num }}
 | 
			
		||||
            </el-descriptions-item>
 | 
			
		||||
            <el-descriptions-item>
 | 
			
		||||
              <template #label>
 | 
			
		||||
                <div class="cell-item">机器码</div>
 | 
			
		||||
              </template>
 | 
			
		||||
              {{ license.machine_id }}
 | 
			
		||||
            </el-descriptions-item>
 | 
			
		||||
          </el-descriptions>
 | 
			
		||||
 | 
			
		||||
          <el-form :model="system" label-width="150px" label-position="right">
 | 
			
		||||
            <el-form-item label="许可授权码" prop="license">
 | 
			
		||||
              <el-input v-model="license"/>
 | 
			
		||||
              <el-input v-model="licenseKey"/>
 | 
			
		||||
            </el-form-item>
 | 
			
		||||
 | 
			
		||||
            <el-form-item>
 | 
			
		||||
@@ -284,6 +317,7 @@ import {InfoFilled, UploadFilled} from "@element-plus/icons-vue";
 | 
			
		||||
import MdEditor from "md-editor-v3";
 | 
			
		||||
import 'md-editor-v3/lib/style.css';
 | 
			
		||||
import Menu from "@/views/admin/Menu.vue";
 | 
			
		||||
import {dateFormat} from "@/utils/libs";
 | 
			
		||||
 | 
			
		||||
const activeName = ref('basic')
 | 
			
		||||
const system = ref({models: []})
 | 
			
		||||
@@ -292,6 +326,7 @@ const systemFormRef = ref(null)
 | 
			
		||||
const models = ref([])
 | 
			
		||||
const openAIModels = ref([])
 | 
			
		||||
const notice = ref("")
 | 
			
		||||
const license = ref({is_active: false})
 | 
			
		||||
 | 
			
		||||
onMounted(() => {
 | 
			
		||||
  // 加载系统配置
 | 
			
		||||
@@ -315,8 +350,17 @@ onMounted(() => {
 | 
			
		||||
    ElMessage.error("获取模型失败:" + e.message)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  fetchLicense()
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
const fetchLicense = () => {
 | 
			
		||||
  httpGet("/api/admin/config/get/license").then(res => {
 | 
			
		||||
    license.value = res.data
 | 
			
		||||
  }).catch(e => {
 | 
			
		||||
    ElMessage.error("获取 License 失败:" + e.message)
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const rules = reactive({
 | 
			
		||||
  title: [{required: true, message: '请输入网站标题', trigger: 'blur',}],
 | 
			
		||||
  admin_title: [{required: true, message: '请输入控制台标题', trigger: 'blur',}],
 | 
			
		||||
@@ -345,13 +389,14 @@ const save = function (key) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 激活授权
 | 
			
		||||
const license = ref("")
 | 
			
		||||
const licenseKey = ref("")
 | 
			
		||||
const active = () => {
 | 
			
		||||
  if (license.value === "") {
 | 
			
		||||
  if (licenseKey.value === "") {
 | 
			
		||||
    return ElMessage.error("请输入授权码")
 | 
			
		||||
  }
 | 
			
		||||
  httpPost("/api/admin/active", {license: license.value}).then(res => {
 | 
			
		||||
  httpPost("/api/admin/active", {license: licenseKey.value}).then(res => {
 | 
			
		||||
    ElMessage.success("授权成功,机器编码为:" + res.data)
 | 
			
		||||
    fetchLicense()
 | 
			
		||||
  }).catch(e => {
 | 
			
		||||
    ElMessage.error(e.message)
 | 
			
		||||
  })
 | 
			
		||||
@@ -401,10 +446,9 @@ const onUploadImg = (files, callback) => {
 | 
			
		||||
  }).catch(e => {
 | 
			
		||||
    ElMessage.error('图片上传失败:' + e.message)
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style lang="stylus" scoped>
 | 
			
		||||
@@ -451,6 +495,10 @@ const onUploadImg = (files, callback) => {
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      .el-descriptions {
 | 
			
		||||
        margin-bottom 20px
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      .el-alert {
 | 
			
		||||
        margin-bottom 15px;
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user