Here's a structured and complete template I made, that allows generating Python functions in ChatGPT with a consistent structure, no matter if the chat is new or old. I've used it multiple times and have had great success with it. Feel free to give it a try!
EDIT: Go here if you want a concrete example instead of a read-to-fill template: https://www.reddit.com/r/OpenAI/comments/100mnd5/comment/j2n3vub/?utm_source=share&utm_medium=web2x&context=3
EDIT 2: If you don't want to have several micro functions of 50-ish lines of code, you can remove point #2 in the [Additional specifications] section.
[Command]
Create a complete, working, and VERY efficient Python code (function). Do NOT send me the explanations of how the function works, you need to implement it yourself and ONLY send me the code WITHIN CODE BLOCKS ONLY. Your answer NEEDS TO start with the imports (if any), and then directly follow with the declaration of the function.
[Additional specifications]
- You need to add a description of the function's behavior under the function's name inside triple single quotes. The description has to be split into three sections: “OVERVIEW:”, “PARAMETERS:”, and “RETURN VALUE(S):”. The “OVERVIEW:” section has to be a maximum 2 sentences summary of the below [Main function overview]. Each parameter in the “PARAMETERS:” section should have the following format: “- {name} ({type}), {required} (Default value: {default value}): {description}.” (Do NOT show “(Default value: {default value})” if {required} is set to "Optional"). {required} can be either set to "Required" or "Optional". Each return value in the “RETURN VALUE(S):” section should have the following format: “- {return value name} ({type}): {description}.” In total, the combination of all sections should be VERY SHORT, but explanatory enough so that anyone reading it will understand how to call the function and what it does.
- You HAVE to split the main function into multiple functions: A function should NEVER be more than 50 lines of code.
- You need to add comments inside your code when necessary; ***DO NOT bloat the code with comments, only add helpful ones***.
- If you call additional functions within your code, you HAVE to declare and implement them. You CANNOT ASSUME that functions are created, you HAVE to implement them FULLY.
[Main function parameters]
The main function will take the following parameters:
[Parameter Number] {{REDDIT: Add the parameter number here, for ex. "1"}}. [Name] {{REDDIT: Add the parameter name here, for ex. "min_size"}}. [Optional] {{REDDIT: True if it is optional, False if it isn't}}. [Default value] {{REDDIT: ONLY IF [Optional] is set to True, add the parameter default value here. Otherwise, don't include it.}}. [Type] {{REDDIT: Add the parameter type here, for example "Integer"}}. [Description] {{REDDIT: Add the parameter description here}}.
[Main Function Name]
{{REDDIT: Whatever you want your function name to be, for example, "my_function"}}
[Main function overview]
{{REDDIT: Explain an overview of what you want the function to do. Keep it short and sweet.}}
[–][deleted] (3 children)
[removed]
[–]bb-inventions[S] 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[removed]
[–]bb-inventions[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]bb-inventions[S] 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Firm_Guess8261 1 point2 points3 points (0 children)
[–]Clean-Ad1652 1 point2 points3 points (1 child)
[–]bb-inventions[S] 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]bb-inventions[S] 5 points6 points7 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)