Fix updating API key and removed gooseai
This commit is contained in:
parent
1d034e82d4
commit
5a0c352ccd
5
Chat.go
5
Chat.go
@ -934,7 +934,7 @@ func LoadSettingsHandler(c *fiber.Ctx) error {
|
||||
|
||||
stripeSubLink := "https://billing.stripe.com/p/login/6oE6sc0PTfvq1Hi288?prefilled_email=" + user.Email
|
||||
|
||||
openaiExists, anthropicExists, mistralExists, groqExists, gooseaiExists, googleExists, perplexityExists, fireworksExists, nimExists, togetherExists, deepseekExists := getExistingKeysNew(c)
|
||||
openaiExists, anthropicExists, mistralExists, groqExists, googleExists, perplexityExists, fireworksExists, nimExists, togetherExists, deepseekExists := getExistingKeysNew(c)
|
||||
isPremium, isBasic := IsCurrentUserSubscribed(c)
|
||||
|
||||
out, err := settingPopoverTmpl.Execute(pongo2.Context{
|
||||
@ -943,14 +943,13 @@ func LoadSettingsHandler(c *fiber.Ctx) error {
|
||||
"AnthropicExists": anthropicExists,
|
||||
"MistralExists": mistralExists,
|
||||
"GroqExists": groqExists,
|
||||
"GooseaiExists": gooseaiExists,
|
||||
"GoogleExists": googleExists,
|
||||
"NimExists": nimExists,
|
||||
"PerplexityExists": perplexityExists,
|
||||
"FireworksExists": fireworksExists,
|
||||
"TogetherExists": togetherExists,
|
||||
"DeepseekExists": deepseekExists,
|
||||
"AnyExists": fireworksExists || openaiExists || anthropicExists || mistralExists || groqExists || gooseaiExists || googleExists || perplexityExists || nimExists || togetherExists || deepseekExists,
|
||||
"AnyExists": fireworksExists || openaiExists || anthropicExists || mistralExists || groqExists || googleExists || perplexityExists || nimExists || togetherExists || deepseekExists,
|
||||
"isPremium": isPremium,
|
||||
"isBasic": isBasic,
|
||||
"StripeSubLink": stripeSubLink,
|
||||
|
12
MyUtils.go
12
MyUtils.go
@ -75,10 +75,9 @@ func addCodeHeader(htmlContent string, languages []string) string {
|
||||
return updatedHTML
|
||||
}
|
||||
|
||||
func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool) {
|
||||
// TODO: Optimize to use only one query
|
||||
func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool, bool, bool, bool) {
|
||||
if edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}) == nil {
|
||||
return false, false, false, false, false, false, false, false, false, false, false
|
||||
return false, false, false, false, false, false, false, false, false, false
|
||||
}
|
||||
|
||||
var userInfo User
|
||||
@ -99,14 +98,13 @@ func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool,
|
||||
`, &userInfo)
|
||||
if err != nil {
|
||||
fmt.Println("Error getting user keys", err)
|
||||
return false, false, false, false, false, false, false, false, false, false, false
|
||||
return false, false, false, false, false, false, false, false, false, false
|
||||
}
|
||||
|
||||
openaiExists := false
|
||||
anthropicExists := false
|
||||
mistralExists := false
|
||||
groqExists := false
|
||||
gooseaiExists := false
|
||||
nimExists := false
|
||||
googleExists := false
|
||||
perplexityExists := false
|
||||
@ -124,8 +122,6 @@ func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool,
|
||||
mistralExists = true
|
||||
case "groq":
|
||||
groqExists = true
|
||||
case "gooseai":
|
||||
gooseaiExists = true
|
||||
case "nim":
|
||||
nimExists = true
|
||||
case "google":
|
||||
@ -141,7 +137,7 @@ func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool,
|
||||
}
|
||||
}
|
||||
|
||||
return openaiExists, anthropicExists, mistralExists, groqExists, gooseaiExists, googleExists, perplexityExists, fireworksExists, nimExists, togetherExists, deepseekExists
|
||||
return openaiExists, anthropicExists, mistralExists, groqExists, googleExists, perplexityExists, fireworksExists, nimExists, togetherExists, deepseekExists
|
||||
}
|
||||
|
||||
func Message2RequestMessage(messages []Message, context string) []RequestMessage {
|
||||
|
@ -39,7 +39,6 @@ func TestMistralKey(apiKey string) bool {
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Accept", "application/json")
|
||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||
|
||||
client := &http.Client{}
|
||||
|
36
main.go
36
main.go
@ -155,27 +155,31 @@ func addKeys(c *fiber.Ctx) error {
|
||||
"deepseek": TestDeepseekKey,
|
||||
}
|
||||
|
||||
openaiExists, anthropicExists, mistralExists, groqExists, googleExists, perplexityExists, fireworksExists, nimExists, togetherExists, deepseekExists := getExistingKeysNew(c)
|
||||
|
||||
keyExists := map[string]bool{
|
||||
"openai": openaiExists,
|
||||
"anthropic": anthropicExists,
|
||||
"mistral": mistralExists,
|
||||
"groq": groqExists,
|
||||
"google": googleExists,
|
||||
"nim": nimExists,
|
||||
"perplexity": perplexityExists,
|
||||
"fireworks": fireworksExists,
|
||||
"together": togetherExists,
|
||||
"deepseek": deepseekExists,
|
||||
}
|
||||
|
||||
for company, key := range keys {
|
||||
if key != "" {
|
||||
if !testFunctions[company](key) {
|
||||
return c.SendString(fmt.Sprintf("Invalid %s API Key\n", company))
|
||||
}
|
||||
|
||||
var Exists bool
|
||||
err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).QuerySingle(edgeCtx, `
|
||||
select exists (
|
||||
select global currentUser.setting.keys
|
||||
filter .company.name = <str>$0
|
||||
);
|
||||
`, &Exists, company)
|
||||
if err != nil {
|
||||
fmt.Println("Error checking if key exists")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if Exists {
|
||||
err = edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).Execute(edgeCtx, `
|
||||
UPDATE Key filter .company.name = <str>$0 AND .key = <str>$1
|
||||
if keyExists[company] {
|
||||
err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).Execute(edgeCtx, `
|
||||
UPDATE Key
|
||||
FILTER .company.name = <str>$0 AND .<keys[IS Setting].<setting[IS User] = global currentUser
|
||||
SET {
|
||||
key := <str>$1,
|
||||
}
|
||||
@ -185,7 +189,7 @@ func addKeys(c *fiber.Ctx) error {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
err = edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).Execute(edgeCtx, `
|
||||
err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).Execute(edgeCtx, `
|
||||
WITH
|
||||
c := (SELECT Company FILTER .name = <str>$0 LIMIT 1)
|
||||
UPDATE global currentUser.setting
|
||||
|
Loading…
x
Reference in New Issue
Block a user