This commit is contained in:
Adrien Bouvais 2024-05-28 10:52:28 +02:00
parent 8ad02e67f7
commit a5a322cd38
19 changed files with 171 additions and 146 deletions

87
Chat.go
View File

@ -16,7 +16,6 @@ import (
func ChatPageHandler(c *fiber.Ctx) error { func ChatPageHandler(c *fiber.Ctx) error {
authCookie := c.Cookies("jade-edgedb-auth-token", "") authCookie := c.Cookies("jade-edgedb-auth-token", "")
fmt.Println("Main page")
if authCookie != "" && !checkIfLogin() { if authCookie != "" && !checkIfLogin() {
edgeClient = edgeClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": authCookie}) 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) messageUUID, err := edgedb.ParseUUID(messageId)
if err != nil { if err != nil {
fmt.Print("Error parsing UUID") fmt.Println("Error parsing UUID")
panic(err) panic(err)
} }
@ -55,7 +54,7 @@ func DeleteMessageHandler(c *fiber.Ctx) error {
FILTER .position >= messageArea.position AND .conversation = messageArea.conversation; FILTER .position >= messageArea.position AND .conversation = messageArea.conversation;
`, messageUUID) `, messageUUID)
if err != nil { if err != nil {
fmt.Print("Error deleting messages") fmt.Println("Error deleting messages")
panic(err) panic(err)
} }
@ -88,12 +87,12 @@ type TemplateMessage struct {
} }
func generateChatHTML() string { func generateChatHTML() string {
// Print the name of the current conversation // Println the name of the current conversation
var currentConv Conversation var currentConv Conversation
err := edgeClient.QuerySingle(edgeCtx, ` err := edgeClient.QuerySingle(edgeCtx, `
SELECT global currentConversation { name }`, &currentConv) SELECT global currentConversation { name }`, &currentConv)
if err != nil { if err != nil {
fmt.Print("Error getting current conversation") fmt.Println("Error getting current conversation")
panic(err) panic(err)
} }
fmt.Println("Current conversation: ", currentConv.Name) fmt.Println("Current conversation: ", currentConv.Name)
@ -123,7 +122,7 @@ func generateChatHTML() string {
ORDER BY .date ASC ORDER BY .date ASC
`, &Messages) `, &Messages)
if err != nil { if err != nil {
fmt.Print("Error getting messages") fmt.Println("Error getting messages")
panic(err) panic(err)
} }
@ -136,7 +135,7 @@ func generateChatHTML() string {
htmlContent := markdownToHTML(message.Content) htmlContent := markdownToHTML(message.Content)
userOut, err := userTmpl.Execute(pongo2.Context{"Content": htmlContent, "ID": message.ID.String()}) userOut, err := userTmpl.Execute(pongo2.Context{"Content": htmlContent, "ID": message.ID.String()})
if err != nil { if err != nil {
fmt.Print("Error executing user template") fmt.Println("Error executing user template")
panic(err) panic(err)
} }
htmlString += userOut htmlString += userOut
@ -169,7 +168,7 @@ func generateChatHTML() string {
botOut, err := botTmpl.Execute(pongo2.Context{"Messages": templateMessages, "ConversationAreaId": i}) botOut, err := botTmpl.Execute(pongo2.Context{"Messages": templateMessages, "ConversationAreaId": i})
if err != nil { if err != nil {
fmt.Print("Error executing bot template") fmt.Println("Error executing bot template")
panic(err) panic(err)
} }
htmlString += botOut htmlString += botOut
@ -198,13 +197,13 @@ func GetUserMessageHandler(c *fiber.Ctx) error {
.id = <uuid>$0; .id = <uuid>$0;
`, &selectedMessage, messageUUID) `, &selectedMessage, messageUUID)
if err != nil { if err != nil {
fmt.Print("Error getting message") fmt.Println("Error getting message")
panic(err) panic(err)
} }
out, err := userTmpl.Execute(pongo2.Context{"Content": markdownToHTML(selectedMessage.Content), "ID": id}) out, err := userTmpl.Execute(pongo2.Context{"Content": markdownToHTML(selectedMessage.Content), "ID": id})
if err != nil { if err != nil {
fmt.Print("Error executing user template") fmt.Println("Error executing user template")
panic(err) panic(err)
} }
@ -293,7 +292,7 @@ func generateWelcomeChatHTML() string {
botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true})
if err != nil { if err != nil {
fmt.Print("Error executing bot template") fmt.Println("Error executing bot template")
panic(err) panic(err)
} }
htmlString += botOut htmlString += botOut
@ -329,7 +328,7 @@ func generateEnterKeyChatHTML() string {
botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true})
if err != nil { if err != nil {
fmt.Print("Error executing bot template") fmt.Println("Error executing bot template")
panic(err) panic(err)
} }
htmlString += botOut htmlString += botOut
@ -373,7 +372,7 @@ func generateTermAndServiceChatHTML() string {
botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true})
if err != nil { if err != nil {
fmt.Print("Error executing bot template") fmt.Println("Error executing bot template")
panic(err) panic(err)
} }
htmlString += botOut htmlString += botOut
@ -390,7 +389,7 @@ func generateLimitReachedChatHTML() string {
var result User var result User
err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id, email } LIMIT 1;", &result) err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id, email } LIMIT 1;", &result)
if err != nil { if err != nil {
fmt.Print("Error getting current user") fmt.Println("Error getting current user")
panic(err) panic(err)
} }
@ -418,7 +417,7 @@ func generateLimitReachedChatHTML() string {
botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true}) botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true})
if err != nil { if err != nil {
fmt.Print("Error executing bot template") fmt.Println("Error executing bot template")
panic(err) panic(err)
} }
htmlString += botOut htmlString += botOut
@ -440,7 +439,7 @@ func GetEditMessageFormHandler(c *fiber.Ctx) error {
FILTER .id = <uuid>$0; FILTER .id = <uuid>$0;
`, &message, idUUID) `, &message, idUUID)
if err != nil { if err != nil {
fmt.Print("Error getting message") fmt.Println("Error getting message")
panic(err) panic(err)
} }
@ -453,7 +452,7 @@ func GetEditMessageFormHandler(c *fiber.Ctx) error {
tmpl := pongo2.Must(pongo2.FromFile("views/partials/message-edit-form.html")) tmpl := pongo2.Must(pongo2.FromFile("views/partials/message-edit-form.html"))
out, err := tmpl.Execute(pongo2.Context{"Content": message.Content, "ID": id, "Rows": rows}) out, err := tmpl.Execute(pongo2.Context{"Content": message.Content, "ID": id, "Rows": rows})
if err != nil { if err != nil {
fmt.Print("Error executing user template") fmt.Println("Error executing user template")
panic(err) panic(err)
} }
return c.SendString(out) return c.SendString(out)
@ -466,7 +465,7 @@ func RedoMessageHandler(c *fiber.Ctx) error {
var selectedLLMIds []string var selectedLLMIds []string
err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds)
if err != nil { if err != nil {
fmt.Print("Error unmarshalling selected LLM IDs") fmt.Println("Error unmarshalling selected LLM IDs")
panic(err) panic(err)
} }
@ -476,7 +475,7 @@ func RedoMessageHandler(c *fiber.Ctx) error {
FILTER .id = <uuid>$0; FILTER .id = <uuid>$0;
`, &message, messageUUID) `, &message, messageUUID)
if err != nil { if err != nil {
fmt.Print("Error getting message") fmt.Println("Error getting message")
panic(err) 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; FILTER .position > messageArea.position AND .conversation = messageArea.conversation AND .conversation.user = global currentUser;
`, messageUUID) `, messageUUID)
if err != nil { if err != nil {
fmt.Print("Error deleting messages") fmt.Println("Error deleting messages")
panic(err) panic(err)
} }
@ -503,7 +502,7 @@ func EditMessageHandler(c *fiber.Ctx) error {
var selectedLLMIds []string var selectedLLMIds []string
err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds)
if err != nil { if err != nil {
fmt.Print("Error unmarshalling selected LLM IDs") fmt.Println("Error unmarshalling selected LLM IDs")
panic(err) 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; FILTER .position >= messageArea.position AND .conversation = messageArea.conversation AND .conversation.user = global currentUser;
`, messageUUID) `, messageUUID)
if err != nil { if err != nil {
fmt.Print("Error deleting messages") fmt.Println("Error deleting messages")
panic(err) panic(err)
} }
@ -533,7 +532,7 @@ func ClearChatHandler(c *fiber.Ctx) error {
FILTER .conversation = global currentConversation; FILTER .conversation = global currentConversation;
`) `)
if err != nil { if err != nil {
fmt.Print("Error deleting messages") fmt.Println("Error deleting messages")
panic(err) panic(err)
} }
@ -553,7 +552,7 @@ func LoadUsageKPIHandler(c *fiber.Ctx) error {
var InputDate time.Time var InputDate time.Time
InputDate, err := time.Parse("01-2006", InputDateID) InputDate, err := time.Parse("01-2006", InputDateID)
if err != nil { if err != nil {
fmt.Print("Error parsing date") fmt.Println("Error parsing date")
panic(err) panic(err)
} }
@ -594,7 +593,7 @@ func LoadUsageKPIHandler(c *fiber.Ctx) error {
} FILTER .total_count > 0 ORDER BY .total_cost DESC } FILTER .total_count > 0 ORDER BY .total_cost DESC
`, &usages, InputDate, InputDate.AddDate(0, 1, 0)) `, &usages, InputDate, InputDate.AddDate(0, 1, 0))
if err != nil { if err != nil {
fmt.Print("Error getting usage") fmt.Println("Error getting usage")
panic(err) panic(err)
} }
@ -618,7 +617,7 @@ func LoadUsageKPIHandler(c *fiber.Ctx) error {
"IsActive": IsActive, "IsActive": IsActive,
}) })
if err != nil { if err != nil {
fmt.Print("Error generating usage") fmt.Println("Error generating usage")
panic(err) panic(err)
} }
@ -642,7 +641,7 @@ func LoadKeysHandler(c *fiber.Ctx) error {
"AnyExists": openaiExists || anthropicExists || mistralExists || groqExists || gooseaiExists || googleExists, "AnyExists": openaiExists || anthropicExists || mistralExists || groqExists || gooseaiExists || googleExists,
}) })
if err != nil { if err != nil {
fmt.Print("Error loading keys") fmt.Println("Error loading keys")
panic(err) panic(err)
} }
return c.SendString(out) return c.SendString(out)
@ -671,7 +670,7 @@ func GenerateModelPopoverHTML(refresh bool) string {
ORDER BY .position ORDER BY .position
`, &llms) `, &llms)
if err != nil { if err != nil {
fmt.Print("Error loading LLMs") fmt.Println("Error loading LLMs")
panic(err) panic(err)
} }
@ -692,7 +691,7 @@ func GenerateModelPopoverHTML(refresh bool) string {
"IsSub": IsCurrentUserSubscribed(), "IsSub": IsCurrentUserSubscribed(),
}) })
if err != nil { if err != nil {
fmt.Print("Error generating model popover") fmt.Println("Error generating model popover")
panic(err) panic(err)
} }
return out return out
@ -717,7 +716,7 @@ func GenerateConversationPopoverHTML(isActive bool) string {
ORDER BY .position ORDER BY .position
`, &conversations) `, &conversations)
if err != nil { if err != nil {
fmt.Print("Error loading conversations") fmt.Println("Error loading conversations")
panic(err) panic(err)
} }
@ -726,7 +725,7 @@ func GenerateConversationPopoverHTML(isActive bool) string {
"IsActive": isActive, "IsActive": isActive,
}) })
if err != nil { if err != nil {
fmt.Print("Error generating conversation popover") fmt.Println("Error generating conversation popover")
panic(err) panic(err)
} }
return out return out
@ -758,7 +757,7 @@ func LoadSettingsHandler(c *fiber.Ctx) error {
FILTER .id = global currentUser.id FILTER .id = global currentUser.id
`, &user) `, &user)
if err != nil { if err != nil {
fmt.Print("Error loading user") fmt.Println("Error loading user")
panic(err) panic(err)
} }
@ -782,7 +781,7 @@ func LoadSettingsHandler(c *fiber.Ctx) error {
"StripeSubLink": stripeSubLink, "StripeSubLink": stripeSubLink,
}) })
if err != nil { if err != nil {
fmt.Print("Error loading settings") fmt.Println("Error loading settings")
panic(err) panic(err)
} }
return c.SendString(out) return c.SendString(out)
@ -807,7 +806,7 @@ func CreateConversationHandler(c *fiber.Ctx) error {
} }
`, name) `, name)
if err != nil { if err != nil {
fmt.Print("Error creating conversation") fmt.Println("Error creating conversation")
panic(err) panic(err)
} }
@ -819,7 +818,7 @@ func DeleteConversationHandler(c *fiber.Ctx) error {
conversationUUID, err := edgedb.ParseUUID(conversationId) conversationUUID, err := edgedb.ParseUUID(conversationId)
if err != nil { if err != nil {
fmt.Print("Error parsing UUID") fmt.Println("Error parsing UUID")
panic(err) panic(err)
} }
@ -828,7 +827,7 @@ func DeleteConversationHandler(c *fiber.Ctx) error {
FILTER .user = global currentUser AND .id = <uuid>$0; FILTER .user = global currentUser AND .id = <uuid>$0;
`, conversationUUID) `, conversationUUID)
if err != nil { if err != nil {
fmt.Print("Error deleting conversation") fmt.Println("Error deleting conversation")
panic(err) panic(err)
} }
@ -839,23 +838,11 @@ func SelectConversationHandler(c *fiber.Ctx) error {
conversationId := c.FormValue("conversation-id") conversationId := c.FormValue("conversation-id")
conversationUUID, err := edgedb.ParseUUID(conversationId) conversationUUID, err := edgedb.ParseUUID(conversationId)
if err != nil { if err != nil {
fmt.Print("Error parsing UUID") fmt.Println("Error parsing UUID")
panic(err) panic(err)
} }
fmt.Println("conversationUUID", conversationUUID.String()) edgeClient = edgeClient.WithGlobals(map[string]interface{}{"ext::auth::client_token": c.Cookies("jade-edgedb-auth-token"), "currentConversationID": conversationUUID})
err = edgeClient.Execute(edgeCtx, `
SET global currentConversation := (
SELECT Conversation
FILTER .id = <uuid>$0
LIMIT 1
);
`, conversationUUID)
if err != nil {
fmt.Print("Error selecting conversation")
panic(err)
}
return c.SendString(generateChatHTML()) return c.SendString(generateChatHTML())
} }

