package main import ( "bytes" "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"
}