🎨 优化模型配置 && 新增apikey功能 && 完善通用接口
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.echol.cn/loser/ai_proxy/server/global"
|
||||
"git.echol.cn/loser/ai_proxy/server/model/app"
|
||||
"git.echol.cn/loser/ai_proxy/server/model/common/request"
|
||||
@@ -41,3 +44,88 @@ func (s *AiPresetService) GetAiPresetList(info request.PageInfo, userID uint) (l
|
||||
err = db.Limit(limit).Offset(offset).Order("id desc").Find(&list).Error
|
||||
return
|
||||
}
|
||||
|
||||
// ParseImportedPreset 解析导入的预设,支持 SillyTavern 格式
|
||||
func (s *AiPresetService) ParseImportedPreset(rawData map[string]interface{}) (*app.AiPreset, error) {
|
||||
preset := &app.AiPreset{
|
||||
Enabled: true,
|
||||
}
|
||||
|
||||
// 处理名称字段 - 支持多种格式
|
||||
if name, ok := rawData["name"].(string); ok && name != "" {
|
||||
preset.Name = name
|
||||
} else if name, ok := rawData["preset_name"].(string); ok && name != "" {
|
||||
preset.Name = name
|
||||
} else if name, ok := rawData["presetName"].(string); ok && name != "" {
|
||||
preset.Name = name
|
||||
} else {
|
||||
return nil, fmt.Errorf("预设名称不能为空")
|
||||
}
|
||||
|
||||
// 处理描述
|
||||
if desc, ok := rawData["description"].(string); ok {
|
||||
preset.Description = desc
|
||||
}
|
||||
|
||||
// 处理参数
|
||||
if temp, ok := rawData["temperature"].(float64); ok {
|
||||
preset.Temperature = temp
|
||||
} else {
|
||||
preset.Temperature = 1.0
|
||||
}
|
||||
|
||||
if topP, ok := rawData["top_p"].(float64); ok {
|
||||
preset.TopP = topP
|
||||
} else {
|
||||
preset.TopP = 0.9
|
||||
}
|
||||
|
||||
if topK, ok := rawData["top_k"].(float64); ok {
|
||||
preset.TopK = int(topK)
|
||||
}
|
||||
|
||||
if maxTokens, ok := rawData["max_tokens"].(float64); ok {
|
||||
preset.MaxTokens = int(maxTokens)
|
||||
} else {
|
||||
preset.MaxTokens = 4096
|
||||
}
|
||||
|
||||
if freqPenalty, ok := rawData["frequency_penalty"].(float64); ok {
|
||||
preset.FrequencyPenalty = freqPenalty
|
||||
}
|
||||
|
||||
if presPenalty, ok := rawData["presence_penalty"].(float64); ok {
|
||||
preset.PresencePenalty = presPenalty
|
||||
}
|
||||
|
||||
// 处理提示词
|
||||
if prompts, ok := rawData["prompts"].([]interface{}); ok {
|
||||
promptsData, _ := json.Marshal(prompts)
|
||||
json.Unmarshal(promptsData, &preset.Prompts)
|
||||
}
|
||||
|
||||
// 处理提示词顺序
|
||||
if promptOrder, ok := rawData["prompt_order"].([]interface{}); ok {
|
||||
orderData, _ := json.Marshal(promptOrder)
|
||||
json.Unmarshal(orderData, &preset.PromptOrder)
|
||||
}
|
||||
|
||||
// 处理正则脚本
|
||||
if regexScripts, ok := rawData["regex_scripts"].([]interface{}); ok {
|
||||
scriptsData, _ := json.Marshal(regexScripts)
|
||||
json.Unmarshal(scriptsData, &preset.RegexScripts)
|
||||
}
|
||||
|
||||
// 处理扩展配置
|
||||
if extensions, ok := rawData["extensions"].(map[string]interface{}); ok {
|
||||
extData, _ := json.Marshal(extensions)
|
||||
json.Unmarshal(extData, &preset.Extensions)
|
||||
}
|
||||
|
||||
// 处理启用状态
|
||||
if enabled, ok := rawData["enabled"].(bool); ok {
|
||||
preset.Enabled = enabled
|
||||
}
|
||||
|
||||
return preset, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user