16
LLM.go
View File

@ -14,7 +14,7 @@ func deleteLLM(c *fiber.Ctx) error {
var selectedLLMIds []string var selectedLLMIds []string
err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds)
if err != nil { if err != nil {
fmt.Print("Error unmarshalling selected LLM IDs") fmt.Println("Error unmarshalling selected LLM IDs")
panic(err) panic(err)
} }
@ -28,7 +28,7 @@ func deleteLLM(c *fiber.Ctx) error {
}; };
`, idUUID) `, idUUID)
if err != nil { if err != nil {
fmt.Print("Error deleting LLM") fmt.Println("Error deleting LLM")
panic(err) panic(err)
} }
} }
@ -87,7 +87,7 @@ func createLLM(c *fiber.Ctx) error {
}; };
`, name, systemPrompt, temperatureFloat, url, token, customID) // TODO Add real max token `, name, systemPrompt, temperatureFloat, url, token, customID) // TODO Add real max token
if err != nil { if err != nil {
fmt.Print("Error creating LLM") fmt.Println("Error creating LLM")
panic(err) panic(err)
} }
} else { } else {
@ -104,7 +104,7 @@ func createLLM(c *fiber.Ctx) error {
} }
`, name, systemPrompt, temperatureFloat, modelID) `, name, systemPrompt, temperatureFloat, modelID)
if err != nil { if err != nil {
fmt.Print("Error creating LLM") fmt.Println("Error creating LLM")
panic(err) panic(err)
} }
} }
@ -126,7 +126,7 @@ func updateLLMPositionBatch(c *fiber.Ctx) error {
for _, update := range positionUpdates { for _, update := range positionUpdates {
idUUID, err := edgedb.ParseUUID(update.ID) idUUID, err := edgedb.ParseUUID(update.ID)
if err != nil { if err != nil {
fmt.Print("Error parsing UUID") fmt.Println("Error parsing UUID")
panic(err) panic(err)
} }
@ -138,7 +138,7 @@ func updateLLMPositionBatch(c *fiber.Ctx) error {
}; };
`, idUUID, int32(update.Position)) `, idUUID, int32(update.Position))
if err != nil { if err != nil {
fmt.Print("Error updating LLM position") fmt.Println("Error updating LLM position")
panic(err) panic(err)
} }
} }
@ -157,7 +157,7 @@ func updateConversationPositionBatch(c *fiber.Ctx) error {
fmt.Println(update.ID) fmt.Println(update.ID)
idUUID, err := edgedb.ParseUUID(update.ID) idUUID, err := edgedb.ParseUUID(update.ID)
if err != nil { if err != nil {
fmt.Print("Error parsing UUID") fmt.Println("Error parsing UUID")
panic(err) panic(err)
} }
@ -169,7 +169,7 @@ func updateConversationPositionBatch(c *fiber.Ctx) error {
}; };
`, idUUID, int32(update.Position)) `, idUUID, int32(update.Position))
if err != nil { if err != nil {
fmt.Print("Error updating conversation position") fmt.Println("Error updating conversation position")
panic(err) panic(err)
} }
} }

