MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / strip_code_wrapper

Function strip_code_wrapper

src/request/openai.rs:310–330  ·  view source on GitHub ↗

strip the code wrapper that ChatGPT generated with code.

(input: &str)

Source from the content-addressed store, hash-verified

308
309/// strip the code wrapper that ChatGPT generated with code.
310fn strip_code_wrapper(input: &str) -> String {
311 let mut input = input.trim();
312 let mut event = "";
313 if let Some(idx) = input.find("```") {
314 event = &input[..idx];
315 input = &input[idx..];
316 }
317 let input = strip_code_prefix(input, "cpp");
318 let input = strip_code_prefix(input, "CPP");
319 let input = strip_code_prefix(input, "C++");
320 let input = strip_code_prefix(input, "c++");
321 let input = strip_code_prefix(input, "c");
322 let input = strip_code_prefix(input, "C");
323 let input = strip_code_prefix(input, "\n");
324 if let Some(idx) = input.rfind("```") {
325 let input = &input[..idx];
326 let input = ["/*", event, "*/\n", input].concat();
327 return input;
328 }
329 ["/*", event, "*/\n", input].concat()
330}
331
332#[cfg(test)]
333mod tests {

Callers 1

generate_program_by_chatFunction · 0.85

Calls 1

strip_code_prefixFunction · 0.85

Tested by

no test coverage detected