claude api support

This commit is contained in:
Sakurasan
2023-08-13 22:55:04 +08:00
parent b3b4f6bba1
commit 678928cafd
2 changed files with 226 additions and 0 deletions

View File

@@ -298,6 +298,30 @@ func HandleAddKey(c *gin.Context) {
}})
return
}
} else if strings.HasPrefix(body.Name, "anthropic.") {
keynames := strings.Split(body.Name, ".")
if len(keynames) < 2 {
c.JSON(http.StatusBadRequest, gin.H{"error": gin.H{
"message": "Invalid Key Name",
}})
return
}
if body.Endpoint == "" {
body.Endpoint = "https://api.anthropic.com"
}
k := &store.Key{
ApiType: "anthropic",
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 {