View File

@ -37,7 +37,7 @@ func GeneratePlaceholderHandler(c *fiber.Ctx) error {
var selectedLLMIds []string var selectedLLMIds []string
err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds) err := json.Unmarshal([]byte(c.FormValue("selectedLLMIds")), &selectedLLMIds)
if err != nil { if err != nil {
fmt.Print("Error unmarshalling selected LLM IDs") fmt.Println("Error unmarshalling selected LLM IDs")
panic(err) panic(err)
} }
@ -74,7 +74,7 @@ func GeneratePlaceholderHTML(message string, selectedLLMIds []string, with_user_
.id = <uuid>$0; .id = <uuid>$0;
`, &selectedLLM, idUUID) `, &selectedLLM, idUUID)
if err != nil { if err != nil {
fmt.Print("Error getting LLM") fmt.Println("Error getting LLM")
panic(err) panic(err)
} }
selectedLLMs = append(selectedLLMs, selectedLLM) selectedLLMs = append(selectedLLMs, selectedLLM)
@ -164,7 +164,7 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error {
FILTER .id = <uuid>$0; FILTER .id = <uuid>$0;
`, &message, messageID) `, &message, messageID)
if err != nil { if err != nil {
fmt.Print("Error getting message") fmt.Println("Error getting message")
panic(err) panic(err)
} }
@ -193,7 +193,7 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error {
"ConversationAreaId": message.Area.Position, "ConversationAreaId": message.Area.Position,
}) })
if err != nil { if err != nil {
fmt.Print("Error generating HTML content") fmt.Println("Error generating HTML content")
panic(err) panic(err)
} }
outBtn = strings.ReplaceAll(outBtn, "\n", "") outBtn = strings.ReplaceAll(outBtn, "\n", "")
@ -220,7 +220,7 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error {
"ConversationAreaId": message.Area.Position, "ConversationAreaId": message.Area.Position,
}) })
if err != nil { if err != nil {
fmt.Print("Error generating HTML content") fmt.Println("Error generating HTML content")
panic(err) panic(err)
} }
@ -258,7 +258,7 @@ func addUsage(inputCost float32, outputCost float32, inputToken int32, outputTok
} }
`, inputCost, outputCost, inputToken, outputToken, modelID) `, inputCost, outputCost, inputToken, outputToken, modelID)
if err != nil { if err != nil {
fmt.Print("Error adding usage") fmt.Println("Error adding usage")
panic(err) panic(err)
} }
} }

