mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-11 02:43:44 +08:00
fix: #1054 Add model mapping to abilities
- Update Abilities model to include model mapping key - Parse model mapping in Channel model and filter models by model mapping in Update function
This commit is contained in:
@@ -3,6 +3,8 @@ package model
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/songquanpeng/one-api/common"
|
||||
"github.com/songquanpeng/one-api/common/config"
|
||||
"github.com/songquanpeng/one-api/common/helper"
|
||||
@@ -115,8 +117,23 @@ func (channel *Channel) Insert() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (channel *Channel) Update() error {
|
||||
var err error
|
||||
func (channel *Channel) Update() (err error) {
|
||||
// https://github.com/songquanpeng/one-api/issues/1054
|
||||
// for compatability, filter models by model-mapping.
|
||||
mapping := channel.GetModelMapping()
|
||||
if len(mapping) != 0 {
|
||||
models := strings.Split(channel.Models, ",")
|
||||
var filteredModels []string
|
||||
for _, model := range models {
|
||||
if _, ok := mapping[model]; ok {
|
||||
filteredModels = append(filteredModels, model)
|
||||
}
|
||||
}
|
||||
|
||||
channel.Models = strings.Join(filteredModels, ",")
|
||||
}
|
||||
|
||||
// update
|
||||
err = DB.Model(channel).Updates(channel).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user