fix select key
This commit is contained in:
@@ -11,7 +11,7 @@ if (import.meta.env.DEV) { // Vite 的方式判断开发环境
|
|||||||
|
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: baseURL,
|
baseURL: baseURL,
|
||||||
timeout: 5000,
|
timeout: 6000,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,17 +12,6 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="error" role="alert" class="alert shadow-lg bg-rose-100">
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 shrink-0 stroke-current" fill="none" viewBox="0 0 24 24">
|
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
|
||||||
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
|
||||||
</svg>
|
|
||||||
<div>
|
|
||||||
<span>Error! {{ error }}</span>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-sm" @click="error = null">X</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card border border-base-300/40 shadow-sm">
|
<div class="card border border-base-300/40 shadow-sm">
|
||||||
<form @submit.prevent="createApiKey" class="card-body space-y-5 p-3 sm:p-8">
|
<form @submit.prevent="createApiKey" class="card-body space-y-5 p-3 sm:p-8">
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
@@ -147,7 +136,7 @@
|
|||||||
<!-- <textarea id="support_models" v-model="newApiKey.support_models_text"
|
<!-- <textarea id="support_models" v-model="newApiKey.support_models_text"
|
||||||
placeholder='["model1", "model2"]' class="textarea textarea-sm textarea-bordered w-full"></textarea> -->
|
placeholder='["model1", "model2"]' class="textarea textarea-sm textarea-bordered w-full"></textarea> -->
|
||||||
<el-input-tag v-model="newApiKey.support_models_array" :trigger="'Enter'" clearable
|
<el-input-tag v-model="newApiKey.support_models_array" :trigger="'Enter'" clearable
|
||||||
placeholder="Please input" @change="onchange_supportmodel"/>
|
placeholder="Please input" @change="onchange_supportmodel" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
@@ -165,10 +154,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="error" role="alert" class="alert shadow-lg bg-rose-100">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 shrink-0 stroke-current" fill="none"
|
||||||
|
viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||||
|
</svg>
|
||||||
|
<div>
|
||||||
|
<span>{{ error }}</span>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-sm" @click="error = null">X</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end pt-4 items-center gap-2">
|
<div class="flex justify-end pt-4 items-center gap-2">
|
||||||
<button @click="cancel" class="btn btn-sm btn-outline">Cancel</button>
|
<button @click="cancel" class="btn btn-sm btn-outline">Cancel</button>
|
||||||
<button type="submit" class="btn btn-outline btn-sm px-4 text-sm font-medium btn-success" :disabled="!isFormValid">
|
<button type="submit" class="btn btn-outline btn-sm px-4 text-sm font-medium btn-success"
|
||||||
|
:disabled="!isFormValid">
|
||||||
Create
|
Create
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -249,7 +251,7 @@ const apiKeyImageMap = {
|
|||||||
'gemini': '/assets/gemini.svg',
|
'gemini': '/assets/gemini.svg',
|
||||||
'azure': '/assets/azure.svg',
|
'azure': '/assets/azure.svg',
|
||||||
'github': '/assets/github.svg'
|
'github': '/assets/github.svg'
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const apiKeyImageUrl = (keytype) => {
|
const apiKeyImageUrl = (keytype) => {
|
||||||
@@ -261,7 +263,7 @@ const createApiKey = async () => {
|
|||||||
setToast('Please fill in all required fields (Name, Type, API Key).', 'error')
|
setToast('Please fill in all required fields (Name, Type, API Key).', 'error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if (!Array.isArray(newApiKey.value.support_models_array)) {
|
if (!Array.isArray(newApiKey.value.support_models_array)) {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (a Api) CreateApiKey(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
if slice.Contain([]string{"openai", "azure", "claude"}, *newkey.ApiType) {
|
if slice.Contain([]string{"openai", "azure", "claude"}, *newkey.ApiType) {
|
||||||
sma, err := utils.FetchKeyModel(a.db, newkey)
|
sma, err := utils.FetchKeyModel(a.db, newkey)
|
||||||
if err == nil {
|
if err == nil && len(sma) > 0 {
|
||||||
newkey.SupportModelsArray = sma
|
newkey.SupportModelsArray = sma
|
||||||
var buf = new(bytes.Buffer)
|
var buf = new(bytes.Buffer)
|
||||||
json.NewEncoder(buf).Encode(sma) //nolint:errcheck
|
json.NewEncoder(buf).Encode(sma) //nolint:errcheck
|
||||||
|
|||||||
@@ -91,11 +91,11 @@ func (dao *ApiKeyDAO) FindApiKeysBySupportModel(db *gorm.DB, modelName string) (
|
|||||||
case "postgres":
|
case "postgres":
|
||||||
return nil, errors.New("not support")
|
return nil, errors.New("not support")
|
||||||
}
|
}
|
||||||
err := db.Model(&model.ApiKey{}).
|
err := db.Raw(`
|
||||||
Joins("CROSS JOIN JSON_EACH(apikeys.support_models)").
|
SELECT a.*
|
||||||
Where("active = true").
|
FROM apikeys a
|
||||||
Where("value = ?", modelName).
|
JOIN json_each(a.support_models) AS je ON je.value = ?
|
||||||
Find(&apiKeys).Error
|
WHERE a.active = true`, modelName).Scan(&apiKeys).Error
|
||||||
return apiKeys, err
|
return apiKeys, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ import (
|
|||||||
"opencatd-open/internal/model"
|
"opencatd-open/internal/model"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var client = &http.Client{}
|
var client = &http.Client{Timeout: 2 * time.Second}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if os.Getenv("LOCAL_PROXY") != "" {
|
if os.Getenv("LOCAL_PROXY") != "" {
|
||||||
@@ -29,13 +30,13 @@ func FetchKeyModel(db *gorm.DB, key *model.ApiKey) ([]string, error) {
|
|||||||
var err error
|
var err error
|
||||||
if *key.ApiType == "openai" || *key.ApiType == "azure" {
|
if *key.ApiType == "openai" || *key.ApiType == "azure" {
|
||||||
supportModels, err = FetchOpenAISupportModels(db, key)
|
supportModels, err = FetchOpenAISupportModels(db, key)
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if *key.ApiType == "claude" {
|
if *key.ApiType == "claude" {
|
||||||
supportModels, err = FetchClaudeSupportModels(db, key)
|
supportModels, err = FetchClaudeSupportModels(db, key)
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
return supportModels, err
|
return supportModels, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user