package main import ( "bytes" "fmt" "regexp" "strings" "github.com/yuin/goldmark" highlighting "github.com/yuin/goldmark-highlighting" ) func markdownToHTML(markdownText string) string { var buf bytes.Buffer md := goldmark.New( goldmark.WithExtensions( highlighting.NewHighlighting(highlighting.WithStyle("monokai")), ), ) if err := md.Convert([]byte(markdownText), &buf); err != nil { panic(err) // Handle the error appropriately } return addCopyButtonsToCode(buf.String()) } func addCopyButtonsToCode(htmlContent string) string { buttonHTML := `` // Regular expression pattern to match
 elements and insert the button right before 
	pattern := `(]*>)`

	// Compile the regular expression
	re := regexp.MustCompile(pattern)

	// Replace each matched 
 element with the updated HTML
	updatedHTML := re.ReplaceAllString(htmlContent, "$1"+buttonHTML)

	return updatedHTML
}

func model2Icon(model string) string {
	if model == "gpt-3.5-turbo" {
		return "openai"
	}
	if model == "gpt-4" {
		return "openai"
	}
	// If model name contain claude-3 retrun anthropic
	if strings.Contains(model, "claude-3") {
		return "anthropic"
	}
	return "openai"
}

func model2Name(model string) string {
	for i := range ModelsInfos {
		if ModelsInfos[i].ID == model {
			return ModelsInfos[i].Name
		}
	}
	return "OpenAI"
}

func getExistingKeys() (bool, bool) {
	if edgeClient == nil {
		return false, false
	}

	var openaiExists bool
	var anthropicExists bool

	err := edgeClient.QuerySingle(edgeCtx, `
	select exists (
		select global currentUser.setting.keys
		filter .company = "openai"
	  );
	`, &openaiExists)
	if err != nil {
		fmt.Println("Error in edgedb.QuerySingle: in addOpenaiKey: ", err)
	}

	err = edgeClient.QuerySingle(edgeCtx, `
	select exists (
		select global currentUser.setting.keys
		filter .company = "anthropic"
	);
	`, &anthropicExists)
	if err != nil {
		fmt.Println("Error in edgedb.QuerySingle: in addOpenaiKey: ", err)
	}

	return openaiExists, anthropicExists
}