<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def function_completions( completion_text: str, bel_spec: BELSpec, function_list: list, bel_fmt: str, size: int, ) -> list: """Filter BEL functions by prefix Args: prefix: completion string bel_fmt: short, medium, long BEL formats spec: BEL specification Returns: list: list of BEL functions that match prefix """


    # Convert provided function list to correct bel_fmt
    if isinstance(function_list, list):
        if bel_fmt in ["short", "medium"]:
            function_list = [
                bel_spec["functions"]["to_short"][fn] for fn in function_list
            ]
        else:
            function_list = [
                bel_spec["functions"]["to_long"][fn] for fn in function_list
            ]
    elif bel_fmt in ["short", "medium"]:
        function_list = bel_spec["functions"]["primary"]["list_short"]
    else:
        function_list = bel_spec["functions"]["primary"]["list_long"]

    matches = []
    for f in function_list:
        escaped_completion_text = completion_text.replace(r"(", r"\(").replace(
            r")", r"\)"
        )
        log.debug(f"Completion match: {escaped_completion_text}  F: {f}")
        if re.match(escaped_completion_text, f):
            matches.append(f)

    replace_list = []
    for match in matches:
        if completion_text:
            highlight = match.replace(completion_text, f"<em>{completion_text}</em>")
        else:
            highlight = completion_text

        replace_list.append(
            {
                "replacement": match,
                "label": f"{match}()",
                "highlight": highlight,
                "type": "Function",
            }
        )

    return replace_list[:size]