MCPcopy Create free account
hub / github.com/cloudwego/eino-examples / tryExtractCodeSnippet

Function tryExtractCodeSnippet

adk/multiagent/deep/tools/python_runner.go:96–120  ·  view source on GitHub ↗
(res string)

Source from the content-addressed store, hash-verified

94}
95
96func tryExtractCodeSnippet(res string) string {
97 var input struct {
98 Code string `json:"code"`
99 }
100
101 var codeToProcess string
102 err := jsoniter.Unmarshal([]byte(res), &input)
103 if err != nil {
104 codeToProcess = res
105 } else {
106 codeToProcess = input.Code
107 }
108
109 rawCode := extractCodeSnippet(codeToProcess)
110 unescapedCode := strings.NewReplacer(
111 "\\\\", "\\",
112 "\\n", "\n",
113 "\\r", "\r",
114 "\\t", "\t",
115 "\\\"", "\"",
116 "\\'", "'",
117 ).Replace(rawCode)
118
119 return unescapedCode
120}
121
122func extractCodeSnippet(res string) string {
123 codePattern := regexp.MustCompile("(?s)```python\\s*(.*?)\\s*```")

Callers 1

InvokableRunMethod · 0.70

Calls 1

extractCodeSnippetFunction · 0.70

Tested by

no test coverage detected