File size: 2,582 Bytes
adc1e1c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | // Copyright (c) 2025 Tethys Plex
//
// This file is part of Veloera.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"encoding/json"
"fmt"
"log"
"veloera/model"
"veloera/service"
)
func main() {
// 初始化模型映射服务
if err := service.InitializeModelMappingService(); err != nil {
log.Fatalf("Failed to initialize model mapping service: %v", err)
}
// 创建示例模型映射配置
exampleMapping := &model.GlobalModelMapping{
Mapping: map[string][]model.ModelMappingItem{
"gpt-3.5-turbo": {
{Model: "gpt-3.5-turbo-0613", Priorities: 10},
{Model: "gpt-3.5-turbo-0301", Priorities: 10},
{Model: "gpt-3.5-turbo-16k", Priorities: 5},
},
"gpt-4": {
{Model: "gpt-4-0613", Priorities: 10},
{Model: "gpt-4-0314", Priorities: 8},
},
"claude-instant": {
{Model: "claude-instant-1.2", Priorities: 10},
{Model: "claude-instant-1.1", Priorities: 5},
},
},
}
// 更新全局模型映射配置
if err := service.UpdateGlobalModelMapping(exampleMapping); err != nil {
log.Fatalf("Failed to update global model mapping: %v", err)
}
// 获取实际模型名
testModels := []string{"gpt-3.5-turbo", "gpt-4", "claude-instant", "non-existent-model"}
fmt.Println("模型映射测试:")
for _, virtualModel := range testModels {
actualModel, err := service.GetActualModel(virtualModel)
if err != nil {
log.Printf("Error getting actual model for %s: %v", virtualModel, err)
continue
}
fmt.Printf("虚拟模型: %-20s -> 实际模型: %s\n", virtualModel, actualModel)
}
// 获取当前配置
currentConfig := service.GetGlobalModelMapping()
fmt.Println("\n当前全局模型映射配置:")
jsonData, _ := json.MarshalIndent(currentConfig, "", " ")
fmt.Println(string(jsonData))
// 重新加载配置
if err := service.ReloadModelMapping(); err != nil {
log.Printf("Failed to reload model mapping: %v", err)
} else {
fmt.Println("\n配置重新加载成功")
}
} |