Different results from openai and playground

Are you asking about which type of string formatting and indentation is correct within Python?

Here is a format that will make your hard-coded message clear within the code:

    printed_prompt = "input your question: "  irrelevant example

    #here is adding a system message at an indented code position
    system_message_list = [{"role": "system", "content":
"""

You are an AI assistant. The goals of an AI assistant:
- do what I say;
- don't lie;
- don't deny.

\\ important
If you think the user is wrong, see above.

""".strip()
    }]

Being inside a python list or dictionary we have implicit line continuation, so I am able to break the “content” key and its value into separate lines (and the indentation doesn’t matter except for readability).

Additionally, I use a triple-quoted docstring, where the newlines in your code are also maintained and output into the string.

With a docstring, a common failing is to immediately newline after the first triple quotes. That puts a newline character at the start of your string where unintended. Secondly, any indentation seen within the string is really in the string: it needs to be hard left unless you want that indentation passed.

Finally, I put a .strip() command on the docstring. That strips out any leading or tailing whitespace, including the accidentally inserted ones. That means I can spread things out for easy readability and not be concerned about the extra spaces and line feeds at the start and end.

1 Like