View File

@ -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) chatCompletion, err := RequestAnthropic(llm.Model.ModelID, Messages, int(llm.Model.MaxToken), float64(llm.Temperature), llm.Context)
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} else if len(chatCompletion.Content) == 0 { } else if len(chatCompletion.Content) == 0 {
fmt.Println("No response from Anthropic") fmt.Println("No response from Anthropic")

View File

@ -51,7 +51,7 @@ func addGoogleMessage(llm LLM, selected bool) edgedb.UUID {
chatCompletion, err := RequestGoogle(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) chatCompletion, err := RequestGoogle(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context)
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} else if len(chatCompletion.Choices) == 0 { } else if len(chatCompletion.Choices) == 0 {
fmt.Println("No response from Google") fmt.Println("No response from Google")

View File

@ -38,7 +38,7 @@ func addGooseaiMessage(llm LLM, selected bool) edgedb.UUID {
chatCompletion, err := RequestGooseai(llm.Model.ModelID, Messages, float64(llm.Temperature)) chatCompletion, err := RequestGooseai(llm.Model.ModelID, Messages, float64(llm.Temperature))
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} else if len(chatCompletion.Choices) == 0 { } else if len(chatCompletion.Choices) == 0 {
fmt.Println("No response from GooseAI") fmt.Println("No response from GooseAI")

View File

@ -42,7 +42,7 @@ func addGroqMessage(llm LLM, selected bool) edgedb.UUID {
chatCompletion, err := RequestGroq(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) chatCompletion, err := RequestGroq(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context)
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} else if len(chatCompletion.Choices) == 0 { } else if len(chatCompletion.Choices) == 0 {
fmt.Println("No response from Groq") fmt.Println("No response from Groq")

View File

@ -42,7 +42,7 @@ func addHuggingfaceMessage(llm LLM, selected bool) edgedb.UUID {
chatCompletion, err := RequestHuggingface(llm, Messages, float64(llm.Temperature)) chatCompletion, err := RequestHuggingface(llm, Messages, float64(llm.Temperature))
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} else if len(chatCompletion.Choices) == 0 { } else if len(chatCompletion.Choices) == 0 {
fmt.Println("No response from Endpoint") fmt.Println("No response from Endpoint")

View File

@ -41,7 +41,7 @@ func addMistralMessage(llm LLM, selected bool) edgedb.UUID {
chatCompletion, err := RequestMistral(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) chatCompletion, err := RequestMistral(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context)
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} else if len(chatCompletion.Choices) == 0 { } else if len(chatCompletion.Choices) == 0 {
id := insertBotMessage("No response from Mistral", selected, llm.ID) id := insertBotMessage("No response from Mistral", selected, llm.ID)

View File

@ -42,7 +42,7 @@ func addOpenaiMessage(llm LLM, selected bool) edgedb.UUID {
chatCompletion, err := RequestOpenai(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context) chatCompletion, err := RequestOpenai(llm.Model.ModelID, Messages, float64(llm.Temperature), llm.Context)
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} else if len(chatCompletion.Choices) == 0 { } else if len(chatCompletion.Choices) == 0 {
fmt.Println("No response from OpenAI") fmt.Println("No response from OpenAI")

View File

@ -22,7 +22,7 @@ func generatePricingTableChatHTML() string {
var result User var result User
err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id, email } LIMIT 1;", &result) err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id, email } LIMIT 1;", &result)
if err != nil { if err != nil {
fmt.Print("Error getting user") fmt.Println("Error getting user")
panic(err) panic(err)
} }
@ -60,7 +60,7 @@ func generatePricingTableChatHTML() string {
botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true, "notFlex": true}) botOut, err := botTmpl.Execute(pongo2.Context{"Messages": NextMessages, "ConversationAreaId": 0, "NotClickable": true, "notFlex": true})
if err != nil { if err != nil {
fmt.Print("Error executing template") fmt.Println("Error executing template")
panic(err) panic(err)
} }
htmlString += botOut htmlString += botOut
@ -87,12 +87,12 @@ func IsCurrentUserSubscribed() bool {
var user User var user User
err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user) err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user)
if err != nil { if err != nil {
fmt.Print("Error getting user") fmt.Println("Error getting user")
panic(err) panic(err)
} }
result, err := customer.Get(user.StripeID, nil) result, err := customer.Get(user.StripeID, nil)
if err != nil { if err != nil {
fmt.Print("Error getting customer") fmt.Println("Error getting customer")
panic(err) panic(err)
} }
if result.Subscriptions.TotalCount == 0 { if result.Subscriptions.TotalCount == 0 {
@ -114,7 +114,7 @@ func IsCurrentUserLimiteReached() bool {
SELECT count(U) SELECT count(U)
`, &count) `, &count)
if err != nil { if err != nil {
fmt.Print("Error counting Usage") fmt.Println("Error counting Usage")
panic(err) panic(err)
} }
return count >= 500 return count >= 500
@ -124,7 +124,7 @@ func CreateClientSecretSession() string {
var user User var user User
err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user) err := edgeClient.QuerySingle(edgeCtx, "SELECT global currentUser { stripe_id } LIMIT 1;", &user)
if err != nil { if err != nil {
fmt.Print("Error getting user") fmt.Println("Error getting user")
panic(err) panic(err)
} }
@ -136,7 +136,7 @@ func CreateClientSecretSession() string {
req, err := http.NewRequest(method, url, bytes.NewBuffer(payload)) req, err := http.NewRequest(method, url, bytes.NewBuffer(payload))
if err != nil { if err != nil {
fmt.Print("failed to create request") fmt.Println("failed to create request")
panic(err) panic(err)
} }
req.Header.Add("Authorization", "Bearer "+apiKey) req.Header.Add("Authorization", "Bearer "+apiKey)
@ -145,20 +145,20 @@ func CreateClientSecretSession() string {
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
fmt.Print("failed to execute request") fmt.Println("failed to execute request")
panic(err) panic(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body) 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))) panic(fmt.Sprintf("failed to create customer session: %s", string(body)))
} }
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
fmt.Print("failed to read response body") fmt.Println("failed to read response body")
panic(err) panic(err)
} }
@ -169,7 +169,7 @@ func CreateClientSecretSession() string {
var customerSession CustomerSessionResponse var customerSession CustomerSessionResponse
if err := json.Unmarshal(body, &customerSession); err != nil { if err := json.Unmarshal(body, &customerSession); err != nil {
fmt.Print("failed to unmarshal response") fmt.Println("failed to unmarshal response")
panic(err) panic(err)
} }

View File

@ -122,7 +122,7 @@ func init() {
var ctx = context.Background() var ctx = context.Background()
client, err := edgedb.CreateClient(ctx, edgedb.Options{}) client, err := edgedb.CreateClient(ctx, edgedb.Options{})
if err != nil { if err != nil {
fmt.Print("Error connecting to edgedb") fmt.Println("Error connecting to edgedb")
panic(err) panic(err)
} }
@ -148,7 +148,7 @@ func insertArea() (edgedb.UUID, int64) {
} }
`, &inserted) `, &inserted)
if err != nil { if err != nil {
fmt.Print("Error inserting area") fmt.Println("Error inserting area")
panic(err) panic(err)
} }
@ -180,11 +180,11 @@ func insertUserMessage(content string) edgedb.UUID {
LIMIT 1 LIMIT 1
`, &lastArea) `, &lastArea)
if err != nil { if err != nil {
fmt.Print("Error getting last area") fmt.Println("Error getting last area")
panic(err) 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, ` err = edgeClient.QuerySingle(edgeCtx, `
INSERT Message { INSERT Message {
role := <str>$0, role := <str>$0,
@ -196,12 +196,12 @@ func insertUserMessage(content string) edgedb.UUID {
conversation := global currentConversation, conversation := global currentConversation,
selected := true, selected := true,
llm := ( llm := (
SELECT LLM FILTER .id = <uuid>"a32c43ec-12fc-11ef-9dc9-b38e0de8bff0" SELECT LLM FILTER .id = <uuid>"32cb4f0c-1c3f-11ef-9247-2fac0086a7d1"
) )
} }
`, &inserted, "user", content, lastArea.ID) `, &inserted, "user", content, lastArea.ID)
if err != nil { if err != nil {
fmt.Print("Error inserting user message") fmt.Println("Error inserting user message")
panic(err) panic(err)
} }
return inserted.id return inserted.id
@ -218,7 +218,7 @@ func insertBotMessage(content string, selected bool, llmUUID edgedb.UUID) edgedb
LIMIT 1 LIMIT 1
`, &lastArea) `, &lastArea)
if err != nil { if err != nil {
fmt.Print("Error getting last area") fmt.Println("Error getting last area")
panic(err) panic(err)
} }
@ -246,7 +246,7 @@ func insertBotMessage(content string, selected bool, llmUUID edgedb.UUID) edgedb
} }
`, &inserted, "bot", llmUUID, content, selected, lastArea.ID) `, &inserted, "bot", llmUUID, content, selected, lastArea.ID)
if err != nil { if err != nil {
fmt.Print("Error inserting bot message") fmt.Println("Error inserting bot message")
panic(err) panic(err)
} }
return inserted.id return inserted.id
@ -279,7 +279,7 @@ func getAllSelectedMessages() []Message {
ORDER BY .date ASC ORDER BY .date ASC
`, &messages) `, &messages)
if err != nil { if err != nil {
fmt.Print("Error getting messages") fmt.Println("Error getting messages")
panic(err) panic(err)
} }

