-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprompts.py
68 lines (53 loc) · 2.6 KB
/
prompts.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def format_docs(ref_docs):
"""
Formats a list of reference documentation into a structured string.
Input:
ref_docs (list of dict): List of dictionaries, each containing 'function' and 'doc_str' keys
Returns:
str: Formatted string combining function names and their corresponding documentation
Raises:
None
"""
return '\n\n'.join(f'Function: {ref_doc["function"]}\nDocumentation: {ref_doc["doc_str"]}' for ref_doc in ref_docs)
SYSTEM_PROMPT = 'You are an intelligent AI programming assistant. You are fluent in Python and only answer questions related to Computer Science'
INSTRUCTIONS = '''\
- Generate documentation for the python function/class given below.
- The documentation should contain:
- Docstring
- Should be declared using “”” triple double quotes “”” just below the original class, method, or function definition.
- Should contain:
- A single line summary
- Input: Short descriptions of each input parameter
- Returns: Short descriptions of each output parameter
- Raises: Short description of failure cases and exceptions raised by the class, method, or function
- Inline comments
- Short inline comments for blocks of code that are hard to understand
- Only write such comments for each block of code, not for every line
- You also have access to reference documentation for sub-functions and sub-classes used in the original class, method, or function. These should be used for enhanced context for better documentation.
- Preserve all existing documentation given in the original class, method, or function.
- For a class, only generate a docstring for the whole class, do not add any comments for the class methods
- Do not change the code, name or existing comments of the original class, method, or function, only add comments wherever necessary.
- Do not add any import statements
- Only reply with the documented class, method, or function within ``` tags followed by the stop token: <STOP>'''
DOC_GENERATION_PROMPT = lambda func, ref_docs: f'''\
### Guidelines:
{INSTRUCTIONS}
### Reference documentation:
{format_docs(ref_docs)}
### Original code block:
```python
{func}
```
### Original code block with documentation:
```python
'''
DOC_SUMMARIZATION_PROMPT = lambda func, doc: f'''\
### Guidelines
Summarize the given function documentation in a single line.
Make sure that the key nuances and overall meaning of the documentation are captured in the summary
Ony Reply with only the summarized documentation followed by the stop token <STOP>
### Original documentation
Function: {func}
{doc}
### Summarized documentation
'''