+
-
-
Tokens
-
+
+
+
+
+ | Token |
+ Status |
+
+ Expired |
+ Quota |
+ Used |
+ |
+
+
+
+
+ | {{ token.name }} |
+
+
+ |
+
+ {{ token.expired_at == 0 ? 'Never' : unixToDate(token.expired_at) }} |
+
+
+
+
+ {{ token.quota }}
+ |
+ {{ token.used_quota }} |
+
+
+
+
+
- No tokens found
-
-
-
-
-
-
-
- | Token |
- Status |
-
- Expired |
- Quota |
- Used |
- |
-
-
-
-
- | {{ token.name }} |
-
-
- |
-
- {{ token.expired_at == 0 ? 'Never' : unixToDate(token.expired_at) }} |
-
-
-
-
- {{ token.quota }}
- |
- {{ token.used_quota }} |
-
-
-
-
-
-
-
-
-
-
-
- |
-
-
-
- |
+
+
+
+
-
-
+
+
+
+
No tokens found
+
+
+
@@ -205,22 +200,6 @@ const viewToken = (token) => {
const qrCodeValue = ref('');
-// 监听showTokenModel的变化,控制模态框的显示和隐藏
-// watch(showTokenModel, (newValue) => {
-// const dialog = tokenRef.value;
-// if (dialog) {
-// if (newValue) {
-// if (!dialog.hasAttribute('open')) {
-// dialog.showModal();
-// }
-// } else {
-// if (dialog.hasAttribute('open')) {
-// dialog.close();
-// }
-// }
-// }
-// });
-
// 关闭模态框
const modalRef = ref(null);
diff --git a/frontend/src/views/dashboard/User.vue b/frontend/src/views/dashboard/User.vue
index 28525aa..7d11e8e 100644
--- a/frontend/src/views/dashboard/User.vue
+++ b/frontend/src/views/dashboard/User.vue
@@ -125,13 +125,13 @@
diff --git a/internal/controller/proxy/proxy.go b/internal/controller/proxy/proxy.go
index 063c750..7891c8f 100644
--- a/internal/controller/proxy/proxy.go
+++ b/internal/controller/proxy/proxy.go
@@ -12,6 +12,7 @@ import (
"net/url"
"opencatd-open/internal/dao"
"opencatd-open/internal/model"
+ "opencatd-open/internal/utils"
"opencatd-open/pkg/config"
"os"
"strings"
@@ -187,7 +188,7 @@ func (p *Proxy) SelectApiKey(model string) error {
if err != nil || len(akpikeys) == 0 {
if strings.HasPrefix(model, "gpt") || strings.HasPrefix(model, "o1") || strings.HasPrefix(model, "o3") || strings.HasPrefix(model, "o4") {
- keys, err := p.apiKeyDao.FindKeys(map[string]any{"apitype = ?": "openai"})
+ keys, err := p.apiKeyDao.FindKeys(map[string]any{"active = ?": true, "apitype = ?": "openai"})
if err != nil {
return err
}
@@ -195,7 +196,7 @@ func (p *Proxy) SelectApiKey(model string) error {
}
if strings.HasPrefix(model, "gemini") {
- keys, err := p.apiKeyDao.FindKeys(map[string]any{"apitype = ?": "gemini"})
+ keys, err := p.apiKeyDao.FindKeys(map[string]any{"active = ?": true, "apitype = ?": "gemini"})
if err != nil {
return err
}
@@ -203,7 +204,7 @@ func (p *Proxy) SelectApiKey(model string) error {
}
if strings.HasPrefix(model, "claude") {
- keys, err := p.apiKeyDao.FindKeys(map[string]any{"apitype = ?": "claude"})
+ keys, err := p.apiKeyDao.FindKeys(map[string]any{"active = ?": true, "apitype = ?": "claude"})
if err != nil {
return err
}
@@ -287,6 +288,9 @@ func (p *Proxy) getOpenAISupportModels(apikey model.ApiKey) ([]string, error) {
var supportModels []string
var req *http.Request
if *apikey.ApiType == "azure" {
+ if strings.HasSuffix(*apikey.Endpoint, "/") {
+ apikey.Endpoint = utils.ToPtr(strings.TrimSuffix(*apikey.Endpoint, "/"))
+ }
req, _ = http.NewRequest("GET", *apikey.Endpoint+azureModelsUrl, nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("api-key", *apikey.ApiKey)
diff --git a/internal/dao/apikey.go b/internal/dao/apikey.go
index 5c67880..0173d0b 100644
--- a/internal/dao/apikey.go
+++ b/internal/dao/apikey.go
@@ -93,6 +93,7 @@ func (dao *ApiKeyDAO) FindApiKeysBySupportModel(db *gorm.DB, modelName string) (
}
err := db.Model(&model.ApiKey{}).
Joins("CROSS JOIN JSON_EACH(apikeys.support_models)").
+ Where("active = true").
Where("value = ?", modelName).
Find(&apiKeys).Error
return apiKeys, err
diff --git a/internal/model/apikey.go b/internal/model/apikey.go
index 47260b3..948a03f 100644
--- a/internal/model/apikey.go
+++ b/internal/model/apikey.go
@@ -3,14 +3,14 @@ package model
import "github.com/lib/pq" //pq.StringArray
type ApiKey_PG struct {
- ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id,omitempty"`
- Name *string `gorm:"column:name;not null;unique;index:idx_apikey_name" json:"name,omitempty"`
- ApiType *string `gorm:"column:apitype;not null;index:idx_apikey_apitype" json:"type,omitempty"`
- ApiKey *string `gorm:"column:apikey;not null;index:idx_apikey_apikey" json:"apikey,omitempty"`
- Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
- Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
- ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
- DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
+ ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id,omitempty"`
+ Name *string `gorm:"column:name;not null;unique;index:idx_apikey_name" json:"name,omitempty"`
+ ApiType *string `gorm:"column:apitype;not null;index:idx_apikey_apitype" json:"type,omitempty"`
+ ApiKey *string `gorm:"column:apikey;not null;index:idx_apikey_apikey" json:"apikey,omitempty"`
+ Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
+ Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
+ ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
+ // DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
ApiSecret *string `gorm:"column:api_secret" json:"api_secret,omitempty"`
ModelPrefix *string `gorm:"column:model_prefix" json:"model_prefix,omitempty"`
ModelAlias *string `gorm:"column:model_alias" json:"model_alias,omitempty"`
@@ -26,14 +26,14 @@ func (ApiKey_PG) TableName() string {
}
type ApiKey struct {
- ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id,omitempty"`
- Name *string `gorm:"column:name;not null;unique;index:idx_apikey_name" json:"name,omitempty"`
- ApiType *string `gorm:"column:apitype;not null;index:idx_apikey_apitype" json:"type,omitempty"`
- ApiKey *string `gorm:"column:apikey;not null;index:idx_apikey_apikey" json:"apikey,omitempty"`
- Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
- Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
- ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
- DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
+ ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id,omitempty"`
+ Name *string `gorm:"column:name;not null;unique;index:idx_apikey_name" json:"name,omitempty"`
+ ApiType *string `gorm:"column:apitype;not null;index:idx_apikey_apitype" json:"type,omitempty"`
+ ApiKey *string `gorm:"column:apikey;not null;index:idx_apikey_apikey" json:"apikey,omitempty"`
+ Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
+ Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
+ ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
+ // DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
AccessKey *string `gorm:"column:access_key" json:"access_key,omitempty"`
SecretKey *string `gorm:"column:secret_key" json:"secret_key,omitempty"`
ModelPrefix *string `gorm:"column:model_prefix" json:"model_prefix,omitempty"`
diff --git a/internal/service/apikey.go b/internal/service/apikey.go
index bda4ab8..32e8178 100644
--- a/internal/service/apikey.go
+++ b/internal/service/apikey.go
@@ -52,9 +52,6 @@ func (s *ApiKeyServiceImpl) UpdateApiKey(ctx context.Context, apikey *model.ApiK
if apikey.ResourceNmae != nil {
_key.ResourceNmae = apikey.ResourceNmae
}
- if apikey.DeploymentName != nil {
- _key.DeploymentName = apikey.DeploymentName
- }
if apikey.AccessKey != nil {
_key.AccessKey = apikey.AccessKey
}
diff --git a/internal/utils/fetchKeyModel.go b/internal/utils/fetchKeyModel.go
index d4ed65f..f5b3afd 100644
--- a/internal/utils/fetchKeyModel.go
+++ b/internal/utils/fetchKeyModel.go
@@ -47,6 +47,9 @@ func FetchOpenAISupportModels(db *gorm.DB, apikey *model.ApiKey) ([]string, erro
var supportModels []string
var req *http.Request
if *apikey.ApiType == "azure" {
+ if strings.HasSuffix(*apikey.Endpoint, "/") {
+ apikey.Endpoint = ToPtr(strings.TrimSuffix(*apikey.Endpoint, "/"))
+ }
req, _ = http.NewRequest("GET", *apikey.Endpoint+azureModelsUrl, nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("api-key", *apikey.ApiKey)
diff --git a/llm/openai_compatible/chat.go b/llm/openai_compatible/chat.go
index d0d0367..1933d23 100644
--- a/llm/openai_compatible/chat.go
+++ b/llm/openai_compatible/chat.go
@@ -86,6 +86,9 @@ func (o *OpenAICompatible) Chat(ctx context.Context, chatReq llm.ChatRequest) (*
}
var buildurl string
if *o.ApiKey.Endpoint != "" {
+ if strings.HasSuffix(*o.ApiKey.Endpoint, "/") {
+ o.ApiKey.ApiKey = utils.ToPtr(strings.TrimSuffix(*o.ApiKey.Endpoint, "/"))
+ }
buildurl = fmt.Sprintf("%s/openai/deployments/%s/chat/completions?api-version=%s", *o.ApiKey.Endpoint, formatModel(chatReq.Model), AzureApiVersion)
} else {
buildurl = fmt.Sprintf("https://%s.openai.azure.com/openai/deployments/%s/chat/completions?api-version=%s", *o.ApiKey.ResourceNmae, formatModel(chatReq.Model), AzureApiVersion)