mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 18:16:38 +08:00
Merge branch 'patch/model-mapping'
This commit is contained in:
commit
1a036d977e
@ -56,7 +56,7 @@ func (channel *Channel) AddAbilities() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add model mappings
|
// add keys of model mapping to abilities
|
||||||
for model := range channel.GetModelMapping() {
|
for model := range channel.GetModelMapping() {
|
||||||
for _, group := range groups_ {
|
for _, group := range groups_ {
|
||||||
ability := Ability{
|
ability := Ability{
|
||||||
|
@ -3,6 +3,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/songquanpeng/one-api/common"
|
"github.com/songquanpeng/one-api/common"
|
||||||
@ -117,8 +118,23 @@ func (channel *Channel) Insert() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (channel *Channel) Update() error {
|
func (channel *Channel) Update() (err error) {
|
||||||
var 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
|
err = DB.Model(channel).Updates(channel).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user