code: def preprocess_completion_prompt(prompt: str) -> tuple[str, str]:
      """Preprocess the DS-1000 prompt (Completion mode) into instruction and response prefix"""
      # hit = False
      if not "SOLUTION START" in prompt:
          answer_index = prompt.rindex("A:")
          answer = prompt[answer_index + 2 :].strip()
          instruction: str = prompt[:answer_index].strip()
          if instruction.startswith("Problem:"):
              instruction = instruction[len("Problem:") :].strip()
          if "### BEGIN SOLUTION" in prompt:
              assert prompt.count("<code>") == 1
              assert prompt.count("</code>") == 0
              lines = answer.splitlines(keepends=True)
              return_line, result_line, begin_line = lines[-3:]
              assert return_line.strip().startswith("# return")
              assert result_line.strip().startswith("# ")
              assert begin_line.strip() == "### BEGIN SOLUTION"
              response = "".join(lines[:-3]).strip()
              hint = begin_line.replace("###", "#").replace(
                  "BEGIN SOLUTION", "Solution"
              )
              response += f"\n{hint}\n"
          else:
              assert "BEGIN SOLUTION" in prompt
              assert prompt.count("<code>") == 2
              assert prompt.count("</code>") == 1
              first_block_start = prompt.index("<code>")
              first_block_end = prompt.index("</code>")
              second_block_start = prompt.index(
                  "<code>", first_block_start + 1
              )
              assert first_block_end < second_block_start
              lines = answer.splitlines(keepends=True)
              (
                  block_end,
                  instruction_line,
                  begin_line,
                  block_start,
              ) = lines[-4:]
              assert begin_line.strip() == "BEGIN SOLUTION"
              assert block_start.strip() == "<code>"
              if not block_end.strip() == "</code>":
                  if lines[-6].strip() == "</code>":
                      response_prefix = lines[:-6]
                      starting_lines = lines[-5:-2]
                  else:
                      assert instruction_line.strip() == "</code>"
                      response_prefix = lines[:-3]
                      starting_lines = lines[-2:-2]
              else:
                  response_prefix = lines[:-4]
                  starting_lines = lines[-3:-2]
              starting_lines = [
                  f"# {line.lstrip()}" for line in starting_lines
              ]
              response = "".join(
                  [*response_prefix, *starting_lines]
              ).strip()
              response += "\n# Solution\n"
      else:
          # hit = True
          assert prompt.count("<code>") == 0
          assert prompt.count("</code>") == 0
          assert prompt.strip().endswith("# SOLUTION START")
          code_prefix = prompt[
              : prompt.rindex("# SOLUTION START")
          ].strip()
          instruction = f"""Write a solution to the following problem:
  ```python
  {code_prefix}
  ```"""
          response = f"```python\n{code_prefix}\n# Solution\n"
      instruction = instruction.replace("<code>", "```python").replace(
          "</code>", "```"
      )
      response = response.replace("<code>", "```python").replace(
          "</code>", "```"
      )
      # if hit:
      #     print("[Instruction]")
      #     print(instruction)
      #     print("[Response]")
      #     print(response)
      #     breakpoint()
      return instruction, response
  
file_path: magicoder/experiments/ds_1000.py
imports: import os
  from dataclasses import dataclass, field
  from pathlib import Path
  from typing import Callable, Literal, cast
  from ds1000 import DS1000Dataset, DS1000Problem
  from tqdm.auto import tqdm
  from transformers import HfArgumentParser
  from magicoder.llm_wrapper import GenerationConfig, ModelContext, create_infilling_prompt, get_model_context
  from magicoder.prompt_template import MAGICODER_PROMPT
label_desc: Use image node_id 4 for calling a global function with example usage: preprocess_completion_prompt(prompt) and returns: instruction,  response