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
|
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)
|
isPremium, isBasic := IsCurrentUserSubscribed(c)
|
||||||
|
|
||||||
out, err := settingPopoverTmpl.Execute(pongo2.Context{
|
out, err := settingPopoverTmpl.Execute(pongo2.Context{
|
||||||
@ -943,14 +943,13 @@ func LoadSettingsHandler(c *fiber.Ctx) error {
|
|||||||
"AnthropicExists": anthropicExists,
|
"AnthropicExists": anthropicExists,
|
||||||
"MistralExists": mistralExists,
|
"MistralExists": mistralExists,
|
||||||
"GroqExists": groqExists,
|
"GroqExists": groqExists,
|
||||||
"GooseaiExists": gooseaiExists,
|
|
||||||
"GoogleExists": googleExists,
|
"GoogleExists": googleExists,
|
||||||
"NimExists": nimExists,
|
"NimExists": nimExists,
|
||||||
"PerplexityExists": perplexityExists,
|
"PerplexityExists": perplexityExists,
|
||||||
"FireworksExists": fireworksExists,
|
"FireworksExists": fireworksExists,
|
||||||
"TogetherExists": togetherExists,
|
"TogetherExists": togetherExists,
|
||||||
"DeepseekExists": deepseekExists,
|
"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,
|
"isPremium": isPremium,
|
||||||
"isBasic": isBasic,
|
"isBasic": isBasic,
|
||||||
"StripeSubLink": stripeSubLink,
|
"StripeSubLink": stripeSubLink,
|
||||||
|
12
MyUtils.go
12
MyUtils.go
@ -75,10 +75,9 @@ func addCodeHeader(htmlContent string, languages []string) string {
|
|||||||
return updatedHTML
|
return updatedHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool) {
|
func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool, bool, bool, bool) {
|
||||||
// TODO: Optimize to use only one query
|
|
||||||
if edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}) == nil {
|
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
|
var userInfo User
|
||||||
@ -99,14 +98,13 @@ func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool,
|
|||||||
`, &userInfo)
|
`, &userInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error getting user keys", err)
|
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
|
openaiExists := false
|
||||||
anthropicExists := false
|
anthropicExists := false
|
||||||
mistralExists := false
|
mistralExists := false
|
||||||
groqExists := false
|
groqExists := false
|
||||||
gooseaiExists := false
|
|
||||||
nimExists := false
|
nimExists := false
|
||||||
googleExists := false
|
googleExists := false
|
||||||
perplexityExists := false
|
perplexityExists := false
|
||||||
@ -124,8 +122,6 @@ func getExistingKeysNew(c *fiber.Ctx) (bool, bool, bool, bool, bool, bool, bool,
|
|||||||
mistralExists = true
|
mistralExists = true
|
||||||
case "groq":
|
case "groq":
|
||||||
groqExists = true
|
groqExists = true
|
||||||
case "gooseai":
|
|
||||||
gooseaiExists = true
|
|
||||||
case "nim":
|
case "nim":
|
||||||
nimExists = true
|
nimExists = true
|
||||||
case "google":
|
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 {
|
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("Content-Type", "application/json")
|
||||||
req.Header.Set("Accept", "application/json")
|
|
||||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
44
main.go
44
main.go
@ -155,37 +155,41 @@ func addKeys(c *fiber.Ctx) error {
|
|||||||
"deepseek": TestDeepseekKey,
|
"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 {
|
for company, key := range keys {
|
||||||
if key != "" {
|
if key != "" {
|
||||||
if !testFunctions[company](key) {
|
if !testFunctions[company](key) {
|
||||||
return c.SendString(fmt.Sprintf("Invalid %s API Key\n", company))
|
return c.SendString(fmt.Sprintf("Invalid %s API Key\n", company))
|
||||||
}
|
}
|
||||||
|
|
||||||
var Exists bool
|
if keyExists[company] {
|
||||||
err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).QuerySingle(edgeCtx, `
|
err := edgeGlobalClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token")}).Execute(edgeCtx, `
|
||||||
select exists (
|
UPDATE Key
|
||||||
select global currentUser.setting.keys
|
FILTER .company.name = <str>$0 AND .<keys[IS Setting].<setting[IS User] = global currentUser
|
||||||
filter .company.name = <str>$0
|
SET {
|
||||||
);
|
key := <str>$1,
|
||||||
`, &Exists, company)
|
}
|
||||||
if err != nil {
|
`, company, key)
|
||||||
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
|
|
||||||
SET {
|
|
||||||
key := <str>$1,
|
|
||||||
}
|
|
||||||
`, company, key)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error updating key")
|
fmt.Println("Error updating key")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
WITH
|
||||||
c := (SELECT Company FILTER .name = <str>$0 LIMIT 1)
|
c := (SELECT Company FILTER .name = <str>$0 LIMIT 1)
|
||||||
UPDATE global currentUser.setting
|
UPDATE global currentUser.setting
|
||||||
|
Loading…
x
Reference in New Issue
Block a user