fix: trimming leading and trailing whitespaces before unmarshal LLM o… (#587)

This commit is contained in:
shentongmartin
2025-08-05 21:12:10 +08:00
committed by GitHub
parent 4b3042359c
commit 117b63f661
2 changed files with 37 additions and 5 deletions

View File

@@ -87,15 +87,13 @@ func TemplateRender(template string, vals map[string]interface{}) (string, error
}
func ExtractJSONString(content string) string {
content = strings.TrimSpace(content)
if strings.HasPrefix(content, "```") && strings.HasSuffix(content, "```") {
content = content[3 : len(content)-3]
}
if strings.HasPrefix(content, "json") {
content = content[4:]
}
return content
return strings.TrimPrefix(content, "json")
}
func ConcatTwoMaps(m1, m2 map[string]any) (map[string]any, error) {