Skip to content

output_prompt ¤

The logic for constructing the output prompt. These methods accept all "return" related properties of the python function and build a string output prompt from them.

Functions:

Name Description
compile_output_prompt

Compiles the output prompt for given function properties.

compile_unstructured_template

Compiles the output prompt for unstructured output but where still a return type is expected (for example int, float).

compile_output_prompt ¤

compile_output_prompt(
    str_schema: str,
    return_type: str,
    return_docstring: str,
    return_magic: str = None,
    structured: Optional[bool] = True,
    structured_template: Optional[str] = None,
) -> str

Compiles the output prompt for given function properties. Args: str_schema: tbd return_type: tbd return_docstring: tbd return_magic: tbd structured: tbd structured_template: tbd

Returns:

Source code in src/declarai/operators/templates/output_prompt.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def compile_output_prompt(
    str_schema: str,
    return_type: str,
    return_docstring: str,
    return_magic: str = None,
    structured: Optional[bool] = True,
    structured_template: Optional[str] = None,
) -> str:
    """
    Compiles the output prompt for given function properties.
    Args:
        str_schema: tbd
        return_type: tbd
        return_docstring: tbd
        return_magic: tbd
        structured: tbd
        structured_template: tbd

    Returns:

    """
    str_schema = str_schema or return_magic

    if not structured:
        return compile_unstructured_template(return_type, return_docstring)

    return compile_output_schema_template(
        str_schema, return_type, return_docstring, structured_template
    )

compile_unstructured_template ¤

compile_unstructured_template(
    return_type: str, return_docstring: str
) -> str

Compiles the output prompt for unstructured output but where still a return type is expected (for example int, float). Args: return_type: the type of the return value return_docstring: the description of the return value

Returns:

Source code in src/declarai/operators/templates/output_prompt.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def compile_unstructured_template(return_type: str, return_docstring: str) -> str:
    """
    Compiles the output prompt for unstructured output but where still a return type is expected (for example int, float).
    Args:
        return_type: the type of the return value
        return_docstring: the description of the return value

    Returns:

    """
    if return_type == "str":
        return ""
    output_prompt = ""
    if return_type:
        output_prompt += f"respond only with the value of type {return_type}:"
    if return_docstring:
        output_prompt += f"  # {return_docstring}"

    return output_prompt