Spaces:
Runtime error
Runtime error
Merge pull request #11 from HemanthSai7/dev
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 +1 -4
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,8 +1,6 @@
|
|
| 1 |
def add(a, b):
|
| 2 |
return a + b
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
def multiply(a, b):
|
| 7 |
return a * b
|
| 8 |
|
|
@@ -11,10 +9,9 @@ def subtract(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)
|
|
|
|
| 1 |
def add(a, b):
|
| 2 |
return a + b
|
| 3 |
|
|
|
|
|
|
|
| 4 |
def multiply(a, b):
|
| 5 |
return a * b
|
| 6 |
|
|
|
|
| 9 |
|
| 10 |
def divide(a, b):
|
| 11 |
if b == 0:
|
| 12 |
+
raise ValueError('Cannot divide by zero')
|
| 13 |
return a / b
|
| 14 |
|
|
|
|
| 15 |
def func(*args, **kwargs):
|
| 16 |
def wrapper(*args, **kwargs):
|
| 17 |
return func(*args, **kwargs)
|