MCPcopy Index your code
hub / github.com/google/gvisor / extractCode

Function extractCode

test/gpu/textgen_test.go:36–56  ·  view source on GitHub ↗

extractCode extracts code between two code block markers.

(response, codeBlockDelim string)

Source from the content-addressed store, hash-verified

34
35// extractCode extracts code between two code block markers.
36func extractCode(response, codeBlockDelim string) (string, error) {
37 if !strings.Contains(response, codeBlockDelim) {
38 return "", fmt.Errorf("no marker string %q", codeBlockDelim)
39 }
40 var codeLines []string
41 isCodeBlock := false
42 for _, line := range strings.Split(response, "\n") {
43 if strings.HasPrefix(line, codeBlockDelim) {
44 isCodeBlock = !isCodeBlock
45 } else if isCodeBlock {
46 codeLines = append(codeLines, line)
47 }
48 }
49 if isCodeBlock {
50 return "", errors.New("non-terminated code block")
51 }
52 if len(codeLines) == 0 {
53 return "", errors.New("no or empty code block")
54 }
55 return strings.Join(codeLines, "\n") + "\n", nil
56}
57
58// runSandboxedPython runs the given Python code in a sandboxed container.
59func runSandboxedPython(ctx context.Context, logger testutil.Logger, code string) (string, error) {

Callers 1

TestLLMFunction · 0.85

Calls 5

ErrorfMethod · 0.65
SplitMethod · 0.65
NewMethod · 0.65
JoinMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…