mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-21 16:37:47 +08:00
18 lines
491 B
Go
18 lines
491 B
Go
package openai
|
|
|
|
import (
|
|
"regexp"
|
|
)
|
|
|
|
var leakedToolHistoryPattern = regexp.MustCompile(`(?is)\[TOOL_CALL_HISTORY\][\s\S]*?\[/TOOL_CALL_HISTORY\]|\[TOOL_RESULT_HISTORY\][\s\S]*?\[/TOOL_RESULT_HISTORY\]`)
|
|
var emptyJSONFencePattern = regexp.MustCompile("(?is)```json\\s*```")
|
|
|
|
func sanitizeLeakedToolHistory(text string) string {
|
|
if text == "" {
|
|
return text
|
|
}
|
|
out := leakedToolHistoryPattern.ReplaceAllString(text, "")
|
|
out = emptyJSONFencePattern.ReplaceAllString(out, "")
|
|
return out
|
|
}
|