pub fn strip_code_fences(response: &str) -> StringExpand description
Remove markdown code fences from LLM output.
Examples found in repository?
examples/coder.rs (line 106)
70 fn run(&mut self, mut state: Task, ctx: &mut Ctx) -> StepResult<Task> {
71 let is_fix = !state.test_output.is_empty();
72
73 let response = if is_fix {
74 ctx.log(format!("coder: fixing (attempt {})", state.attempts));
75
76 ctx.llm()
77 .system(
78 "You are a developer. Fix the code based on the test failures. \
79 Return ONLY the complete fixed file contents, no explanation. \
80 Do not include doc comments or doc tests. \
81 Do not wrap the output in markdown code fences.",
82 )
83 .user(format!(
84 "Test errors:\n{}\n\nCurrent code:\n{}",
85 state.test_output, state.code
86 ))
87 .send()?
88 } else {
89 let plan = ctx.get("plan").unwrap_or("no plan found").to_string();
90 ctx.log("coder: writing initial code");
91
92 ctx.llm()
93 .system(
94 "You are a developer. Write the code based on the plan. \
95 Return ONLY the complete file contents, no explanation. \
96 Do not include doc comments or doc tests. \
97 Do not wrap the output in markdown code fences.",
98 )
99 .user(format!(
100 "Plan:\n{plan}\n\nFile: {}\n\nCurrent code:\n{}",
101 state.file_path, state.code
102 ))
103 .send()?
104 };
105
106 state.code = tools::strip_code_fences(&response);
107 state.test_output.clear();
108 tools::write_file(&state.file_path, &state.code)?;
109 Ok((state, Outcome::Continue))
110 }