revert: Rework text model logic and update dependencies

- Rewrite model name for relay text
- Simplify logic and move logging statements
- Remove a check that filtered out models by model-mapping
- Remove abilities for the model mapping
- Lower numeric tolerance for test files
This commit is contained in:
Laisky.Cai
2024-03-01 02:14:32 +00:00
parent c849292621
commit ba827b95e3
6 changed files with 13 additions and 155 deletions

View File

@@ -55,21 +55,6 @@ func (channel *Channel) AddAbilities() error {
abilities = append(abilities, ability)
}
}
// add keys of model mapping to abilities
for model := range channel.GetModelMapping() {
for _, group := range groups_ {
ability := Ability{
Group: group,
Model: model,
ChannelId: channel.Id,
Enabled: channel.Status == common.ChannelStatusEnabled,
Priority: channel.Priority,
}
abilities = append(abilities, ability)
}
}
return DB.Create(&abilities).Error
}

View File

@@ -4,17 +4,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/songquanpeng/one-api/common"
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/common/logger"
"math/rand"
"sort"
"strconv"
"strings"
"sync"
"time"
gutils "github.com/Laisky/go-utils/v4"
"github.com/songquanpeng/one-api/common"
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/common/logger"
)
var (
@@ -156,13 +154,11 @@ func InitChannelCache() {
for group := range groups {
newGroup2model2channels[group] = make(map[string][]*Channel)
}
var supportedModels []string
for _, channel := range channels {
groups := strings.Split(channel.Group, ",")
for _, group := range groups {
models := strings.Split(channel.Models, ",")
for _, model := range models {
supportedModels = append(supportedModels, model)
if _, ok := newGroup2model2channels[group][model]; !ok {
newGroup2model2channels[group][model] = make([]*Channel, 0)
}
@@ -184,9 +180,7 @@ func InitChannelCache() {
channelSyncLock.Lock()
group2model2channels = newGroup2model2channels
channelSyncLock.Unlock()
supportedModels = gutils.UniqueStrings(supportedModels)
logger.SysLog(fmt.Sprintf("channels synced from database, support models: %q", strings.Join(supportedModels, ",")))
logger.SysLog("channels synced from database")
}
func SyncChannelCache(frequency int) {

View File

@@ -3,9 +3,6 @@ package model
import (
"encoding/json"
"fmt"
"strings"
"github.com/pkg/errors"
"github.com/songquanpeng/one-api/common"
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/common/helper"
@@ -118,34 +115,15 @@ func (channel *Channel) Insert() error {
return err
}
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
func (channel *Channel) Update() error {
var err error
err = DB.Model(channel).Updates(channel).Error
if err != nil {
return err
}
DB.Model(channel).First(channel, "id = ?", channel.Id)
if err = channel.UpdateAbilities(); err != nil {
logger.SysError("failed to update abilities: " + err.Error())
return errors.Wrap(err, "failed to update abilities")
}
return nil
err = channel.UpdateAbilities()
return err
}
func (channel *Channel) UpdateResponseTime(responseTime int64) {