View File

@ -8,10 +8,17 @@ module default {
)) ))
); );
required global currentConversationID: uuid {
default := <uuid>"00000000-0000-0000-0000-000000000000"
};
global currentConversation := ( global currentConversation := (
assert_single(( assert_single((
select Conversation select Conversation
filter .name = 'Default' AND .user = global currentUser filter .user = global currentUser AND (
.id = global currentConversationID OR
(global currentConversationID = <uuid>"00000000-0000-0000-0000-000000000000" AND .name = 'Default')
)
)) ))
); );

View File

@ -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 = <std::uuid>GLOBAL default::currentConversationID) OR ((GLOBAL default::currentConversationID = '') AND (.name = 'Default'))))
)));
};

View File

@ -0,0 +1,5 @@
CREATE MIGRATION m1f65xatu7epwthdl6s4yekiuusexvyk2w747gdt5ixzzggxzliyga
ONTO m1zlzfafekdlqfpf7zcj4taysmccydrzclqrkxjogkermv4qcn4wia
{
ALTER GLOBAL default::currentConversationID SET default := '00000000-0000-0000-0000-000000000000';
};

View File

@ -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 := (<std::uuid>'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 = <std::uuid>'00000000-0000-0000-0000-000000000000') AND (.name = 'Default'))))
)));
};

