-
Notifications
You must be signed in to change notification settings - Fork 10
/
document_python_code.py
46 lines (41 loc) · 1.3 KB
/
document_python_code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def document_python_code(
code: str,
context: str = None,
format: str = "Google"
) -> str:
prompt = f"""
Your task is to generate a docstring for the Python function/class delimited by triple backticks below.
```python
{code}
```
Use {format} style.
"""
if context is not None:
prompt = prompt + f"""
Here you have more code that can help you creating the docstring:
```python
{context}
```
"""
prompt = prompt + f"Output only the function/class definition and the docstring. Do not output the actual code of the function"
return prompt
_title = "Document Python Code"
_author = "@nachollorca"
_description = "A senior ordered you to document 1M lines worth of project? Worry not, my friend, for this recipe shall soothe your path."
_ui = {
"code": {
"text": "",
"help": "The function/class you want to document.",
"suggestions": "def hello_world():\n caps('Hello World')",
},
"context": {
"text": "",
"help": "Any code you want GPT-4 to read before generating the docstring.",
"suggestions": "def caps(string: str) -> str: \n return string.uppercase()",
},
"format": {
"text": "",
"help": "The docstring format you want the docstring to have.",
"suggestions": "NumPy, reST, ...",
},
}