Spaces:
Runtime error
Runtime error
Commit
·
63de821
1
Parent(s):
db88ae6
CMD tool ready
Browse files- TechdocsAPI/backend/router.py +0 -1
- TechdocsAPI/backend/utils/prompt.txt +13 -8
- techdocs/requirements.txt +0 -1
- techdocs/utils/functools.py +2 -2
- techdocs/utils/parse.py +9 -5
- testing/test.py +88 -3
TechdocsAPI/backend/router.py
CHANGED
@@ -50,7 +50,6 @@ async def signup(response: UserAuth):
|
|
50 |
|
51 |
@app.post("/auth/login", summary="Logs in user", response_model=TokenSchema, tags=["Auth Server"])
|
52 |
async def login(response:LoginCreds):
|
53 |
-
print("login")
|
54 |
return ops_login(response)
|
55 |
|
56 |
@app.put("/auth/regenerate_api_key",summary="Forget Password",response_model=APIKey,tags=["Auth Server"],dependencies=[Depends(JWTBearer())])
|
|
|
50 |
|
51 |
@app.post("/auth/login", summary="Logs in user", response_model=TokenSchema, tags=["Auth Server"])
|
52 |
async def login(response:LoginCreds):
|
|
|
53 |
return ops_login(response)
|
54 |
|
55 |
@app.put("/auth/regenerate_api_key",summary="Forget Password",response_model=APIKey,tags=["Auth Server"],dependencies=[Depends(JWTBearer())])
|
TechdocsAPI/backend/utils/prompt.txt
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
-
You are an AI Coding
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
Your task is to generate a docstring for the above query.
|
11 |
Response:
|
|
|
1 |
+
You are an AI Coding Assistant, and your role is to create comprehensive and highly informative docstrings for Python functions entered by the user. A well-structured docstring is essential for helping developers understand and use the function effectively. A standard Python docstring typically consists of the following sections:
|
2 |
+
|
3 |
+
1. Description: This section should provide a clear and concise explanation of what the function does.
|
4 |
+
|
5 |
+
2. Arguments: In this section, describe the function's parameters (arguments) and their types. Include both mandatory and optional arguments. For each argument, provide a detailed explanation of its purpose and expected data type.
|
6 |
+
|
7 |
+
3. Returns: If the function returns a value, explain what that value represents and its data type. If the function doesn't return anything (i.e., it has a None return type), mention that explicitly.
|
8 |
+
|
9 |
+
4. Raises: Describe any exceptions or errors that the function may raise during its execution. Specify the conditions under which these exceptions might occur.
|
10 |
+
|
11 |
+
Please follow Google docstring style guidelines to generate a docstring for the query function given by the user.
|
12 |
+
|
13 |
+
Instructions: {instruction}
|
14 |
|
15 |
Your task is to generate a docstring for the above query.
|
16 |
Response:
|
techdocs/requirements.txt
CHANGED
@@ -1 +0,0 @@
|
|
1 |
-
tqdm
|
|
|
|
techdocs/utils/functools.py
CHANGED
@@ -24,7 +24,7 @@ def get_access_token(data, return_refresh_token=False):
|
|
24 |
def request_inference(config, code_block, max_retries=1):
|
25 |
|
26 |
if max_retries == 0:
|
27 |
-
return
|
28 |
|
29 |
url = BASE_URL+"/api/inference"
|
30 |
headers={"accept":"application/json", "Authorization": f"Bearer {config['access_token']}"}
|
@@ -40,7 +40,7 @@ def request_inference(config, code_block, max_retries=1):
|
|
40 |
print("Encountered error retrying...")
|
41 |
config.update({"access_token":get_access_token(data)})
|
42 |
|
43 |
-
return request_inference(config,
|
44 |
|
45 |
|
46 |
|
|
|
24 |
def request_inference(config, code_block, max_retries=1):
|
25 |
|
26 |
if max_retries == 0:
|
27 |
+
return None
|
28 |
|
29 |
url = BASE_URL+"/api/inference"
|
30 |
headers={"accept":"application/json", "Authorization": f"Bearer {config['access_token']}"}
|
|
|
40 |
print("Encountered error retrying...")
|
41 |
config.update({"access_token":get_access_token(data)})
|
42 |
|
43 |
+
return request_inference(config, code_block, max_retries=max_retries-1)
|
44 |
|
45 |
|
46 |
|
techdocs/utils/parse.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import ast
|
2 |
import os
|
3 |
-
from tqdm import tqdm
|
4 |
import requests
|
5 |
|
6 |
from utils.functools import *
|
@@ -12,9 +11,14 @@ def extract_outermost_function(node, config):
|
|
12 |
if isinstance(node, ast.FunctionDef):
|
13 |
function_def = ast.unparse(node)
|
14 |
response = request_inference(config=config, code_block=function_def)
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
|
20 |
for child in ast.iter_child_nodes(node):
|
@@ -22,7 +26,7 @@ def extract_outermost_function(node, config):
|
|
22 |
|
23 |
# Function to traverse directories recursively and extract functions from Python files
|
24 |
def extract_functions_from_directory(config):
|
25 |
-
for root,
|
26 |
for file in files:
|
27 |
if file.endswith(".py"):
|
28 |
file_path = os.path.join(root, file)
|
|
|
1 |
import ast
|
2 |
import os
|
|
|
3 |
import requests
|
4 |
|
5 |
from utils.functools import *
|
|
|
11 |
if isinstance(node, ast.FunctionDef):
|
12 |
function_def = ast.unparse(node)
|
13 |
response = request_inference(config=config, code_block=function_def)
|
14 |
+
if response is not None:
|
15 |
+
try:
|
16 |
+
docstr = response.split('"""')
|
17 |
+
docstring = ast.Expr(value=ast.Str(s=docstr[1]))
|
18 |
+
print(f"Docstring generated for def {node.name}")
|
19 |
+
node.body.insert(0, docstring)
|
20 |
+
except IndexError:
|
21 |
+
pass
|
22 |
|
23 |
|
24 |
for child in ast.iter_child_nodes(node):
|
|
|
26 |
|
27 |
# Function to traverse directories recursively and extract functions from Python files
|
28 |
def extract_functions_from_directory(config):
|
29 |
+
for root, dirnames, files in os.walk(config["dir"]):
|
30 |
for file in files:
|
31 |
if file.endswith(".py"):
|
32 |
file_path = os.path.join(root, file)
|
testing/test.py
CHANGED
@@ -1,21 +1,106 @@
|
|
1 |
def add(a, b):
|
2 |
-
|
|
|
|
|
|
|
|
|
3 |
|
|
|
|
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def multiply(a, b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
return a * b
|
8 |
|
9 |
def subtract(a, b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
return a - b
|
11 |
|
12 |
def divide(a, b):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
if b == 0:
|
14 |
-
raise ValueError(
|
15 |
return a / b
|
16 |
|
17 |
-
|
18 |
def func(*args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def wrapper(*args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
return func(*args, **kwargs)
|
21 |
return wrapper
|
|
|
1 |
def add(a, b):
|
2 |
+
"""
|
3 |
+
Adds two numbers together.
|
4 |
+
|
5 |
+
:param a: The first number to add. Must be a numeric type.
|
6 |
+
:type a: int or float
|
7 |
|
8 |
+
:param b: The second number to add. Must be a numeric type.
|
9 |
+
:type b: int or float
|
10 |
|
11 |
+
:returns: The sum of the two numbers.
|
12 |
+
:rtype: int or float
|
13 |
+
|
14 |
+
:raises TypeError: If the input parameters are not numeric types.
|
15 |
+
:raises ValueError: If the input parameters are not numbers.
|
16 |
+
"""
|
17 |
+
return a + b
|
18 |
|
19 |
def multiply(a, b):
|
20 |
+
"""
|
21 |
+
Description:
|
22 |
+
This function multiplies two numbers.
|
23 |
+
|
24 |
+
Arguments:
|
25 |
+
a: First number to be multiplied. It should be an integer or a float.
|
26 |
+
b: Second number to be multiplied. It should be an integer or a float.
|
27 |
+
|
28 |
+
Returns:
|
29 |
+
The product of the two numbers. It will be an integer or a float depending on the input.
|
30 |
+
|
31 |
+
Raises:
|
32 |
+
None.
|
33 |
+
"""
|
34 |
return a * b
|
35 |
|
36 |
def subtract(a, b):
|
37 |
+
"""
|
38 |
+
Description:
|
39 |
+
This function performs subtraction of two numbers.
|
40 |
+
|
41 |
+
Arguments:
|
42 |
+
a (int): The first number to be subtracted.
|
43 |
+
b (int): The second number to be subtracted from the first number.
|
44 |
+
|
45 |
+
Returns:
|
46 |
+
int: Returns the difference of the two numbers.
|
47 |
+
|
48 |
+
Raises:
|
49 |
+
None
|
50 |
+
"""
|
51 |
return a - b
|
52 |
|
53 |
def divide(a, b):
|
54 |
+
"""
|
55 |
+
Description:
|
56 |
+
This function divides two numbers.
|
57 |
+
|
58 |
+
Arguments:
|
59 |
+
a (float): The first number to be divided.
|
60 |
+
b (float): The second number to be divided.
|
61 |
+
|
62 |
+
Returns:
|
63 |
+
float: Returns the result of a divided by b.
|
64 |
+
|
65 |
+
Raises:
|
66 |
+
ValueError: If b is equal to zero, it raises a ValueError with the message "Cannot divide by zero".
|
67 |
+
"""
|
68 |
if b == 0:
|
69 |
+
raise ValueError('Cannot divide by zero')
|
70 |
return a / b
|
71 |
|
|
|
72 |
def func(*args, **kwargs):
|
73 |
+
"""
|
74 |
+
This function is a decorator that wraps another function and returns a wrapper function.
|
75 |
+
|
76 |
+
Arguments:
|
77 |
+
* args: A variable-length argument list (optional).
|
78 |
+
* kwargs: A dictionary of keyword arguments (optional).
|
79 |
+
|
80 |
+
Returns:
|
81 |
+
A wrapper function that calls the original function with the same arguments.
|
82 |
+
|
83 |
+
Raises:
|
84 |
+
None
|
85 |
+
"""
|
86 |
+
|
87 |
def wrapper(*args, **kwargs):
|
88 |
+
"""
|
89 |
+
This function acts as a wrapper function that calls another function.
|
90 |
+
|
91 |
+
Arguments:
|
92 |
+
* args: Positional arguments to be passed to the wrapped function.
|
93 |
+
(type: tuple)
|
94 |
+
* kwargs: Keyword arguments to be passed to the wrapped function.
|
95 |
+
(type: dict)
|
96 |
+
|
97 |
+
Returns:
|
98 |
+
The result of calling the wrapped function with the provided arguments.
|
99 |
+
(type: any)
|
100 |
+
|
101 |
+
Raises:
|
102 |
+
Any exceptions raised by the wrapped function will be propagated.
|
103 |
+
(type: any)
|
104 |
+
"""
|
105 |
return func(*args, **kwargs)
|
106 |
return wrapper
|