View File

@ -38,32 +38,32 @@ func getGoogleUserProfile(providerToken string) (string, string, string) {
// Fetch the discovery document // Fetch the discovery document
resp, err := http.Get("https://accounts.google.com/.well-known/openid-configuration") resp, err := http.Get("https://accounts.google.com/.well-known/openid-configuration")
if err != nil { if err != nil {
fmt.Print("Error fetching discovery document") fmt.Println("Error fetching discovery document")
panic(err) panic(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
fmt.Print("Error fetching discovery document") fmt.Println("Error fetching discovery document")
panic(resp.StatusCode) panic(resp.StatusCode)
} }
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
fmt.Print("Error reading discovery document") fmt.Println("Error reading discovery document")
panic(err) panic(err)
} }
var discoveryDocument DiscoveryDocument var discoveryDocument DiscoveryDocument
if err := json.Unmarshal(body, &discoveryDocument); err != nil { if err := json.Unmarshal(body, &discoveryDocument); err != nil {
fmt.Print("Error unmarshalling discovery document") fmt.Println("Error unmarshalling discovery document")
panic(err) panic(err)
} }
// Fetch the user profile // Fetch the user profile
req, err := http.NewRequest("GET", discoveryDocument.UserInfoEndpoint, nil) req, err := http.NewRequest("GET", discoveryDocument.UserInfoEndpoint, nil)
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} }
req.Header.Set("Authorization", "Bearer "+providerToken) req.Header.Set("Authorization", "Bearer "+providerToken)
@ -72,25 +72,25 @@ func getGoogleUserProfile(providerToken string) (string, string, string) {
client := &http.Client{} client := &http.Client{}
resp, err = client.Do(req) resp, err = client.Do(req)
if err != nil { if err != nil {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
fmt.Print("Error fetching user profile") fmt.Println("Error fetching user profile")
panic(err) panic(err)
} }
body, err = io.ReadAll(resp.Body) body, err = io.ReadAll(resp.Body)
if err != nil { if err != nil {
fmt.Print("Error reading user profile") fmt.Println("Error reading user profile")
panic(err) panic(err)
} }
var userProfile UserProfile var userProfile UserProfile
if err := json.Unmarshal(body, &userProfile); err != nil { if err := json.Unmarshal(body, &userProfile); err != nil {
fmt.Print("Error unmarshalling user profile") fmt.Println("Error unmarshalling user profile")
panic(err) panic(err)
} }
@ -101,7 +101,7 @@ func getGitHubUserProfile(providerToken string) (string, string, string) {
// Create the request to fetch the user profile // Create the request to fetch the user profile
req, err := http.NewRequest("GET", "https://api.github.com/user", nil) req, err := http.NewRequest("GET", "https://api.github.com/user", nil)
if err != nil { if err != nil {
fmt.Print("failed to create request: %v", err) fmt.Println("failed to create request: %v", err)
panic(err) panic(err)
} }
req.Header.Set("Authorization", "Bearer "+providerToken) req.Header.Set("Authorization", "Bearer "+providerToken)
@ -111,25 +111,25 @@ func getGitHubUserProfile(providerToken string) (string, string, string) {
client := &http.Client{} client := &http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
fmt.Print("failed to execute request") fmt.Println("failed to execute request")
panic(err) panic(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { 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) panic(resp.StatusCode)
} }
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
fmt.Print("failed to read response body") fmt.Println("failed to read response body")
panic(err) panic(err)
} }
var userProfile UserProfile var userProfile UserProfile
if err := json.Unmarshal(body, &userProfile); err != nil { if err := json.Unmarshal(body, &userProfile); err != nil {
fmt.Print("failed to unmarshal user profile") fmt.Println("failed to unmarshal user profile")
panic(err) panic(err)
} }
@ -140,7 +140,7 @@ func generatePKCE() (string, string) {
verifier_source := make([]byte, 32) verifier_source := make([]byte, 32)
_, err := rand.Read(verifier_source) _, err := rand.Read(verifier_source)
if err != nil { if err != nil {
fmt.Print("failed to generate PKCE") fmt.Println("failed to generate PKCE")
panic(err) panic(err)
} }
@ -167,7 +167,7 @@ func handleCallbackSignup(c *fiber.Ctx) error {
code := c.Query("code") code := c.Query("code")
if code == "" { if code == "" {
err := c.Query("error") 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) 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) codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", EDGEDB_AUTH_BASE_URL, code, verifier)
resp, err := http.Get(codeExchangeURL) resp, err := http.Get(codeExchangeURL)
if err != nil { if err != nil {
fmt.Print("Error exchanging code for access token") fmt.Println("Error exchanging code for access token")
panic(err) panic(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != fiber.StatusOK { if resp.StatusCode != fiber.StatusOK {
body, _ := io.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
fmt.Print("Error exchanging code for access token") fmt.Println("Error exchanging code for access token")
panic(string(body)) panic(string(body))
} }
var tokenResponse TokenResponse var tokenResponse TokenResponse
err = json.NewDecoder(resp.Body).Decode(&tokenResponse) err = json.NewDecoder(resp.Body).Decode(&tokenResponse)
if err != nil { if err != nil {
fmt.Print("Error decoding auth server response") fmt.Println("Error decoding auth server response")
panic(err) panic(err)
} }
@ -209,7 +209,7 @@ func handleCallbackSignup(c *fiber.Ctx) error {
var identity Identity var identity Identity
identityUUID, err := edgedb.ParseUUID(tokenResponse.IdentityID) identityUUID, err := edgedb.ParseUUID(tokenResponse.IdentityID)
if err != nil { if err != nil {
fmt.Print("Error parsing UUID") fmt.Println("Error parsing UUID")
panic(err) panic(err)
} }
err = edgeClient.QuerySingle(edgeCtx, ` err = edgeClient.QuerySingle(edgeCtx, `
@ -218,7 +218,7 @@ func handleCallbackSignup(c *fiber.Ctx) error {
} FILTER .id = <uuid>$0 } FILTER .id = <uuid>$0
`, &identity, identityUUID) `, &identity, identityUUID)
if err != nil { if err != nil {
fmt.Print("Error fetching identity") fmt.Println("Error fetching identity")
panic(err) panic(err)
} }
@ -252,7 +252,7 @@ func handleCallbackSignup(c *fiber.Ctx) error {
} }
`, stripCustID, providerEmail, providerName, providerAvatar, identityUUID) `, stripCustID, providerEmail, providerName, providerAvatar, identityUUID)
if err != nil { if err != nil {
fmt.Print("Error creating user") fmt.Println("Error creating user")
panic(err) panic(err)
} }
@ -265,7 +265,7 @@ func handleCallbackSignup(c *fiber.Ctx) error {
position := 1 position := 1
}`) }`)
if err != nil { if err != nil {
fmt.Print("Error creating default conversation") fmt.Println("Error creating default conversation")
panic(err) panic(err)
} }
@ -276,7 +276,7 @@ func handleCallback(c *fiber.Ctx) error {
code := c.Query("code") code := c.Query("code")
if code == "" { if code == "" {
err := c.Query("error") 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) 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) codeExchangeURL := fmt.Sprintf("%s/token?code=%s&verifier=%s", EDGEDB_AUTH_BASE_URL, code, verifier)
resp, err := http.Get(codeExchangeURL) resp, err := http.Get(codeExchangeURL)
if err != nil { if err != nil {
fmt.Print("Error exchanging code for access token") fmt.Println("Error exchanging code for access token")
panic(err) panic(err)
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != fiber.StatusOK { if resp.StatusCode != fiber.StatusOK {
body, _ := io.ReadAll(resp.Body) body, _ := io.ReadAll(resp.Body)
fmt.Print("Error exchanging code for access token") fmt.Println("Error exchanging code for access token")
panic(string(body)) panic(string(body))
} }
var tokenResponse TokenResponse var tokenResponse TokenResponse
err = json.NewDecoder(resp.Body).Decode(&tokenResponse) err = json.NewDecoder(resp.Body).Decode(&tokenResponse)
if err != nil { if err != nil {
fmt.Print("Error decoding auth server response") fmt.Println("Error decoding auth server response")
panic(err) panic(err)
} }

36
main.go
View File

@ -206,7 +206,7 @@ func addKeys(c *fiber.Ctx) error {
); );
`, &Exists) `, &Exists)
if err != nil { if err != nil {
fmt.Print("Error checking if OpenAI key exists") fmt.Println("Error checking if OpenAI key exists")
panic(err) panic(err)
} }
@ -218,7 +218,7 @@ func addKeys(c *fiber.Ctx) error {
} }
`, "openai", openaiKey) `, "openai", openaiKey)
if err != nil { if err != nil {
fmt.Print("Error updating OpenAI key") fmt.Println("Error updating OpenAI key")
panic(err) panic(err)
} }
} else { } else {
@ -236,7 +236,7 @@ func addKeys(c *fiber.Ctx) error {
) )
}`, openaiKey) }`, openaiKey)
if err != nil { if err != nil {
fmt.Print("Error adding OpenAI key") fmt.Println("Error adding OpenAI key")
panic(err) panic(err)
} }
} }
@ -256,7 +256,7 @@ func addKeys(c *fiber.Ctx) error {
); );
`, &Exists) `, &Exists)
if err != nil { if err != nil {
fmt.Print("Error checking if Anthropic key exists") fmt.Println("Error checking if Anthropic key exists")
panic(err) panic(err)
} }
@ -268,7 +268,7 @@ func addKeys(c *fiber.Ctx) error {
} }
`, anthropicKey) `, anthropicKey)
if err != nil { if err != nil {
fmt.Print("Error updating Anthropic key") fmt.Println("Error updating Anthropic key")
panic(err) panic(err)
} }
} else { } else {
@ -286,7 +286,7 @@ func addKeys(c *fiber.Ctx) error {
) )
}`, anthropicKey) }`, anthropicKey)
if err != nil { if err != nil {
fmt.Print("Error adding Anthropic key") fmt.Println("Error adding Anthropic key")
panic(err) panic(err)
} }
} }
@ -306,7 +306,7 @@ func addKeys(c *fiber.Ctx) error {
); );
`, &Exists) `, &Exists)
if err != nil { if err != nil {
fmt.Print("Error checking if Mistral key exists") fmt.Println("Error checking if Mistral key exists")
panic(err) panic(err)
} }
@ -318,7 +318,7 @@ func addKeys(c *fiber.Ctx) error {
} }
`, mistralKey) `, mistralKey)
if err != nil { if err != nil {
fmt.Print("Error updating Mistral key") fmt.Println("Error updating Mistral key")
panic(err) panic(err)
} }
} else { } else {
@ -336,7 +336,7 @@ func addKeys(c *fiber.Ctx) error {
) )
}`, mistralKey) }`, mistralKey)
if err != nil { if err != nil {
fmt.Print("Error adding Mistral key") fmt.Println("Error adding Mistral key")
panic(err) panic(err)
} }
} }
@ -356,7 +356,7 @@ func addKeys(c *fiber.Ctx) error {
); );
`, &Exists) `, &Exists)
if err != nil { if err != nil {
fmt.Print("Error checking if Groq key exists") fmt.Println("Error checking if Groq key exists")
panic(err) panic(err)
} }
@ -368,7 +368,7 @@ func addKeys(c *fiber.Ctx) error {
} }
`, groqKey) `, groqKey)
if err != nil { if err != nil {
fmt.Print("Error updating Groq key") fmt.Println("Error updating Groq key")
panic(err) panic(err)
} }
} else { } else {
@ -386,7 +386,7 @@ func addKeys(c *fiber.Ctx) error {
) )
}`, groqKey) }`, groqKey)
if err != nil { if err != nil {
fmt.Print("Error adding Groq key") fmt.Println("Error adding Groq key")
panic(err) panic(err)
} }
} }
@ -406,7 +406,7 @@ func addKeys(c *fiber.Ctx) error {
); );
`, &Exists) `, &Exists)
if err != nil { if err != nil {
fmt.Print("Error checking if Gooseai key exists") fmt.Println("Error checking if Gooseai key exists")
panic(err) panic(err)
} }
@ -418,7 +418,7 @@ func addKeys(c *fiber.Ctx) error {
} }
`, gooseaiKey) `, gooseaiKey)
if err != nil { if err != nil {
fmt.Print("Error updating Gooseai key") fmt.Println("Error updating Gooseai key")
panic(err) panic(err)
} }
} else { } else {
@ -436,7 +436,7 @@ func addKeys(c *fiber.Ctx) error {
) )
}`, gooseaiKey) }`, gooseaiKey)
if err != nil { if err != nil {
fmt.Print("Error adding Gooseai key") fmt.Println("Error adding Gooseai key")
panic(err) panic(err)
} }
} }
@ -456,7 +456,7 @@ func addKeys(c *fiber.Ctx) error {
); );
`, &Exists) `, &Exists)
if err != nil { if err != nil {
fmt.Print("Error checking if Google key exists") fmt.Println("Error checking if Google key exists")
panic(err) panic(err)
} }
@ -468,7 +468,7 @@ func addKeys(c *fiber.Ctx) error {
} }
`, googleKey) `, googleKey)
if err != nil { if err != nil {
fmt.Print("Error updating Google key") fmt.Println("Error updating Google key")
panic(err) panic(err)
} }
} else { } else {
@ -486,7 +486,7 @@ func addKeys(c *fiber.Ctx) error {
) )
}`, googleKey) }`, googleKey)
if err != nil { if err != nil {
fmt.Print("Error adding Google key") fmt.Println("Error adding Google key")
panic(err) panic(err)
} }
} }

