fix active key,suffix
This commit is contained in:
@@ -100,13 +100,13 @@
|
|||||||
class="input input-sm input-bordered w-full" />
|
class="input input-sm input-bordered w-full" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-control">
|
<!-- <div class="form-control">
|
||||||
<label for="deployment_name" class="label">
|
<label for="deployment_name" class="label">
|
||||||
<span class="label-text">Deployment Name</span>
|
<span class="label-text">Deployment Name</span>
|
||||||
</label>
|
</label>
|
||||||
<input id="deployment_name" type="text" v-model="newApiKey.deployment_name"
|
<input id="deployment_name" type="text" v-model="newApiKey.deployment_name"
|
||||||
placeholder="Deployment Name" class="input input-sm input-bordered w-full" />
|
placeholder="Deployment Name" class="input input-sm input-bordered w-full" />
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<label for="api_secret" class="label">
|
<label for="api_secret" class="label">
|
||||||
@@ -200,7 +200,7 @@ const newApiKey = ref({
|
|||||||
active: true,
|
active: true,
|
||||||
endpoint: '',
|
endpoint: '',
|
||||||
resource_name: '',
|
resource_name: '',
|
||||||
deployment_name: '',
|
// deployment_name: '',
|
||||||
api_secret: '',
|
api_secret: '',
|
||||||
model_prefix: '',
|
model_prefix: '',
|
||||||
model_alias: '',
|
model_alias: '',
|
||||||
@@ -217,7 +217,7 @@ const resetNewApiKey = () => {
|
|||||||
active: true,
|
active: true,
|
||||||
endpoint: '',
|
endpoint: '',
|
||||||
resource_name: '',
|
resource_name: '',
|
||||||
deployment_name: '',
|
// deployment_name: '',
|
||||||
api_secret: '',
|
api_secret: '',
|
||||||
model_prefix: '',
|
model_prefix: '',
|
||||||
model_alias: '',
|
model_alias: '',
|
||||||
|
|||||||
@@ -79,13 +79,13 @@
|
|||||||
class="input input-sm input-bordered w-full" />
|
class="input input-sm input-bordered w-full" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-control">
|
<!-- <div class="form-control">
|
||||||
<label for="deployment_name" class="label">
|
<label for="deployment_name" class="label">
|
||||||
<span class="label-text">Deployment Name</span>
|
<span class="label-text">Deployment Name</span>
|
||||||
</label>
|
</label>
|
||||||
<input id="deployment_name" type="text" v-model="key.deployment_name"
|
<input id="deployment_name" type="text" v-model="key.deployment_name"
|
||||||
placeholder="Deployment Name" class="input input-sm input-bordered w-full" />
|
placeholder="Deployment Name" class="input input-sm input-bordered w-full" />
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<label for="api_secret" class="label">
|
<label for="api_secret" class="label">
|
||||||
|
|||||||
@@ -126,7 +126,7 @@
|
|||||||
<!-- <td class="text-xs dark:text-white">{{ key.apikey }}</td> -->
|
<!-- <td class="text-xs dark:text-white">{{ key.apikey }}</td> -->
|
||||||
<!-- <td class="text-xs dark:text-white">{{ key.endpoint }}</td> -->
|
<!-- <td class="text-xs dark:text-white">{{ key.endpoint }}</td> -->
|
||||||
<td>
|
<td>
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-2">
|
||||||
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open" data-tip="预览">
|
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open" data-tip="预览">
|
||||||
<button class="btn btn-ghost btn-xs btn-square " @click="viewKey(key)">
|
<button class="btn btn-ghost btn-xs btn-square " @click="viewKey(key)">
|
||||||
<EyeIcon class="w-4 h-4 dark:text-white" />
|
<EyeIcon class="w-4 h-4 dark:text-white" />
|
||||||
|
|||||||
@@ -24,86 +24,81 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Table -->
|
<!-- Table -->
|
||||||
<div class="card card-bordered bg-base-100 shadow-sm mt-6" v-if="user">
|
<div class="card card-bordered bg-base-100 shadow-sm mt-6">
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card bg-base-100 shadow-xs overflow-x-auto dark:bg-base-200" v-if="user">
|
||||||
<h3 class="card-title text-lg">Tokens</h3>
|
<table class="table table-sm w-full">
|
||||||
<div v-if="user.tokens">
|
<thead>
|
||||||
|
<tr class="text-xs text-base-content/70 uppercase bg-base-200">
|
||||||
|
<th class="px-2 py-3">Token</th>
|
||||||
|
<th class="px-2 py-3">Status</th>
|
||||||
|
<!-- <th class="px-2 py-3">Key</th> -->
|
||||||
|
<th class="px-2 py-3">Expired</th>
|
||||||
|
<th class="px-2 py-3">Quota</th>
|
||||||
|
<th class="px-2 py-3">Used</th>
|
||||||
|
<th class="text-right px-2 py-3"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="token in user.tokens" :key="token.id" class="hover">
|
||||||
|
<td class="font-mono text-xs px-2 py-3">{{ token.name }}</td>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" class="toggle toggle-xs"
|
||||||
|
:class="token.active ? 'toggle-success' : 'toggle-error'" v-model="token.active"
|
||||||
|
@change="updateStatus(token)" />
|
||||||
|
</td>
|
||||||
|
<!-- <td class="font-mono text-xs px-2 py-3">{{ token.key }}</td> -->
|
||||||
|
<td class="px-2 py-3">{{ token.expired_at == 0 ? 'Never' : unixToDate(token.expired_at) }}</td>
|
||||||
|
<td class="px-2 py-3">
|
||||||
|
<template v-if="token.unlimited_quota">
|
||||||
|
<Infinity />
|
||||||
|
</template>
|
||||||
|
<template v-else>{{ token.quota }}</template>
|
||||||
|
</td>
|
||||||
|
<td class="px-2 py-3">{{ token.used_quota }}</td>
|
||||||
|
<td class="text-right px-1 py-3">
|
||||||
|
<div class="flex items-center gap-2.5">
|
||||||
|
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open pt-1" data-tip="预览">
|
||||||
|
<button class="btn btn-ghost btn-xs btn-square" onclick="" @click="viewToken(token)">
|
||||||
|
<EyeIcon class="w-5 h-5 dark:text-white" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
<div class="md:tooltip" data-tip="clean used">
|
||||||
|
<button class="btn btn-ghost btn-xs btn-square text-sky-300 mt-1" @click="cleanUsedToken(token)"
|
||||||
|
aria-label="Revoke token">
|
||||||
|
<Eraser class="w-5 h-5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p v-else class="text-center text-base-content/70 py-4">No tokens found</p>
|
<button v-if="token.name !== 'default'"
|
||||||
</div>
|
class="btn btn-ghost btn-xs btn-square text-error items-center" @click="confirmRevokeToken(token)"
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card bg-base-100 shadow-xs overflow-x-auto dark:bg-base-200" v-if="user">
|
|
||||||
<table class="table table-sm w-full">
|
|
||||||
<thead>
|
|
||||||
<tr class="text-xs text-base-content/70 uppercase bg-base-200">
|
|
||||||
<th class="px-2 py-3">Token</th>
|
|
||||||
<th class="px-2 py-3">Status</th>
|
|
||||||
<!-- <th class="px-2 py-3">Key</th> -->
|
|
||||||
<th class="px-2 py-3">Expired</th>
|
|
||||||
<th class="px-2 py-3">Quota</th>
|
|
||||||
<th class="px-2 py-3">Used</th>
|
|
||||||
<th class="text-right px-2 py-3"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr v-for="token in user.tokens" :key="token.id" class="hover">
|
|
||||||
<td class="font-mono text-xs px-2 py-3">{{ token.name }}</td>
|
|
||||||
<td>
|
|
||||||
<input type="checkbox" class="toggle toggle-xs" :class="token.active ? 'toggle-success' : 'toggle-error'"
|
|
||||||
v-model="token.active" @change="updateStatus(token)" />
|
|
||||||
</td>
|
|
||||||
<!-- <td class="font-mono text-xs px-2 py-3">{{ token.key }}</td> -->
|
|
||||||
<td class="px-2 py-3">{{ token.expired_at == 0 ? 'Never' : unixToDate(token.expired_at) }}</td>
|
|
||||||
<td class="px-2 py-3">
|
|
||||||
<template v-if="token.unlimited_quota">
|
|
||||||
<Infinity />
|
|
||||||
</template>
|
|
||||||
<template v-else>{{ token.quota }}</template>
|
|
||||||
</td>
|
|
||||||
<td class="px-2 py-3">{{ token.used_quota }}</td>
|
|
||||||
<td class="text-right px-1 py-3">
|
|
||||||
<div class="flex items-center gap-2.5">
|
|
||||||
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open pt-1" data-tip="预览">
|
|
||||||
<button class="btn btn-ghost btn-xs btn-square" onclick="" @click="viewToken(token)">
|
|
||||||
<EyeIcon class="w-5 h-5 dark:text-white" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<br />
|
|
||||||
<div class="md:tooltip" data-tip="clean used">
|
|
||||||
<button class="btn btn-ghost btn-xs btn-square text-sky-300 mt-1" @click="cleanUsedToken(token)"
|
|
||||||
aria-label="Revoke token">
|
aria-label="Revoke token">
|
||||||
<Eraser class="w-5 h-5" />
|
<TrashIcon class="w-5 h-5" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</td>
|
||||||
<button v-if="token.name !== 'default'" class="btn btn-ghost btn-xs btn-square text-error items-center"
|
</tr>
|
||||||
@click="confirmRevokeToken(token)" aria-label="Revoke token">
|
</tbody>
|
||||||
<TrashIcon class="w-5 h-5" />
|
</table>
|
||||||
</button>
|
<dialog id="myToken" class="modal" ref="tokenRef">
|
||||||
</div>
|
<div class="modal-box px-0 sm:px-8">
|
||||||
</td>
|
<form method="dialog">
|
||||||
</tr>
|
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>
|
||||||
</tbody>
|
</form>
|
||||||
</table>
|
<QRCodeCard :value="qrCodeValue" :size="120" />
|
||||||
<dialog id="myToken" class="modal" ref="tokenRef">
|
</div>
|
||||||
<div class="modal-box px-0 sm:px-8">
|
<form method="dialog" class="modal-backdrop">
|
||||||
<form method="dialog">
|
<button>关闭</button>
|
||||||
<button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button>
|
|
||||||
</form>
|
</form>
|
||||||
token
|
</dialog>
|
||||||
<QRCodeCard
|
</div>
|
||||||
:value="qrCodeValue"
|
|
||||||
:size="120" />
|
<p v-else class="text-center text-base-content/70 py-4">No tokens found</p>
|
||||||
</div>
|
|
||||||
<form method="dialog" class="modal-backdrop">
|
|
||||||
<button>关闭</button>
|
|
||||||
</form>
|
|
||||||
</dialog>
|
|
||||||
</div>
|
</div>
|
||||||
|
<!-- </div> -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -205,22 +200,6 @@ const viewToken = (token) => {
|
|||||||
|
|
||||||
const qrCodeValue = ref('');
|
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);
|
const modalRef = ref(null);
|
||||||
|
|||||||
@@ -125,13 +125,13 @@
|
|||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open" data-tip="预览">
|
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open" data-tip="预览">
|
||||||
<button class="btn btn-ghost btn-xs btn-square " @click="viewUser(user)">
|
<button class="btn btn-ghost btn-xs btn-square " @click="viewUser(user)">
|
||||||
<EyeIcon class="w-3.5 h-3.5 dark:text-white" />
|
<EyeIcon class="w-4 h-4 dark:text-white" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open" data-tip="删除" v-if="user.role < 20">
|
<div class="lg:tooltip lg:tooltip-top lg:tooltip-open" data-tip="删除" v-if="user.role < 20">
|
||||||
<button class="btn btn-ghost btn-xs btn-square text-error hover:bg-error/30"
|
<button class="btn btn-ghost btn-xs btn-square text-error hover:bg-error/30"
|
||||||
@click="confirmDeleteUser(user)">
|
@click="confirmDeleteUser(user)">
|
||||||
<TrashIcon class="w-3.5 h-3.5 dark:text-white" />
|
<TrashIcon class="w-4 h-4 dark:text-white" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"opencatd-open/internal/dao"
|
"opencatd-open/internal/dao"
|
||||||
"opencatd-open/internal/model"
|
"opencatd-open/internal/model"
|
||||||
|
"opencatd-open/internal/utils"
|
||||||
"opencatd-open/pkg/config"
|
"opencatd-open/pkg/config"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -187,7 +188,7 @@ func (p *Proxy) SelectApiKey(model string) error {
|
|||||||
|
|
||||||
if err != nil || len(akpikeys) == 0 {
|
if err != nil || len(akpikeys) == 0 {
|
||||||
if strings.HasPrefix(model, "gpt") || strings.HasPrefix(model, "o1") || strings.HasPrefix(model, "o3") || strings.HasPrefix(model, "o4") {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -195,7 +196,7 @@ func (p *Proxy) SelectApiKey(model string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(model, "gemini") {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -203,7 +204,7 @@ func (p *Proxy) SelectApiKey(model string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(model, "claude") {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -287,6 +288,9 @@ func (p *Proxy) getOpenAISupportModels(apikey model.ApiKey) ([]string, error) {
|
|||||||
var supportModels []string
|
var supportModels []string
|
||||||
var req *http.Request
|
var req *http.Request
|
||||||
if *apikey.ApiType == "azure" {
|
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, _ = http.NewRequest("GET", *apikey.Endpoint+azureModelsUrl, nil)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("api-key", *apikey.ApiKey)
|
req.Header.Set("api-key", *apikey.ApiKey)
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ func (dao *ApiKeyDAO) FindApiKeysBySupportModel(db *gorm.DB, modelName string) (
|
|||||||
}
|
}
|
||||||
err := db.Model(&model.ApiKey{}).
|
err := db.Model(&model.ApiKey{}).
|
||||||
Joins("CROSS JOIN JSON_EACH(apikeys.support_models)").
|
Joins("CROSS JOIN JSON_EACH(apikeys.support_models)").
|
||||||
|
Where("active = true").
|
||||||
Where("value = ?", modelName).
|
Where("value = ?", modelName).
|
||||||
Find(&apiKeys).Error
|
Find(&apiKeys).Error
|
||||||
return apiKeys, err
|
return apiKeys, err
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package model
|
|||||||
import "github.com/lib/pq" //pq.StringArray
|
import "github.com/lib/pq" //pq.StringArray
|
||||||
|
|
||||||
type ApiKey_PG struct {
|
type ApiKey_PG struct {
|
||||||
ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id,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"`
|
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"`
|
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"`
|
ApiKey *string `gorm:"column:apikey;not null;index:idx_apikey_apikey" json:"apikey,omitempty"`
|
||||||
Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
|
Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
|
||||||
Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
|
Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
|
||||||
ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
|
ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
|
||||||
DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
|
// DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
|
||||||
ApiSecret *string `gorm:"column:api_secret" json:"api_secret,omitempty"`
|
ApiSecret *string `gorm:"column:api_secret" json:"api_secret,omitempty"`
|
||||||
ModelPrefix *string `gorm:"column:model_prefix" json:"model_prefix,omitempty"`
|
ModelPrefix *string `gorm:"column:model_prefix" json:"model_prefix,omitempty"`
|
||||||
ModelAlias *string `gorm:"column:model_alias" json:"model_alias,omitempty"`
|
ModelAlias *string `gorm:"column:model_alias" json:"model_alias,omitempty"`
|
||||||
@@ -26,14 +26,14 @@ func (ApiKey_PG) TableName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ApiKey struct {
|
type ApiKey struct {
|
||||||
ID int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id,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"`
|
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"`
|
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"`
|
ApiKey *string `gorm:"column:apikey;not null;index:idx_apikey_apikey" json:"apikey,omitempty"`
|
||||||
Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
|
Active *bool `gorm:"column:active;default:true" json:"active,omitempty"`
|
||||||
Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
|
Endpoint *string `gorm:"column:endpoint" json:"endpoint,omitempty"`
|
||||||
ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
|
ResourceNmae *string `gorm:"column:resource_name" json:"resource_name,omitempty"`
|
||||||
DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
|
// DeploymentName *string `gorm:"column:deployment_name" json:"deployment_name,omitempty"`
|
||||||
AccessKey *string `gorm:"column:access_key" json:"access_key,omitempty"`
|
AccessKey *string `gorm:"column:access_key" json:"access_key,omitempty"`
|
||||||
SecretKey *string `gorm:"column:secret_key" json:"secret_key,omitempty"`
|
SecretKey *string `gorm:"column:secret_key" json:"secret_key,omitempty"`
|
||||||
ModelPrefix *string `gorm:"column:model_prefix" json:"model_prefix,omitempty"`
|
ModelPrefix *string `gorm:"column:model_prefix" json:"model_prefix,omitempty"`
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ func (s *ApiKeyServiceImpl) UpdateApiKey(ctx context.Context, apikey *model.ApiK
|
|||||||
if apikey.ResourceNmae != nil {
|
if apikey.ResourceNmae != nil {
|
||||||
_key.ResourceNmae = apikey.ResourceNmae
|
_key.ResourceNmae = apikey.ResourceNmae
|
||||||
}
|
}
|
||||||
if apikey.DeploymentName != nil {
|
|
||||||
_key.DeploymentName = apikey.DeploymentName
|
|
||||||
}
|
|
||||||
if apikey.AccessKey != nil {
|
if apikey.AccessKey != nil {
|
||||||
_key.AccessKey = apikey.AccessKey
|
_key.AccessKey = apikey.AccessKey
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ func FetchOpenAISupportModels(db *gorm.DB, apikey *model.ApiKey) ([]string, erro
|
|||||||
var supportModels []string
|
var supportModels []string
|
||||||
var req *http.Request
|
var req *http.Request
|
||||||
if *apikey.ApiType == "azure" {
|
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, _ = http.NewRequest("GET", *apikey.Endpoint+azureModelsUrl, nil)
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("api-key", *apikey.ApiKey)
|
req.Header.Set("api-key", *apikey.ApiKey)
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ func (o *OpenAICompatible) Chat(ctx context.Context, chatReq llm.ChatRequest) (*
|
|||||||
}
|
}
|
||||||
var buildurl string
|
var buildurl string
|
||||||
if *o.ApiKey.Endpoint != "" {
|
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)
|
buildurl = fmt.Sprintf("%s/openai/deployments/%s/chat/completions?api-version=%s", *o.ApiKey.Endpoint, formatModel(chatReq.Model), AzureApiVersion)
|
||||||
} else {
|
} else {
|
||||||
buildurl = fmt.Sprintf("https://%s.openai.azure.com/openai/deployments/%s/chat/completions?api-version=%s", *o.ApiKey.ResourceNmae, formatModel(chatReq.Model), AzureApiVersion)
|
buildurl = fmt.Sprintf("https://%s.openai.azure.com/openai/deployments/%s/chat/completions?api-version=%s", *o.ApiKey.ResourceNmae, formatModel(chatReq.Model), AzureApiVersion)
|
||||||
|
|||||||
Reference in New Issue
Block a user