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"
	}
	if strings.Contains(model, "mistral") || strings.Contains(model, "mixtral") {
		return "mistral"
	}
	return "bouvai2"
}

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

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

	var openaiExists bool
	var anthropicExists bool
	var mistralExists 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 checking for openai: ", err)
		openaiExists = false
	}

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

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

	return openaiExists, anthropicExists, mistralExists
}