View File

@ -20,7 +20,7 @@ func markdownToHTML(markdownText string) string {
), ),
) )
if err := md.Convert([]byte(markdownText), &buf); err != nil { 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) panic(err)
} }
@ -63,7 +63,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) {
); );
`, &openaiExists) `, &openaiExists)
if err != nil { if err != nil {
fmt.Print("Error checking if OpenAI key exists") fmt.Println("Error checking if OpenAI key exists")
panic(err) panic(err)
} }
@ -74,7 +74,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) {
); );
`, &anthropicExists) `, &anthropicExists)
if err != nil { if err != nil {
fmt.Print("Error checking if Anthropic key exists") fmt.Println("Error checking if Anthropic key exists")
panic(err) panic(err)
} }
@ -85,7 +85,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) {
); );
`, &mistralExists) `, &mistralExists)
if err != nil { if err != nil {
fmt.Print("Error checking if Mistral key exists") fmt.Println("Error checking if Mistral key exists")
panic(err) panic(err)
} }
@ -96,7 +96,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) {
); );
`, &groqExists) `, &groqExists)
if err != nil { if err != nil {
fmt.Print("Error checking if Groq key exists") fmt.Println("Error checking if Groq key exists")
panic(err) panic(err)
} }
@ -107,7 +107,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) {
); );
`, &gooseaiExists) `, &gooseaiExists)
if err != nil { if err != nil {
fmt.Print("Error checking if GooseAI key exists") fmt.Println("Error checking if GooseAI key exists")
panic(err) panic(err)
} }
@ -118,7 +118,7 @@ func getExistingKeys() (bool, bool, bool, bool, bool, bool) {
); );
`, &googleExists) `, &googleExists)
if err != nil { if err != nil {
fmt.Print("Error checking if Google key exists") fmt.Println("Error checking if Google key exists")
panic(err) panic(err)
} }
@ -186,7 +186,7 @@ func GetAvailableModels() []ModelInfo {
} FILTER .modelID != 'none' AND .company.name != 'huggingface' AND .company IN global currentUser.setting.keys.company } FILTER .modelID != 'none' AND .company.name != 'huggingface' AND .company IN global currentUser.setting.keys.company
`, &models) `, &models)
if err != nil { if err != nil {
fmt.Print("Error getting models") fmt.Println("Error getting models")
panic(err) panic(err)
} }
return models return models