Skip to content

Prompt Templates

During the planning phase, the ToCT algorithm leverages your chosen prompt template along with the samples in your dataset to generate the prompt for inference. The content of this prompt varies based on several factors, including the source and target programming languages, the input code from the sample, and other relevant variables. You have the flexibility to define custom parameters within your prompt, which the ToCT algorithm will automatically replace with the appropriate values from your request. The order of these parameters is not crucial; they can be arranged in any configuration.

Example Prompt

This prompt is a modification from the paper Exploring the Impact of the Output Format on the Evaluation of Large Language Models for Code Translation

prompt_humanevalx: |
@@ Instruction
You are a skilled software developer proficient in multiple programming languages. Your task is to re-write the input source code. Below is the input source code written in {input_lang} that you should re-write into {target_lang} programming language. You must respond with the {target_lang} output code only.
Here are some examples:
{extra_prompt_data}
Translate the code below. Your {target_lang} code must have this signature and include imports.
{signature}
Source code:
{input_code}
@@ Response

Available Parameters

  • {input_lang}: The source programming language of the input code. Currently accepts: Java, Python, C, C++, C#, Go, Rust, JavaScript.
  • {target_lang}: The target programming language of the output code. Currently accepts: Java, Python, C, C++, C#, Go, Rust, JavaScript.
  • {input_code}: The input code that needs to be translated.
  • {signature} (optional): The signature of the output code that needs to be translated. This is useful to control the name of the generated function or class, and the imports that are required for the output code.
  • {extra_prompt_data} (optional): Additional information that can be included in the prompt. This can be used to provide context to the user about the task they are performing, implement few-shot prompting by including examples or add the compiler feedback from previous executions.