diff --git a/Chat.go b/Chat.go index 10742d3..ec52b15 100644 --- a/Chat.go +++ b/Chat.go @@ -16,7 +16,6 @@ import ( func ChatPageHandler(c *fiber.Ctx) error { authCookie := c.Cookies("jade-edgedb-auth-token", "") - fmt.Println("Main page") if authCookie != "" && !checkIfLogin() { edgeClient = edgeClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": authCookie}) @@ -43,7 +42,7 @@ func DeleteMessageHandler(c *fiber.Ctx) error { messageUUID, err := edgedb.ParseUUID(messageId) if err != nil { - fmt.Print("Error parsing UUID") + fmt.Println("Error parsing UUID") panic(err) } @@ -55,7 +54,7 @@ func DeleteMessageHandler(c *fiber.Ctx) error { FILTER .position >= messageArea.position AND .conversation = messageArea.conversation; `, messageUUID) if err != nil { - fmt.Print("Error deleting messages") + fmt.Println("Error deleting messages") panic(err) } @@ -88,12 +87,12 @@ type TemplateMessage struct { } func generateChatHTML() string { - // Print the name of the current conversation + // Println the name of the current conversation var currentConv Conversation err := edgeClient.QuerySingle(edgeCtx, ` SELECT global currentConversation { name }`, ¤tConv) if err != nil { - fmt.Print("Error getting current conversation") + fmt.Println("Error getting current conversation") panic(err) } fmt.Println("Current conversation: ", currentConv.Name) @@ -123,7 +122,7 @@ func generateChatHTML() string { ORDER BY .date ASC `, &Messages) if err != nil { - fmt.Print("Error getting messages") + fmt.Println("Error getting messages") panic(err) } @@ -136,7 +135,7 @@ func generateChatHTML() string { htmlContent := markdownToHTML(message.Content) userOut, err := userTmpl.Execute(pongo2.Context{"Content": htmlContent, "ID": message.ID.String()}) if err != nil { - fmt.Print("Error executing user template") + fmt.Println("Error executing user template") panic(err) } htmlString += userOut @@ -169,7 +168,7 @@ func generateChatHTML() string { botOut, err := botTmpl.Execute(pongo2.Context{"Messages": templateMessages, "ConversationAreaId": i}) if err != nil { - fmt.Print("Error executing bot template") + fmt.Println("Error executing bot template") panic(err) } htmlString += botOut @@ -198,13 +197,13 @@ func GetUserMessageHandler(c *fiber.Ctx) error { .id = $0; `, &selectedMessage, messageUUID) if err != nil { - fmt.Print("Error getting message") + fmt.Println("Error getting message") panic(err) } out, err := userTmpl.Execute(pongo2.Context{"Content": markdownToHTML(selectedMessage.Content), "ID": id}) if err != nil { - fmt.Print("Error executing user template") + fmt.Println("Error executing user template") panic(err) } @@ -293,7 +292,7 @@ func generateWelcomeChatHTML() string { botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) if err != nil { - fmt.Print("Error executing bot template") + fmt.Println("Error executing bot template") panic(err) } htmlString += botOut @@ -329,7 +328,7 @@ func generateEnterKeyChatHTML() string { botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) if err != nil { - fmt.Print("Error executing bot template") + fmt.Println("Error executing bot template") panic(err) } htmlString += botOut @@ -373,7 +372,7 @@ func generateTermAndServiceChatHTML() string { botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) if err != nil { - fmt.Print("Error executing bot template") + fmt.Println("Error executing bot template") panic(err) } htmlString += botOut @@ -390,7 +389,7 @@ func generateLimitReachedChatHTML() string { var result User err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id, email } LIMIT 1;", &result) if err != nil { - fmt.Print("Error getting current user") + fmt.Println("Error getting current user") panic(err) } @@ -418,7 +417,7 @@ func generateLimitReachedChatHTML() string { botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) if err != nil { - fmt.Print("Error executing bot template") + fmt.Println("Error executing bot template") panic(err) } htmlString += botOut @@ -440,7 +439,7 @@ func GetEditMessageFormHandler(c *fiber.Ctx) error { FILTER .id = $0; `, &message, idUUID) if err != nil { - fmt.Print("Error getting message") + fmt.Println("Error getting message") panic(err) } @@ -453,7 +452,7 @@ func GetEditMessageFormHandler(c *fiber.Ctx) error { tmpl := pongo2.Must(pongo2.FromFile("views/partials/message-edit-form.html")) out, err := tmpl.Execute(pongo2.Context{"Content": message.Content, "ID": id, "Rows": rows}) if err != nil { - fmt.Print("Error executing user template") + fmt.Println("Error executing user template") panic(err) } return c.SendString(out) @@ -466,7 +465,7 @@ func RedoMessageHandler(c *fiber.Ctx) error { var selectedLLMIds []string err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) if err != nil { - fmt.Print("Error unmarshalling selected LLM IDs") + fmt.Println("Error unmarshalling selected LLM IDs") panic(err) } @@ -476,7 +475,7 @@ func RedoMessageHandler(c *fiber.Ctx) error { FILTER .id = $0; `, &message, messageUUID) if err != nil { - fmt.Print("Error getting message") + fmt.Println("Error getting message") panic(err) } @@ -488,7 +487,7 @@ func RedoMessageHandler(c *fiber.Ctx) error { FILTER .position > messageArea.position AND .conversation = messageArea.conversation AND .conversation.user = global currentUser; `, messageUUID) if err != nil { - fmt.Print("Error deleting messages") + fmt.Println("Error deleting messages") panic(err) } @@ -503,7 +502,7 @@ func EditMessageHandler(c *fiber.Ctx) error { var selectedLLMIds []string err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) if err != nil { - fmt.Print("Error unmarshalling selected LLM IDs") + fmt.Println("Error unmarshalling selected LLM IDs") panic(err) } @@ -519,7 +518,7 @@ func EditMessageHandler(c *fiber.Ctx) error { FILTER .position >= messageArea.position AND .conversation = messageArea.conversation AND .conversation.user = global currentUser; `, messageUUID) if err != nil { - fmt.Print("Error deleting messages") + fmt.Println("Error deleting messages") panic(err) } @@ -533,7 +532,7 @@ func ClearChatHandler(c *fiber.Ctx) error { FILTER .conversation = global currentConversation; `) if err != nil { - fmt.Print("Error deleting messages") + fmt.Println("Error deleting messages") panic(err) } @@ -553,7 +552,7 @@ func LoadUsageKPIHandler(c *fiber.Ctx) error { var InputDate time.Time InputDate, err := time.Parse("01-2006", InputDateID) if err != nil { - fmt.Print("Error parsing date") + fmt.Println("Error parsing date") panic(err) } @@ -594,7 +593,7 @@ func LoadUsageKPIHandler(c *fiber.Ctx) error { } FILTER .total_count > 0 ORDER BY .total_cost DESC `, &usages, InputDate, InputDate.AddDate(0, 1, 0)) if err != nil { - fmt.Print("Error getting usage") + fmt.Println("Error getting usage") panic(err) } @@ -618,7 +617,7 @@ func LoadUsageKPIHandler(c *fiber.Ctx) error { "IsActive": IsActive, }) if err != nil { - fmt.Print("Error generating usage") + fmt.Println("Error generating usage") panic(err) } @@ -642,7 +641,7 @@ func LoadKeysHandler(c *fiber.Ctx) error { "AnyExists": openaiExists || anthropicExists || mistralExists || groqExists || gooseaiExists || googleExists, }) if err != nil { - fmt.Print("Error loading keys") + fmt.Println("Error loading keys") panic(err) } return c.SendString(out) @@ -671,7 +670,7 @@ func GenerateModelPopoverHTML(refresh bool) string { ORDER BY .position `, &llms) if err != nil { - fmt.Print("Error loading LLMs") + fmt.Println("Error loading LLMs") panic(err) } @@ -692,7 +691,7 @@ func GenerateModelPopoverHTML(refresh bool) string { "IsSub": IsCurrentUserSubscribed(), }) if err != nil { - fmt.Print("Error generating model popover") + fmt.Println("Error generating model popover") panic(err) } return out @@ -717,7 +716,7 @@ func GenerateConversationPopoverHTML(isActive bool) string { ORDER BY .position `, &conversations) if err != nil { - fmt.Print("Error loading conversations") + fmt.Println("Error loading conversations") panic(err) } @@ -726,7 +725,7 @@ func GenerateConversationPopoverHTML(isActive bool) string { "IsActive": isActive, }) if err != nil { - fmt.Print("Error generating conversation popover") + fmt.Println("Error generating conversation popover") panic(err) } return out @@ -758,7 +757,7 @@ func LoadSettingsHandler(c *fiber.Ctx) error { FILTER .id = global currentUser.id `, &user) if err != nil { - fmt.Print("Error loading user") + fmt.Println("Error loading user") panic(err) } @@ -782,7 +781,7 @@ func LoadSettingsHandler(c *fiber.Ctx) error { "StripeSubLink": stripeSubLink, }) if err != nil { - fmt.Print("Error loading settings") + fmt.Println("Error loading settings") panic(err) } return c.SendString(out) @@ -807,7 +806,7 @@ func CreateConversationHandler(c *fiber.Ctx) error { } `, name) if err != nil { - fmt.Print("Error creating conversation") + fmt.Println("Error creating conversation") panic(err) } @@ -819,7 +818,7 @@ func DeleteConversationHandler(c *fiber.Ctx) error { conversationUUID, err := edgedb.ParseUUID(conversationId) if err != nil { - fmt.Print("Error parsing UUID") + fmt.Println("Error parsing UUID") panic(err) } @@ -828,7 +827,7 @@ func DeleteConversationHandler(c *fiber.Ctx) error { FILTER .user = global currentUser AND .id = $0; `, conversationUUID) if err != nil { - fmt.Print("Error deleting conversation") + fmt.Println("Error deleting conversation") panic(err) } @@ -839,23 +838,11 @@ func SelectConversationHandler(c *fiber.Ctx) error { conversationId := c.FormValue("conversation-id") conversationUUID, err := edgedb.ParseUUID(conversationId) if err != nil { - fmt.Print("Error parsing UUID") + fmt.Println("Error parsing UUID") panic(err) } - fmt.Println("conversationUUID", conversationUUID.String()) - - err = edgeClient.Execute(edgeCtx, ` - SET global currentConversation := ( - SELECT Conversation - FILTER .id = $0 - LIMIT 1 - ); - `, conversationUUID) - if err != nil { - fmt.Print("Error selecting conversation") - panic(err) - } + edgeClient = edgeClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token"), "currentConversationID": conversationUUID}) return c.SendString(generateChatHTML()) } diff --git a/LLM.go b/LLM.go index 81b06e0..2519375 100644 --- a/LLM.go +++ b/LLM.go @@ -14,7 +14,7 @@ func deleteLLM(c *fiber.Ctx) error { var selectedLLMIds []string err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) if err != nil { - fmt.Print("Error unmarshalling selected LLM IDs") + fmt.Println("Error unmarshalling selected LLM IDs") panic(err) } @@ -28,7 +28,7 @@ func deleteLLM(c *fiber.Ctx) error { }; `, idUUID) if err != nil { - fmt.Print("Error deleting LLM") + fmt.Println("Error deleting LLM") panic(err) } } @@ -87,7 +87,7 @@ func createLLM(c *fiber.Ctx) error { }; `, name, systemPrompt, temperatureFloat, url, token, customID) // TODO Add real max token if err != nil { - fmt.Print("Error creating LLM") + fmt.Println("Error creating LLM") panic(err) } } else { @@ -104,7 +104,7 @@ func createLLM(c *fiber.Ctx) error { } `, name, systemPrompt, temperatureFloat, modelID) if err != nil { - fmt.Print("Error creating LLM") + fmt.Println("Error creating LLM") panic(err) } } @@ -126,7 +126,7 @@ func updateLLMPositionBatch(c *fiber.Ctx) error { for _, update := range positionUpdates { idUUID, err := edgedb.ParseUUID(update.ID) if err != nil { - fmt.Print("Error parsing UUID") + fmt.Println("Error parsing UUID") panic(err) } @@ -138,7 +138,7 @@ func updateLLMPositionBatch(c *fiber.Ctx) error { }; `, idUUID, int32(update.Position)) if err != nil { - fmt.Print("Error updating LLM position") + fmt.Println("Error updating LLM position") panic(err) } } @@ -157,7 +157,7 @@ func updateConversationPositionBatch(c *fiber.Ctx) error { fmt.Println(update.ID) idUUID, err := edgedb.ParseUUID(update.ID) if err != nil { - fmt.Print("Error parsing UUID") + fmt.Println("Error parsing UUID") panic(err) } @@ -169,7 +169,7 @@ func updateConversationPositionBatch(c *fiber.Ctx) error { }; `, idUUID, int32(update.Position)) if err != nil { - fmt.Print("Error updating conversation position") + fmt.Println("Error updating conversation position") panic(err) } } diff --git a/Request.go b/Request.go index 6e99846..6db238a 100644 --- a/Request.go +++ b/Request.go @@ -37,7 +37,7 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error { var selectedLLMIds []string err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) if err != nil { - fmt.Print("Error unmarshalling selected LLM IDs") + fmt.Println("Error unmarshalling selected LLM IDs") panic(err) } @@ -74,7 +74,7 @@ func GeneratePlaceholderHTML(message string, selectedLLMIds []string, with_user_ .id = $0; `, &selectedLLM, idUUID) if err != nil { - fmt.Print("Error getting LLM") + fmt.Println("Error getting LLM") panic(err) } selectedLLMs = append(selectedLLMs, selectedLLM) @@ -164,7 +164,7 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error { FILTER .id = $0; `, &message, messageID) if err != nil { - fmt.Print("Error getting message") + fmt.Println("Error getting message") panic(err) } @@ -193,7 +193,7 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error { "ConversationAreaId": message.Area.Position, }) if err != nil { - fmt.Print("Error generating HTML content") + fmt.Println("Error generating HTML content") panic(err) } outBtn = strings.ReplaceAll(outBtn, "\n", "") @@ -220,7 +220,7 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error { "ConversationAreaId": message.Area.Position, }) if err != nil { - fmt.Print("Error generating HTML content") + fmt.Println("Error generating HTML content") panic(err) } @@ -258,7 +258,7 @@ func addUsage(inputCost float32, outputCost float32, inputToken int32, outputTok } `, inputCost, outputCost, inputToken, outputToken, modelID) if err != nil { - fmt.Print("Error adding usage") + fmt.Println("Error adding usage") panic(err) } } diff --git a/RequestAnthropic.go b/RequestAnthropic.go index 54f3f9b..f7385a9 100644 --- a/RequestAnthropic.go +++ b/RequestAnthropic.go @@ -41,7 +41,7 @@ func addAnthropicMessage(llm LLM, selected bool) edgedb.UUID { chatCompletion, err := RequestAnthropic(llm.Model.ModelID, Messages, int(llm.Model.MaxToken), float64(llm.Temperature), llm.Context) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } else if len(chatCompletion.Content) == 0 { fmt.Println("No response from Anthropic") diff --git a/RequestGoogle.go b/RequestGoogle.go index 78e0815..db36fad 100644 --- a/RequestGoogle.go +++ b/RequestGoogle.go @@ -51,7 +51,7 @@ func addGoogleMessage(llm LLM, selected bool) edgedb.UUID { chatCompletion, err := RequestGoogle(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } else if len(chatCompletion.Choices) == 0 { fmt.Println("No response from Google") diff --git a/RequestGooseai.go b/RequestGooseai.go index c6a1dcf..958852a 100644 --- a/RequestGooseai.go +++ b/RequestGooseai.go @@ -38,7 +38,7 @@ func addGooseaiMessage(llm LLM, selected bool) edgedb.UUID { chatCompletion, err := RequestGooseai(llm.Model.ModelID, Messages, float64(llm.Temperature)) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } else if len(chatCompletion.Choices) == 0 { fmt.Println("No response from GooseAI") diff --git a/RequestGroq.go b/RequestGroq.go index 868f285..82a8315 100644 --- a/RequestGroq.go +++ b/RequestGroq.go @@ -42,7 +42,7 @@ func addGroqMessage(llm LLM, selected bool) edgedb.UUID { chatCompletion, err := RequestGroq(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } else if len(chatCompletion.Choices) == 0 { fmt.Println("No response from Groq") diff --git a/RequestHuggingface.go b/RequestHuggingface.go index 77a2b15..8cbb367 100644 --- a/RequestHuggingface.go +++ b/RequestHuggingface.go @@ -42,7 +42,7 @@ func addHuggingfaceMessage(llm LLM, selected bool) edgedb.UUID { chatCompletion, err := RequestHuggingface(llm, Messages, float64(llm.Temperature)) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } else if len(chatCompletion.Choices) == 0 { fmt.Println("No response from Endpoint") diff --git a/RequestMistral.go b/RequestMistral.go index 9144c48..8807e89 100644 --- a/RequestMistral.go +++ b/RequestMistral.go @@ -41,7 +41,7 @@ func addMistralMessage(llm LLM, selected bool) edgedb.UUID { chatCompletion, err := RequestMistral(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } else if len(chatCompletion.Choices) == 0 { id := insertBotMessage("No response from Mistral", selected, llm.ID) diff --git a/RequestOpenai.go b/RequestOpenai.go index 31f5af0..50cc523 100644 --- a/RequestOpenai.go +++ b/RequestOpenai.go @@ -42,7 +42,7 @@ func addOpenaiMessage(llm LLM, selected bool) edgedb.UUID { chatCompletion, err := RequestOpenai(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } else if len(chatCompletion.Choices) == 0 { fmt.Println("No response from OpenAI") diff --git a/Stripe.go b/Stripe.go index 1c6f231..13b6b75 100644 --- a/Stripe.go +++ b/Stripe.go @@ -22,7 +22,7 @@ func generatePricingTableChatHTML() string { var result User err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id, email } LIMIT 1;", &result) if err != nil { - fmt.Print("Error getting user") + fmt.Println("Error getting user") panic(err) } @@ -60,7 +60,7 @@ func generatePricingTableChatHTML() string { botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true, "notFlex": true}) if err != nil { - fmt.Print("Error executing template") + fmt.Println("Error executing template") panic(err) } htmlString += botOut @@ -87,12 +87,12 @@ func IsCurrentUserSubscribed() bool { var user User err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user) if err != nil { - fmt.Print("Error getting user") + fmt.Println("Error getting user") panic(err) } result, err := customer.Get(user.StripeID, nil) if err != nil { - fmt.Print("Error getting customer") + fmt.Println("Error getting customer") panic(err) } if result.Subscriptions.TotalCount == 0 { @@ -114,7 +114,7 @@ func IsCurrentUserLimiteReached() bool { SELECT count(U) `, &count) if err != nil { - fmt.Print("Error counting Usage") + fmt.Println("Error counting Usage") panic(err) } return count >= 500 @@ -124,7 +124,7 @@ func CreateClientSecretSession() string { var user User err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user) if err != nil { - fmt.Print("Error getting user") + fmt.Println("Error getting user") panic(err) } @@ -136,7 +136,7 @@ func CreateClientSecretSession() string { req, err := http.NewRequest(method, url, bytes.NewBuffer(payload)) if err != nil { - fmt.Print("failed to create request") + fmt.Println("failed to create request") panic(err) } req.Header.Add("Authorization", "Bearer "+apiKey) @@ -145,20 +145,20 @@ func CreateClientSecretSession() string { client := &http.Client{} resp, err := client.Do(req) if err != nil { - fmt.Print("failed to execute request") + fmt.Println("failed to execute request") panic(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { body, _ := io.ReadAll(resp.Body) - fmt.Print("failed to create customer session") + fmt.Println("failed to create customer session") panic(fmt.Sprintf("failed to create customer session: %s", string(body))) } body, err := io.ReadAll(resp.Body) if err != nil { - fmt.Print("failed to read response body") + fmt.Println("failed to read response body") panic(err) } @@ -169,7 +169,7 @@ func CreateClientSecretSession() string { var customerSession CustomerSessionResponse if err := json.Unmarshal(body, &customerSession); err != nil { - fmt.Print("failed to unmarshal response") + fmt.Println("failed to unmarshal response") panic(err) } diff --git a/database.go b/database.go index 5d319a7..310d95e 100644 --- a/database.go +++ b/database.go @@ -122,7 +122,7 @@ func init() { var ctx = context.Background() client, err := edgedb.CreateClient(ctx, edgedb.Options{}) if err != nil { - fmt.Print("Error connecting to edgedb") + fmt.Println("Error connecting to edgedb") panic(err) } @@ -148,7 +148,7 @@ func insertArea() (edgedb.UUID, int64) { } `, &inserted) if err != nil { - fmt.Print("Error inserting area") + fmt.Println("Error inserting area") panic(err) } @@ -180,11 +180,11 @@ func insertUserMessage(content string) edgedb.UUID { LIMIT 1 `, &lastArea) if err != nil { - fmt.Print("Error getting last area") + fmt.Println("Error getting last area") panic(err) } - var inserted struct{ id edgedb.UUID } + var inserted struct{ id edgedb.UUID } // TODO: Maybe remove that hard code LLM err = edgeClient.QuerySingle(edgeCtx, ` INSERT Message { role := $0, @@ -196,12 +196,12 @@ func insertUserMessage(content string) edgedb.UUID { conversation := global currentConversation, selected := true, llm := ( - SELECT LLM FILTER .id = "a32c43ec-12fc-11ef-9dc9-b38e0de8bff0" + SELECT LLM FILTER .id = "32cb4f0c-1c3f-11ef-9247-2fac0086a7d1" ) } `, &inserted, "user", content, lastArea.ID) if err != nil { - fmt.Print("Error inserting user message") + fmt.Println("Error inserting user message") panic(err) } return inserted.id @@ -218,7 +218,7 @@ func insertBotMessage(content string, selected bool, llmUUID edgedb.UUID) edgedb LIMIT 1 `, &lastArea) if err != nil { - fmt.Print("Error getting last area") + fmt.Println("Error getting last area") panic(err) } @@ -246,7 +246,7 @@ func insertBotMessage(content string, selected bool, llmUUID edgedb.UUID) edgedb } `, &inserted, "bot", llmUUID, content, selected, lastArea.ID) if err != nil { - fmt.Print("Error inserting bot message") + fmt.Println("Error inserting bot message") panic(err) } return inserted.id @@ -279,7 +279,7 @@ func getAllSelectedMessages() []Message { ORDER BY .date ASC `, &messages) if err != nil { - fmt.Print("Error getting messages") + fmt.Println("Error getting messages") panic(err) } diff --git a/dbschema/default.esdl b/dbschema/default.esdl index e3f9fba..d119b3c 100644 --- a/dbschema/default.esdl +++ b/dbschema/default.esdl @@ -8,10 +8,17 @@ module default { )) ); + required global currentConversationID: uuid { + default := "00000000-0000-0000-0000-000000000000" + }; + global currentConversation := ( assert_single(( - select Conversation - filter .name = 'Default' AND .user = global currentUser + select Conversation + filter .user = global currentUser AND ( + .id = global currentConversationID OR + (global currentConversationID = "00000000-0000-0000-0000-000000000000" AND .name = 'Default') + ) )) ); diff --git a/dbschema/migrations/00045-m1zlzfa.edgeql b/dbschema/migrations/00045-m1zlzfa.edgeql new file mode 100644 index 0000000..57736fc --- /dev/null +++ b/dbschema/migrations/00045-m1zlzfa.edgeql @@ -0,0 +1,12 @@ +CREATE MIGRATION m1zlzfafekdlqfpf7zcj4taysmccydrzclqrkxjogkermv4qcn4wia + ONTO m1xiilci36z6h4kris43l3gb6w63y7lbql3ismz7coxobr6r2yhz6a +{ + CREATE REQUIRED GLOBAL default::currentConversationID -> std::str { + SET default := ''; + }; + ALTER GLOBAL default::currentConversation USING (std::assert_single((SELECT + default::Conversation + FILTER + ((.user = GLOBAL default::currentUser) AND ((.id = GLOBAL default::currentConversationID) OR ((GLOBAL default::currentConversationID = '') AND (.name = 'Default')))) + ))); +}; diff --git a/dbschema/migrations/00046-m1f65xa.edgeql b/dbschema/migrations/00046-m1f65xa.edgeql new file mode 100644 index 0000000..e605a3e --- /dev/null +++ b/dbschema/migrations/00046-m1f65xa.edgeql @@ -0,0 +1,5 @@ +CREATE MIGRATION m1f65xatu7epwthdl6s4yekiuusexvyk2w747gdt5ixzzggxzliyga + ONTO m1zlzfafekdlqfpf7zcj4taysmccydrzclqrkxjogkermv4qcn4wia +{ + ALTER GLOBAL default::currentConversationID SET default := '00000000-0000-0000-0000-000000000000'; +}; diff --git a/dbschema/migrations/00047-m1nb4by.edgeql b/dbschema/migrations/00047-m1nb4by.edgeql new file mode 100644 index 0000000..b5739d1 --- /dev/null +++ b/dbschema/migrations/00047-m1nb4by.edgeql @@ -0,0 +1,14 @@ +CREATE MIGRATION m1nb4byflyh4jp3yp6zdr6ydzw7btucfslsznwz7ooywnmbjxqyl6q + ONTO m1f65xatu7epwthdl6s4yekiuusexvyk2w747gdt5ixzzggxzliyga +{ + DROP GLOBAL default::currentConversation; + DROP GLOBAL default::currentConversationID; + CREATE REQUIRED GLOBAL default::currentConversationID -> std::uuid { + SET default := ('00000000-0000-0000-0000-000000000000'); + }; + CREATE GLOBAL default::currentConversation := (std::assert_single((SELECT + default::Conversation + FILTER + ((.user = GLOBAL default::currentUser) AND ((.id = GLOBAL default::currentConversationID) OR ((GLOBAL default::currentConversationID = '00000000-0000-0000-0000-000000000000') AND (.name = 'Default')))) + ))); +}; diff --git a/login.go b/login.go index c442c06..6d31823 100644 --- a/login.go +++ b/login.go @@ -38,32 +38,32 @@ func getGoogleUserProfile(providerToken string) (string, string, string) { // Fetch the discovery document resp, err := http.Get("https://accounts.google.com/.well-known/openid-configuration") if err != nil { - fmt.Print("Error fetching discovery document") + fmt.Println("Error fetching discovery document") panic(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - fmt.Print("Error fetching discovery document") + fmt.Println("Error fetching discovery document") panic(resp.StatusCode) } body, err := io.ReadAll(resp.Body) if err != nil { - fmt.Print("Error reading discovery document") + fmt.Println("Error reading discovery document") panic(err) } var discoveryDocument DiscoveryDocument if err := json.Unmarshal(body, &discoveryDocument); err != nil { - fmt.Print("Error unmarshalling discovery document") + fmt.Println("Error unmarshalling discovery document") panic(err) } // Fetch the user profile req, err := http.NewRequest("GET", discoveryDocument.UserInfoEndpoint, nil) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } req.Header.Set("Authorization", "Bearer "+providerToken) @@ -72,25 +72,25 @@ func getGoogleUserProfile(providerToken string) (string, string, string) { client := &http.Client{} resp, err = client.Do(req) if err != nil { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - fmt.Print("Error fetching user profile") + fmt.Println("Error fetching user profile") panic(err) } body, err = io.ReadAll(resp.Body) if err != nil { - fmt.Print("Error reading user profile") + fmt.Println("Error reading user profile") panic(err) } var userProfile UserProfile if err := json.Unmarshal(body, &userProfile); err != nil { - fmt.Print("Error unmarshalling user profile") + fmt.Println("Error unmarshalling user profile") panic(err) } @@ -101,7 +101,7 @@ func getGitHubUserProfile(providerToken string) (string, string, string) { // Create the request to fetch the user profile req, err := http.NewRequest("GET", "https://api.github.com/user", nil) if err != nil { - fmt.Print("failed to create request: %v", err) + fmt.Println("failed to create request: %v", err) panic(err) } req.Header.Set("Authorization", "Bearer "+providerToken) @@ -111,25 +111,25 @@ func getGitHubUserProfile(providerToken string) (string, string, string) { client := &http.Client{} resp, err := client.Do(req) if err != nil { - fmt.Print("failed to execute request") + fmt.Println("failed to execute request") panic(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - fmt.Print("failed to fetch user profile: status code") + fmt.Println("failed to fetch user profile: status code") panic(resp.StatusCode) } body, err := io.ReadAll(resp.Body) if err != nil { - fmt.Print("failed to read response body") + fmt.Println("failed to read response body") panic(err) } var userProfile UserProfile if err := json.Unmarshal(body, &userProfile); err != nil { - fmt.Print("failed to unmarshal user profile") + fmt.Println("failed to unmarshal user profile") panic(err) } @@ -140,7 +140,7 @@ func generatePKCE() (string, string) { verifier_source := make([]byte, 32) _, err := rand.Read(verifier_source) if err != nil { - fmt.Print("failed to generate PKCE") + fmt.Println("failed to generate PKCE") panic(err) } @@ -167,7 +167,7 @@ func handleCallbackSignup(c *fiber.Ctx) error { code := c.Query("code") if code == "" { err := c.Query("error") - fmt.Print("OAuth callback is missing 'code'. OAuth provider responded with error") + fmt.Println("OAuth callback is missing 'code'. OAuth provider responded with error") panic(err) } @@ -179,21 +179,21 @@ func handleCallbackSignup(c *fiber.Ctx) error { codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", EDGEDB_AUTH_BASE_URL, code, verifier) resp, err := http.Get(codeExchangeURL) if err != nil { - fmt.Print("Error exchanging code for access token") + fmt.Println("Error exchanging code for access token") panic(err) } defer resp.Body.Close() if resp.StatusCode != fiber.StatusOK { body, _ := io.ReadAll(resp.Body) - fmt.Print("Error exchanging code for access token") + fmt.Println("Error exchanging code for access token") panic(string(body)) } var tokenResponse TokenResponse err = json.NewDecoder(resp.Body).Decode(&tokenResponse) if err != nil { - fmt.Print("Error decoding auth server response") + fmt.Println("Error decoding auth server response") panic(err) } @@ -209,7 +209,7 @@ func handleCallbackSignup(c *fiber.Ctx) error { var identity Identity identityUUID, err := edgedb.ParseUUID(tokenResponse.IdentityID) if err != nil { - fmt.Print("Error parsing UUID") + fmt.Println("Error parsing UUID") panic(err) } err = edgeClient.QuerySingle(edgeCtx, ` @@ -218,7 +218,7 @@ func handleCallbackSignup(c *fiber.Ctx) error { } FILTER .id = $0 `, &identity, identityUUID) if err != nil { - fmt.Print("Error fetching identity") + fmt.Println("Error fetching identity") panic(err) } @@ -252,7 +252,7 @@ func handleCallbackSignup(c *fiber.Ctx) error { } `, stripCustID, providerEmail, providerName, providerAvatar, identityUUID) if err != nil { - fmt.Print("Error creating user") + fmt.Println("Error creating user") panic(err) } @@ -265,7 +265,7 @@ func handleCallbackSignup(c *fiber.Ctx) error { position := 1 }`) if err != nil { - fmt.Print("Error creating default conversation") + fmt.Println("Error creating default conversation") panic(err) } @@ -276,7 +276,7 @@ func handleCallback(c *fiber.Ctx) error { code := c.Query("code") if code == "" { err := c.Query("error") - fmt.Print("OAuth callback is missing 'code'. OAuth provider responded with error") + fmt.Println("OAuth callback is missing 'code'. OAuth provider responded with error") panic(err) } @@ -288,21 +288,21 @@ func handleCallback(c *fiber.Ctx) error { codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", EDGEDB_AUTH_BASE_URL, code, verifier) resp, err := http.Get(codeExchangeURL) if err != nil { - fmt.Print("Error exchanging code for access token") + fmt.Println("Error exchanging code for access token") panic(err) } defer resp.Body.Close() if resp.StatusCode != fiber.StatusOK { body, _ := io.ReadAll(resp.Body) - fmt.Print("Error exchanging code for access token") + fmt.Println("Error exchanging code for access token") panic(string(body)) } var tokenResponse TokenResponse err = json.NewDecoder(resp.Body).Decode(&tokenResponse) if err != nil { - fmt.Print("Error decoding auth server response") + fmt.Println("Error decoding auth server response") panic(err) } diff --git a/main.go b/main.go index dcc6086..d6ed758 100644 --- a/main.go +++ b/main.go @@ -206,7 +206,7 @@ func addKeys(c *fiber.Ctx) error { ); `, &Exists) if err != nil { - fmt.Print("Error checking if OpenAI key exists") + fmt.Println("Error checking if OpenAI key exists") panic(err) } @@ -218,7 +218,7 @@ func addKeys(c *fiber.Ctx) error { } `, "openai", openaiKey) if err != nil { - fmt.Print("Error updating OpenAI key") + fmt.Println("Error updating OpenAI key") panic(err) } } else { @@ -236,7 +236,7 @@ func addKeys(c *fiber.Ctx) error { ) }`, openaiKey) if err != nil { - fmt.Print("Error adding OpenAI key") + fmt.Println("Error adding OpenAI key") panic(err) } } @@ -256,7 +256,7 @@ func addKeys(c *fiber.Ctx) error { ); `, &Exists) if err != nil { - fmt.Print("Error checking if Anthropic key exists") + fmt.Println("Error checking if Anthropic key exists") panic(err) } @@ -268,7 +268,7 @@ func addKeys(c *fiber.Ctx) error { } `, anthropicKey) if err != nil { - fmt.Print("Error updating Anthropic key") + fmt.Println("Error updating Anthropic key") panic(err) } } else { @@ -286,7 +286,7 @@ func addKeys(c *fiber.Ctx) error { ) }`, anthropicKey) if err != nil { - fmt.Print("Error adding Anthropic key") + fmt.Println("Error adding Anthropic key") panic(err) } } @@ -306,7 +306,7 @@ func addKeys(c *fiber.Ctx) error { ); `, &Exists) if err != nil { - fmt.Print("Error checking if Mistral key exists") + fmt.Println("Error checking if Mistral key exists") panic(err) } @@ -318,7 +318,7 @@ func addKeys(c *fiber.Ctx) error { } `, mistralKey) if err != nil { - fmt.Print("Error updating Mistral key") + fmt.Println("Error updating Mistral key") panic(err) } } else { @@ -336,7 +336,7 @@ func addKeys(c *fiber.Ctx) error { ) }`, mistralKey) if err != nil { - fmt.Print("Error adding Mistral key") + fmt.Println("Error adding Mistral key") panic(err) } } @@ -356,7 +356,7 @@ func addKeys(c *fiber.Ctx) error { ); `, &Exists) if err != nil { - fmt.Print("Error checking if Groq key exists") + fmt.Println("Error checking if Groq key exists") panic(err) } @@ -368,7 +368,7 @@ func addKeys(c *fiber.Ctx) error { } `, groqKey) if err != nil { - fmt.Print("Error updating Groq key") + fmt.Println("Error updating Groq key") panic(err) } } else { @@ -386,7 +386,7 @@ func addKeys(c *fiber.Ctx) error { ) }`, groqKey) if err != nil { - fmt.Print("Error adding Groq key") + fmt.Println("Error adding Groq key") panic(err) } } @@ -406,7 +406,7 @@ func addKeys(c *fiber.Ctx) error { ); `, &Exists) if err != nil { - fmt.Print("Error checking if Gooseai key exists") + fmt.Println("Error checking if Gooseai key exists") panic(err) } @@ -418,7 +418,7 @@ func addKeys(c *fiber.Ctx) error { } `, gooseaiKey) if err != nil { - fmt.Print("Error updating Gooseai key") + fmt.Println("Error updating Gooseai key") panic(err) } } else { @@ -436,7 +436,7 @@ func addKeys(c *fiber.Ctx) error { ) }`, gooseaiKey) if err != nil { - fmt.Print("Error adding Gooseai key") + fmt.Println("Error adding Gooseai key") panic(err) } } @@ -456,7 +456,7 @@ func addKeys(c *fiber.Ctx) error { ); `, &Exists) if err != nil { - fmt.Print("Error checking if Google key exists") + fmt.Println("Error checking if Google key exists") panic(err) } @@ -468,7 +468,7 @@ func addKeys(c *fiber.Ctx) error { } `, googleKey) if err != nil { - fmt.Print("Error updating Google key") + fmt.Println("Error updating Google key") panic(err) } } else { @@ -486,7 +486,7 @@ func addKeys(c *fiber.Ctx) error { ) }`, googleKey) if err != nil { - fmt.Print("Error adding Google key") + fmt.Println("Error adding Google key") panic(err) } } diff --git a/utils.go b/utils.go index 6cc1318..8703545 100644 --- a/utils.go +++ b/utils.go @@ -20,7 +20,7 @@ func markdownToHTML(markdownText string) string { ), ) if err := md.Convert([]byte(markdownText), &buf); err != nil { - fmt.Print("failed to convert markdown to HTML") + fmt.Println("failed to convert markdown to HTML") panic(err) } @@ -63,7 +63,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) { ); `, &openaiExists) if err != nil { - fmt.Print("Error checking if OpenAI key exists") + fmt.Println("Error checking if OpenAI key exists") panic(err) } @@ -74,7 +74,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) { ); `, &anthropicExists) if err != nil { - fmt.Print("Error checking if Anthropic key exists") + fmt.Println("Error checking if Anthropic key exists") panic(err) } @@ -85,7 +85,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) { ); `, &mistralExists) if err != nil { - fmt.Print("Error checking if Mistral key exists") + fmt.Println("Error checking if Mistral key exists") panic(err) } @@ -96,7 +96,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) { ); `, &groqExists) if err != nil { - fmt.Print("Error checking if Groq key exists") + fmt.Println("Error checking if Groq key exists") panic(err) } @@ -107,7 +107,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) { ); `, &gooseaiExists) if err != nil { - fmt.Print("Error checking if GooseAI key exists") + fmt.Println("Error checking if GooseAI key exists") panic(err) } @@ -118,7 +118,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) { ); `, &googleExists) if err != nil { - fmt.Print("Error checking if Google key exists") + fmt.Println("Error checking if Google key exists") panic(err) } @@ -186,7 +186,7 @@ func GetAvailableModels() []ModelInfo { } FILTER .modelID != 'none' AND .company.name != 'huggingface' AND .company IN global currentUser.setting.keys.company `, &models) if err != nil { - fmt.Print("Error getting models") + fmt.Println("Error getting models") panic(err) } return models