Spaces:
Runtime error
Runtime error
Commit
·
c1f3831
1
Parent(s):
2ecc792
Initial cmd tool script
Browse files- TechdocsAPI/backend/router.py +0 -2
- TechdocsAPI/backend/services/auth/ops.py +1 -0
- techdocs/__init__.py +0 -0
- techdocs/execute.py +28 -0
- techdocs/requirements.txt +1 -0
- techdocs/utils/__init__.py +0 -0
- techdocs/utils/functools.py +43 -0
- techdocs/utils/parse.py +35 -0
TechdocsAPI/backend/router.py
CHANGED
@@ -59,7 +59,5 @@ async def regenerate_api_key(access_token: str = Depends(JWTBearer())):
|
|
59 |
@app.post("/api/inference", summary="Inference", response_model=Inference, tags=["Resource Server"], dependencies=[Depends(JWTBearer())])
|
60 |
async def inference(code_block:str, api_key: str,access_token:str=Depends(JWTBearer())):
|
61 |
user_sub=Auth.get_user_credentials(access_token)
|
62 |
-
|
63 |
-
print("after res")
|
64 |
|
65 |
return ops_inference(code_block,api_key,user_sub)
|
|
|
59 |
@app.post("/api/inference", summary="Inference", response_model=Inference, tags=["Resource Server"], dependencies=[Depends(JWTBearer())])
|
60 |
async def inference(code_block:str, api_key: str,access_token:str=Depends(JWTBearer())):
|
61 |
user_sub=Auth.get_user_credentials(access_token)
|
|
|
|
|
62 |
|
63 |
return ops_inference(code_block,api_key,user_sub)
|
TechdocsAPI/backend/services/auth/ops.py
CHANGED
@@ -102,6 +102,7 @@ def ops_inference(source_code:str,api_key:str,username:str):
|
|
102 |
llm_response = app.state.llmchain.run({"instruction": source_code_message})
|
103 |
|
104 |
docstring = Inference(docstr=llm_response)
|
|
|
105 |
|
106 |
|
107 |
return docstring
|
|
|
102 |
llm_response = app.state.llmchain.run({"instruction": source_code_message})
|
103 |
|
104 |
docstring = Inference(docstr=llm_response)
|
105 |
+
print(docstring)
|
106 |
|
107 |
|
108 |
return docstring
|
techdocs/__init__.py
ADDED
File without changes
|
techdocs/execute.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from utils import parse,functools
|
2 |
+
|
3 |
+
import argparse
|
4 |
+
|
5 |
+
def main():
|
6 |
+
parser = argparse.ArgumentParser(description='Weather Application')
|
7 |
+
parser.add_argument('--api_key','-k',help='API key for Techdocs')
|
8 |
+
parser.add_argument('--username','-u',help='Username for Techdocs')
|
9 |
+
parser.add_argument('--password','-p',help='Password for Techdocs')
|
10 |
+
parser.add_argument('--dir','-d',help='Root directory to be documented')
|
11 |
+
|
12 |
+
args=parser.parse_args()
|
13 |
+
|
14 |
+
config = {
|
15 |
+
arg[0]:arg[1] for arg in args._get_kwargs()
|
16 |
+
}
|
17 |
+
|
18 |
+
data = {
|
19 |
+
"username":config['username'],
|
20 |
+
"password":config['password']
|
21 |
+
}
|
22 |
+
|
23 |
+
config.update({"access_token":functools.get_access_token(data)})
|
24 |
+
|
25 |
+
parse.extract_functions_from_directory(config)
|
26 |
+
|
27 |
+
if __name__ == '__main__':
|
28 |
+
main()
|
techdocs/requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tqdm
|
techdocs/utils/__init__.py
ADDED
File without changes
|
techdocs/utils/functools.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import requests
|
3 |
+
|
4 |
+
BASE_URL = "http://localhost:8000"
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
def get_access_token(data, return_refresh_token=False):
|
9 |
+
url = BASE_URL + "/auth/login"
|
10 |
+
headers = {
|
11 |
+
"accept": "application/json",
|
12 |
+
}
|
13 |
+
data = json.dumps(data)
|
14 |
+
response = requests.post(url, data=data, headers=headers)
|
15 |
+
access_token = response.json()['access_token']
|
16 |
+
if return_refresh_token:
|
17 |
+
refresh_token = response.json()['refresh_token']
|
18 |
+
return access_token, refresh_token
|
19 |
+
return access_token
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
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']}"}
|
31 |
+
code_input = code_block
|
32 |
+
response = requests.post(url=url, headers=headers, params={'code_block':code_input, 'api_key':config['api_key']})
|
33 |
+
if response.status_code == 200:
|
34 |
+
return response.json()["docstr"]
|
35 |
+
else:
|
36 |
+
data = {
|
37 |
+
"username":config['username'],
|
38 |
+
"password":config['password']
|
39 |
+
}
|
40 |
+
print("Encountered error retrying...")
|
41 |
+
config.update({"access_token":get_access_token(data)})
|
42 |
+
|
43 |
+
return request_inference(config,config["access_token"], code_block, max_retries=max_retries-1)
|
techdocs/utils/parse.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ast
|
2 |
+
import os
|
3 |
+
from tqdm import tqdm
|
4 |
+
import requests
|
5 |
+
|
6 |
+
from utils.functools import *
|
7 |
+
|
8 |
+
|
9 |
+
# Function to extract and print the outermost nested function with line number
|
10 |
+
def extract_outermost_function(node, config, line_number=1,):
|
11 |
+
base_url = "http://localhost:8000"
|
12 |
+
if isinstance(node, ast.FunctionDef):
|
13 |
+
function_def = ast.unparse(node)
|
14 |
+
print(f"Function starting at line {line_number}:\n{function_def}")
|
15 |
+
print("=" * 30)
|
16 |
+
|
17 |
+
response = request_inference(config=config,code_block=function_def)
|
18 |
+
|
19 |
+
|
20 |
+
for child in ast.iter_child_nodes(node):
|
21 |
+
if isinstance(child, ast.FunctionDef):
|
22 |
+
line_number = child.lineno
|
23 |
+
extract_outermost_function(child, line_number)
|
24 |
+
|
25 |
+
# Function to traverse directories recursively and extract functions from Python files
|
26 |
+
def extract_functions_from_directory(config):
|
27 |
+
for root, _, files in os.walk(config["dir"]):
|
28 |
+
for file in files:
|
29 |
+
if file.endswith(".py"):
|
30 |
+
file_path = os.path.join(root, file)
|
31 |
+
print(file_path)
|
32 |
+
with open(file_path, "r",errors='ignore') as file:
|
33 |
+
content = file.read()
|
34 |
+
parsed = ast.parse(content)
|
35 |
+
extract_outermost_function(parsed, config)
|