This commit is contained in:
Sakurasan
2024-04-21 00:27:35 +08:00
parent 8dbeeee9bf
commit 151757c2fe
5 changed files with 457 additions and 70 deletions

View File

@@ -325,6 +325,29 @@ func HandleAddKey(c *gin.Context) {
}})
return
}
} else if strings.HasPrefix(body.Name, "google.") {
keynames := strings.Split(body.Name, ".")
if len(keynames) < 2 {
c.JSON(http.StatusBadRequest, gin.H{"error": gin.H{
"message": "Invalid Key Name",
}})
return
}
k := &store.Key{
// ApiType: "anthropic",
ApiType: "google",
Name: body.Name,
Key: body.Key,
ResourceNmae: keynames[1],
EndPoint: body.Endpoint,
}
if err := store.CreateKey(k); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": gin.H{
"message": err.Error(),
}})
return
}
} else {
if body.ApiType == "" {
if err := store.AddKey("openai", body.Key, body.Name); err != nil {