Find answers from the community

k
kati
Offline, last seen 3 months ago
Joined September 25, 2024
Is this the correct prompt when using PandasQueryEngine with vLLM (huggingface) ?

Plain Text
 system_message = """\
    You are working with a pandas dataframe in Python.
    The name of the dataframe is `df`.
    This is the result of `print(df.head())`:
    {df_str}
    """

    instruction_str = """\
    1. Convert the query to executable Python code using Pandas.
    2. The final line of code should be a Python expression that can be called with the `eval()` function.
    3. The code should represent a solution to the query.
    4. PRINT ONLY THE EXPRESSION.
    5. Do not quote the expression.
    """

    user_message = """\
    Follow these instructions:
    {instruction_str}
    Query: {query_str}
    """

    assistant_message = "Expression: "

    def create_conversation(sample):
        return {
            "messages": [
                {"role": "system", "content": system_message.format(df_str=sample["header"])},
                {
                    "role": "user",
                    "content": user_message.format(
                        instruction_str=instruction_str, query_str=sample["Question"]
                    ),
                },
                {"role": "assistant", "content": assistant_message + sample["Expression"]},
            ]
        }

    query_express_ds = query_express_ds.map(create_conversation)
2 comments
W