refact & update new model

This commit is contained in:
Sakurasan
2024-09-13 21:32:10 +08:00
parent c11824f5aa
commit 7fd82b43f4
21 changed files with 1094 additions and 975 deletions

View File

@@ -53,6 +53,14 @@ func SelectKeyCache(apitype string) (Key, error) {
if item.Object.(Key).ApiType == "azure" {
keys = append(keys, item.Object.(Key))
}
if item.Object.(Key).ApiType == "github" {
keys = append(keys, item.Object.(Key))
}
}
if apitype == "claude" {
if item.Object.(Key).ApiType == "vertex" {
keys = append(keys, item.Object.(Key))
}
}
}
if len(keys) == 0 {

View File

@@ -2,9 +2,35 @@ package store
import (
"encoding/json"
"fmt"
"log"
"opencatd-open/pkg/vertexai"
"os"
"time"
)
func init() {
// check vertex
if os.Getenv("Vertex") != "" {
vertex_auth := os.Getenv("Vertex")
var Vertex vertexai.VertexSecretKey
if err := json.Unmarshal([]byte(vertex_auth), &Vertex); err != nil {
log.Fatalln(err)
return
}
key := Key{
ApiType: "vertex",
Name: Vertex.ProjectID,
Key: vertex_auth,
ApiSecret: vertex_auth,
}
if err := db.FirstOrCreate(&key).Error; err != nil {
log.Println(fmt.Errorf("create vertex key error: %v", err))
}
}
LoadKeysCache()
}
type Key struct {
ID uint `gorm:"primarykey" json:"id,omitempty"`
Key string `gorm:"unique;not null" json:"key,omitempty"`
@@ -14,6 +40,7 @@ type Key struct {
EndPoint string `gorm:"column:endpoint"`
ResourceNmae string `gorm:"column:resource_name"`
DeploymentName string `gorm:"column:deployment_name"`
ApiSecret string `gorm:"column:api_secret"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
}