Skip to content

Latest commit

 

History

History
216 lines (177 loc) · 7.27 KB

Infilling_guideline.md

File metadata and controls

216 lines (177 loc) · 7.27 KB

Code Completion Tutorial: Contextual, Cross-File, and Project-Level Completion

This tutorial primarily introduces the code completion capabilities of plugin-enabled models. These capabilities include contextual completion, cross-file completion, and project-level file completion.

  • Contextual Completion: Within the same code file, based on the cursor's position and the surrounding context.

  • Cross-File Completion: Enhances code completion capabilities by incorporating dependencies or related files of the current code file.

  • Project-Level Completion: The model can generate complete new files based on your project information and requirements.

    You can use the CodeGeeX4-ALL-9B-128k model and control memory requirements by setting different max_length values. For example, you can set max_length to 16k or 32k to run the model on consumer-grade graphics cards.

Code Completion Usage Tutorial

1. Contextual Completion

  1. File Path: "###PATH:" + relative file path or file name
  2. Language Tag: This is very important and must be included. The list of languages is mentioned above, and the format generally starts with the language's initial capital letter, with a few exceptions. If unsure about the language, you can leave it blank after the colon. All language tags start with "###LANGUAGE:".
  3. Two Modes: "###MODE:", LINE generates a single line, and BLOCK generates multiple lines. The default is BLOCK mode.
  4. Format:
<|user|>
###PATH:{path}
###LANGUAGE:{code_language}
###MODE:{LINE/BLOCK}
<|code_suffix|>{code}<|code_prefix|>{code}<|code_middle|><|assistant|>\n
  1. Example: When all information including path, code_language, mode, suffix, and prefix is provided:
<|user|>
###PATH:src.py
###LANGUAGE:Python
###MODE:LINE/BLOCK
<|code_suffix|>            else:
                depth -= 1

        return max_depth

    return [parse_paren_group(x) for x in paren_string.split(' ') if x]
<|code_prefix|>from typing import List

def parse_nested_parens(paren_string: str) -> List[int]:
    """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
    For each of the group, output the deepest level of nesting of parentheses.
    E.g. (()()) has maximum two levels of nesting while ((())) has three.

    >>> parse_nested_parens('(()()) ((())) () ((())()())')
   [2, 3, 1, 3]
"""
<|code_middle|><|assistant|>\n
  • Situation with no language and no suffix provided
<|user|>
###PATH:src.py
###LANGUAGE:
###MODE:LINE/BLOCK
<|code_suffix|><|code_prefix|>from typing import List

def parse_nested_parens(paren_string: str) -> List[int]:
    """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
    For each of the group, output the deepest level of nesting of parentheses.
    E.g. (()()) has maximum two levels of nesting while ((())) has three.

    >>> parse_nested_parens('(()()) ((())) () ((())()())')
    [2, 3, 1, 3]
   """
<|code_middle|><|assistant|>\n

2. Cross File Infilling

  1. Please format reference code as below:
###REFERENCE:
###PATH: relative file path or file name
code snippet
###REFERENCE:
###PATH: relative file path or file name
code snippet
  1. File Path: "###PATH:" + relative file path or file name
  2. Language Tag: This is very important and must be included. The list of languages is mentioned above, and the format generally starts with the language's initial capital letter, with a few exceptions. If unsure about the language, you can leave it blank after the colon. All language tags start with "###LANGUAGE:".
  3. Two Modes: "###MODE:", LINE generates a single line, and BLOCK generates multiple lines. The default is BLOCK mode.
  4. Format:
<|user|>
###REFERENCE:
###PATH:{path}
{code}
...
...
...
###REFERENCE:
###PATH:{path}
{code}
###PATH:{path}\n\n###LANGUAGE:{code_language}\n###MODE:{LINE/BLOCK}\n<|code_suffix|>{code}<|code_prefix|>{code}<|code_middle|><|assistant|>\n
  1. Example:
|Python
<|user|>
###PATH:./sort/quick_sort.py
def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quick_sort(left) + middle + quick_sort(right)

arr = [3,6,8,10,1,2,1]
print(quick_sort(arr))
###PATH:src.py
###LANGUAGE:Python
###MODE:LINE/BLOCK
<|code_suffix|>            else:
                depth -= 1

        return max_depth

    return [parse_paren_group(x) for x in paren_string.split(' ') if x]
<|code_prefix|>from typing import List


def parse_nested_parens(paren_string: str) -> List[int]:
    """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
    For each of the group, output the deepest level of nesting of parentheses.
    E.g. (()()) has maximum two levels of nesting while ((())) has three.

    >>> parse_nested_parens('(()()) ((())) () ((())()())')
    [2, 3, 1, 3]
    """
<|code_middle|><|assistant|>\n

3. Repository Level File Generation

  1. You can use the project-level add, delete, and modify format to complete the task of adding a file in the project.
  2. Related files: Example format is as follows:
###REFERENCE:
###PATH: relative file path or file name
代码
###REFERENCE:
###PATH: relative file path or file name
代码
  1. File Path: "###PATH:" + relative file path or file name
  2. Language Tag: This is very important and must be included. The list of languages is mentioned above, and the format generally starts with the language's initial capital letter, with a few exceptions. If unsure about the language, you can leave it blank after the colon. All language tags start with "###LANGUAGE:".
  3. Two Modes: "###MODE:", LINE generates a single line, and BLOCK generates multiple lines. The default is BLOCK mode.
  4. Format:
<|user|>
###REFERENCE:
###PATH:{path}
{code}
...
...
...
###REFERENCE:
###PATH:{path}
{code}
###PATH:{path}
###LANGUAGE:{code_language}
###MODE:{LINE/BLOCK}
<|code_suffix|>{code}<|code_prefix|>{code}<|code_middle|><|assistant|>\n
  1. Example:
<|user|>
###PATH:./sort/quick_sort.py
def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    left = [x for x in arr if x < pivot]
    middle = [x for x in arr if x == pivot]
    right = [x for x in arr if x > pivot]
    return quick_sort(left) + middle + quick_sort(right)

arr = [3,6,8,10,1,2,1]
print(quick_sort(arr))
###PATH:src.py
###LANGUAGE:Python
###MODE:LINE/BLOCK
<|code_suffix|>            else:
                depth -= 1

        return max_depth

    return [parse_paren_group(x) for x in paren_string.split(' ') if x]
<|code_prefix|>from typing import List


def parse_nested_parens(paren_string: str) -> List[int]:
    """ Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
    For each of the group, output the deepest level of nesting of parentheses.
    E.g. (()()) has maximum two levels of nesting while ((())) has three.

    >>> parse_nested_parens('(()()) ((())) () ((())()())')
    [2, 3, 1, 3]
    """
<|code_middle|><|assistant|>\n